I'm trying to understand why my Insert is returning false w/ no results found.
$mysql_link=mysqli_connect(host,user,dbpswd,dbname);
if (mysqli_connect_errno()){echo "Failed to connect to MySQL: " . mysqli_connect_error();} // Never shows
mysqli_set_charset($mysql_link,"utf8");
...
echo $TableName; // Outputs correct table name
echo $flds; // Outputs correct field names, didn't include id field, as auto generated
field1, field2, field3, field4, field5, field6, field7, field8@2x, field9, field10, field11
echo $str; // Outputs correct field values, didn't include id value
'***', '0', '0.0', '2018-07-28', '16:42:00', '0.00', '[email protected]', '***', '../rw_common/plugins/stacks/myimage.png', 'https://www.google.com', '***'
$query="INSERT INTO ".$TableName."(".$flds.") VALUES (".$str.")";
$mysql_result = mysqli_query($mysql_link,$query);
if ($mysql_result->num_rows > 0) {echo 'record found';}
else {echo 'query ok but no results found';} // Outputs this line !
if ($mysql_result===false) // Resolves to false
Is there anything else I can check and how to fix this?
Update1:
echo $query: Outputs this:
INSERT INTO mytable3(field1, field2, field3, field4, field5, field6, field7, field8@2x, field9, field10, field11) VALUES ('***', '0', '0.0', '2018-07-28', '16:55:00', '0.00', '[email protected]', '***', '../rw_common/plugins/stacks/myimage.png', 'https://www.google.com', '***')
Update2:
echo $query:
INSERT INTO mytable3(`field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8@2x`, `field9`, `field10`, `field11`) VALUES ('***', '0', '0.0', '2018-07-28', '17:15:00', '0.00', '[email protected]', '***', '../rw_common/plugins/stacks/myimage.png', 'https://www.google.com', '***')
So, for those who might have a similar problem: You need to wrap the fields in back ticks to account for someone using special characters or reserved names. Also, I discovered a field that was not being entered, which was also breaking the insert ;)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments