Trying to Understand Why Insert Mysql Returns False & How to Fix

parti

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', '***')
parti

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.

edited at
0

Comments

0 comments
Login to comment

Related

Why 'a like a' returns false in MySQL

mysql - returns false on valid INSERT syntax

Python loop returns false answers and I don't understand why

I don't understand why this regex always returns false?

Trying to understand how to create an async function in rust that returns a MySqlPool object

Why ModelState returns different result and how to fix it?

MySQL's EXPLAIN INSERT unavailable: how to understand if INSERT is slow or not?

How to fix MySQL-Connector INSERT Bug?

mysqli_query($connect, $query) returns false : how to fix this?

How to fix that stmt->execute() always returns false?

How to fix end of statement when trying to insert multiple values in SQL?

Trying to understand why make is failing

why is my MySQL hostname empty ? and how to fix it?

Why there are empty string while trying to split a string in Java? And how to fix it?

trying to understand code of a linked list insert function

Trying to understand DLL returns for String types

How to Fix False Negative

How to understand and fix conflicts in PLY

Why toggle checkbox returns false?

Why isUniquelyReferencedNonObjC returns false in this case?

Why `("" || "word") == true` returns false?

Why returns false without comparison?

why get text returns false?

C# a Dictionary Interface throws on accessing but returns false on null check? How to fix it?

OWASP ZAP scan returns "Application Error Disclosure" to javascript library. Is it false positive? How to proove that or fix?

Trying to understand how SyncLock Works

Trying to understand how to work with IFS

Trying to understand how to make a UpdateOrCreate

Trying to understand how partitions function…