Jump to content

PHP inserting blank strings in MYSQL


danboy712

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.