Re: accidently inserting into web database blank records.

From: Date: Fri, 14 Mar 2003 16:19:05 +0000
Subject: Re: accidently inserting into web database blank records.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139726@lists.php.net to get a copy of this message
Mahmut KARADEMIR wrote:
Hi All; I am trying to add a new record web database using Mysql&PHP. But after at every add process a new blank record is added to mysql table. The entered text is not considered with codes. What is my trouble in this html or php code? Could anyone has any idea? Thanks. ***************name.html****************** <html> <body> <form action="name.php" method="post"> <PRE>
name......         : <input
                       type="text"
                       name="name"
                       size="25"
                       maxlength="25"
                       value="<? echo $name>">
                      <P>
surname:             <input                        type="text"
                       name="surname"
                       size="25"
                       maxlength="25">
                        < input type="submit"                         name="submit"                        value="submit">
</PRE> </form> </body> </html> *******************name.php*************** <?php mysql_connect("localhost","user","password"); mysql_select_db ("mydatabasename"); mysql_query ("INSERT INTO name (name,surname) VALUES ('$name','$surname')"); echo ('Your record has been added.'); print ("<p>"); print ("Your Name:"); print ($name); print (" "); print ("<p>"); print ("Your Surname:"); print ($surname); print ("<p>"); print ("THANKS"); ?>
Try putting your sql statement into a variable and echoing it before using it. That way you can see if the statement is correct. I suspect not. The way you are coding this assumes register_globals is set to "on", which it is not by default in recent versions of PHP. HTH Chris

« previous php.general (#139726) next »