Click here to Skip to main content
14,695,620 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I keep getting a error for the following insert statement:

$uploadAttempts = "INSERT INTO `results` (`fullName`, `temp`, `data1`, `data2`, `data3`, `data4`, `data5`, `data6`, `message`, `result`, `dateTime`, `indexData`) VALUES ('$answer1', '$answer2', '$answer3', '$answer4', '$answer5', '$answer6', '$answer7', '$answer8', '$answer9', '$overallResult', CURRENT_TIMESTAMP, '1'";


Not sure what is wrong with it, I referenced back to another insert statement and everthing looks good. Could it be the CURRENT_TIMESTAMP?

What I have tried:

I tried using php checker with the result of :

Error: There is 1 more opening parenthesis '(' found


I also tried putting single quotes around CURRENT_TIMESTAMP with no luck.
Posted
Updated 16-May-20 16:53pm

1 solution

There are only two problems with your SQL

1) you should never concatenate strings to form SQL - you leave yourself open to SQL injection - xkcd: Exploits of a Mom[^] - so please learn how to use a parameterised SQL statement - yes, its possible, even in PHP ;-)

2) this
$uploadAttempts = "INSERT INTO `results` (`fullName`, `temp`, `data1`, `data2`, `data3`, `data4`, `data5`, `data6`, `message`, `result`, `dateTime`, `indexData`) VALUES ('$answer1', '$answer2', '$answer3', '$answer4', '$answer5', '$answer6', '$answer7', '$answer8', '$answer9', '$overallResult', CURRENT_TIMESTAMP, '1'";
might need to be

...CURRENT_TIMESTAMP, '1')";
(note the ')' before the closing double-quote '"' )
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900