Jump to content

PHP Error code help: Error 0


traxy

Recommended Posts

Hey,

 

Im currently working on a uni assignment using php and mysql the problem is when I try to execute a mysql query using the mysqli_query function I get an error code 0. Im not sure what this means (from my research it may have something to do with not being able to start mysql). The system (CentOS) that the script is running on I have limited access to but I can confirm mysql is running and I can connect to it via the mysql prompt. Here is a the code for you to look at as well:

 

$DBConnect=@mysqli_connect("localhost", "$username", "$password", "$database")

Or die("<br/><br/>Unable to connect to the database server.</p>" . "<br/><br/>Error code " . mysqli_connect_errno($DBConnect) . ":" . mysqli_connect_error($DBConnect)) . "</p>";

 

$TableName="TEST";

$SQLstring = "INSERT INTO $TableName VALUES (',$_POST[field1],$_POST[field2],$_POST[field3])";

$QueryResult=@mysqli_query($DBConnect, $SQLstring)

Or die("<br/><br/>Unable to execute the query.</p>" . "<br/><br/>Error code " . mysqli_connect_errno($DBConnect) . ":" . mysqli_connect_error($DBConnect)) . "</p>";

echo "<br/><br/>Successfully executed the query.</p>";

mysqli_close($DBConnect);

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/156242-php-error-code-help-error-0/
Share on other sites

I don't think there is a connection error, I could be wrong but I think error code 0 means no error.

 

The problem is your query syntax. first of all you have a single quote with a comma at the beginning of the value set, why? Secondly each value in the value set needs to be enclosed by quotes. Thirdly you should use $_POST['field1'] not $_POST[field1]:

 

$SQLstring = "INSERT INTO $TableName VALUES (',$_POST[field1],$_POST[field2],$_POST[field3])";

 

This should solve the problem, but you also need to escape the posted data, using something like real_escape_string()

 

$SQLstring = "INSERT INTO $TableName VALUES ('" . $_POST['field1'] . "', '" . $_POST['field2'] . "', '" . $_POST['field3'] . '"")";

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.