RE: [PHP] Code check please

From: Date: Thu, 21 Jun 2001 05:54:27 +0000
Subject: RE: [PHP] Code check please
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-54678@lists.php.net to get a copy of this message
Andreas, I'm not sure about code that appears to be missing like an execute query function or checking the number of affected rows to make sure that the insert worked, but clearly your insert code is not properly formed. The query could also be impacted by whether the columns are defined with special attributes like DATE, etc. Assuming that all columns are defined as character strings the query should look like; $sql = "INSERT INTO tabell (fornamn, efternamn, email) " . "VALUES(\"$fornamn\", \"$efternamn\", \"$email\")"; I've found that I often have problems trying to use "single quotes" in sql queries so I avoid them. I notice that you also included a semi-colon in the query text, while this works when piping a file of queries into the mysql command, it does not work from a program. The semi-colon in a command stream into the mysql command actually signifies a point to stop and execute the preceding text as a query and after executing that query, continue on from the next character. hope you got it working, Warren Vail -----Original Message----- From: Andreas Skarin [mailto:sdts@sdts.nu] Sent: Wednesday, June 20, 2001 9:00 AM To: PHP General Subject: [PHP] Code check please I've tried to get this working for over an hour now, and it still won't. I don't even get an error message to help me find the problem so I was hoping that someone could check my code for me. I'm fooling around with a basic form that is supposed to send one's name, surname and e-mail address to "receive.php". "receive.php" is then supposed to take the information and add it to a table called "tabell" in a database called "databas", but it doesn't work. I think there might be something wrong with my MySQL query. - - - - - - - - - - - FORM - - - - - - - - - - - - - - <form action="receive.php" method="post"> <P>F&ouml;rnamn:<br> <input type="text" name="fornamn" size="25"></p> <p>Efternamn:<br> <input type="text" name="efternamn" size="25"></p> <p>E-mailadress:<br> <input type="text" name="email" size="25"></p> <input type="submit" name="submit" value="Log in"> </form> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RECEIVE.PHP - - - - - - - - - - - <?php // connection to MySQL $connection = mysql_connect("localhost", "username", "password"); if (!$connection) { echo ("<P>Unable to connect to the database server at this time.</P>" ); exit(); } //select database if (! @mysql_select_db("databas") ) { echo ("<P>Unable to locate the database at this time.</P>"); exit(); } // MySQL query $sql = "INSERT INTO tabell SET" . "fornamn ='$fornamn'," . "efternamn='$efternamn'," . "email='$email';"; ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - Thanks in advance! // Andreas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#54678) next »