|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP inputting blank records into mysql
Hey all,
I'm totally new at this... I have a test server on my home network, running Red Hat 8.0/Apache 2.0.43/PHP 4.3.0/MySQL 3.23.54 I've written this form in DreamweaverMX and the form works fine. However, when I look at the MySQL database, the records are blank. Is it an improperly set network or is there something wrong with my PHP installation? or is my code bad? Help please! <form method="post" action="formmail.php"> <table width="400" border="0" cellspacing="1" cellpadding="4" align="center"> <tr> <td>Screenname</td> <td><input type="TEXT" name="screenname" size="32" maxlength="50"></td> </tr> <tr> <td>First Name</td> <td><input type="TEXT" name="firstname" size="32" maxlength="50"></td> </tr> <tr> <td>Last Name</td> <td><input type="TEXT" name="lastname" size="32" maxlength="50"></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="SUBMIT" name="submit" value="Send Message"></div></td> </tr> </table> </form> and formmail.php looks like: <?php $user = "user"; $password = "password"; $db = "database"; $link = mysql_connect("192.168.1.4", $user, $password); if (!$link ) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die ("Couldn't open $db:" .mysql_error()); $query = "INSERT INTO names (screenname, firstname, lastname) VALUES ('$screenname', '$firstname', '$lastname')"; mysql_query($query) or die (mysql_error() ); mysql_close($link); ?> Thanks in advance! Pierre |
|
#2
|
|||
|
|||
|
RE: PHP inputting blank records into mysql
your version of PHP comes with register globals off.
You need to use the superglobals. In this case you would use the $_POST[] variable. change : $query = "INSERT INTO names (screenname, firstname, lastname) VALUES ('$screenname', '$firstname', '$lastname')"; to : $query = "INSERT INTO names (screenname, firstname, lastname) VALUES ('$_POST[screenname]', '$_POST[firstname]', '$_POST[lastname]')"; and that should do it. |
|
#3
|
|||
|
|||
|
RE: PHP inputting blank records into mysql
Thanks Kaboo!
Worked like a charm! Can I turn globals on instead of having to type $_POST[] everywhere? Thanks for your prompt reply btw! Pierre |
|
#4
|
||||
|
||||
|
RE: PHP inputting blank records into mysql
Yes you can turn it on.
Edit the php.ini on your server on line where it says: register_globals Off set to On |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > PHP inputting blank records into mysql |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|