traxy Posted April 30, 2009 Share Posted April 30, 2009 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 More sharing options...
the182guy Posted April 30, 2009 Share Posted April 30, 2009 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'] . '"")"; Link to comment https://forums.phpfreaks.com/topic/156242-php-error-code-help-error-0/#findComment-822543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.