Re: Can't to insert data ( via variable ) into MS-SQL
| From: | Chris Thomas | Date: | Fri, 26 Mar 2004 17:10:47 +0000 |
| Subject: | Re: Can't to insert data ( via variable ) into MS-SQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181569@lists.php.net to get a copy of this message | ||
Do you have register_globals on?
If not ayou have to get the POST information manually.
ie.. $job = $_POST['job']
Also are you sure that you are connecting to the database successfully?
add:
or die('could not connect')
to the end of your mssql_pconnect and mssql_select_db statements.
So your save.php should something like this.
<a href=view.php">Search data</a>
</body>
</html>
<?
$name = $_POST['name'];
$job = $_POST['job'];
$subject = $_POST['subject'];
$date=date('Y-m-d H:i:s');
$link = mssql_pconnect("sql","sa","1234") or die("Could not
connect to db
server");
mssql_select_db("phpbook",$link) or die("Could not connect to server");
$str = " INSERT INTO staff (name,job,subject)
VALUES('$name','$job','$date','$subject',)";
mssql_query($str,$link);
?>
Chris
<edwardspl@ita.org.mo> wrote in message news:40644F7C.D1639531@ita.org.mo...
> Dear All,
>
> There is a sample that can't to insert any data ( via variable ) in
> MS-SQL :
>
> insert.php:
> <form action="save.php" method="post">
> <table border="0" align=center>
> <input type="text" size="20" name="name"
> maxlength="8" value="<? echo
> $GBName ?>"><br>
> Job<input type=text" size="16" name="job"><br>
> Subject<input type="text" size="30"
> name="subject"><br>
> <input type="submit" value="SubMit">
> </center>
> </table>
> </form>
>
> save.php:
> <a href=view.php">Search data</a>
> </body>
> </html>
> <?
> $date=date('Y-m-d H:i:s');
> $link = mssql_pconnect("sql","sa","1234");
> mssql_select_db("phpbook",$link);
> $str = " INSERT INTO staff (name,job,subject)
> VALUES('$name','$job','$date','$subject',)";
> mssql_query($str,$link);
> ?>
>
> After insert data by using save.php, I found no any data from the
> Database system ( MS-SQL ), but I sure the Database System is no problem
> !
>
> So, how can I fix this kind of problem ( Sorry, I'm not familar with php
> ) ?
> Many thank for your help !
>
> Edward.