danboy712 Posted February 6, 2009 Share Posted February 6, 2009 Hi I have been learning PHP, MYSQL & APACHE. I have a problem in that a php script I have written to experiment with inserting data beleives it is passing a string into the database and no error is thrown up by the server, however when I check the entry in the MYSQL CLI it is just a blank string although the AUTO_INCREMENT id column is updated and an entry has obviously been made. This is the HTML Form: <html lang="en"> <head> <title>Record Insertation Form</title> </head> <body> <form action="insert.php" method="POST"> <p>Text to Add:<br> <input type="text" name="testfield" size="30"> <p><input type="submit" name="submit" value="insert record"></p> </form> </body> </html> And the PHP script: <?php $mysqli = mysqli_connect("localhost", "root", "mypassword", "testDB"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $sql = "INSERT INTO testTable (testField) VALUES ('".$POST["testfield"]."')"; $res = mysqli_query($mysqli, $sql); if ($res === TRUE) { echo "A record has been inserted."; } else { printf("Could not insert record: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> Does anyone have any advice? Many Thanks PS I am running the latest versions PHP, MYSQL & APACHE on Windows XP. Link to comment https://forums.phpfreaks.com/topic/144143-php-inserting-blank-strings-in-mysql/ Share on other sites More sharing options...
printf Posted February 6, 2009 Share Posted February 6, 2009 $POST["testfield"] is not the super global $_POST["testfield"] Link to comment https://forums.phpfreaks.com/topic/144143-php-inserting-blank-strings-in-mysql/#findComment-756367 Share on other sites More sharing options...
danboy712 Posted February 6, 2009 Author Share Posted February 6, 2009 Sad thing is I knew that full well. Being staring at this screen all day. Thanx very much. I'll fix that then i'm packing it in for the day (I live in uk its 23:00 here). Link to comment https://forums.phpfreaks.com/topic/144143-php-inserting-blank-strings-in-mysql/#findComment-756369 Share on other sites More sharing options...
printf Posted February 6, 2009 Share Posted February 6, 2009 Hey don't feel bad, I always need another set of eyes, especially on Mondays, Link to comment https://forums.phpfreaks.com/topic/144143-php-inserting-blank-strings-in-mysql/#findComment-756380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.