Jump to content

Error in MySQL syntax


cordoprod

Recommended Posts

Hi. I want to insert something in a mysql db.

 

I get this error message:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,2,3,4,5,6) VALUES('glenn','glenn','glenn','glenn','glenn','glenn')' at line 1

 

 

My syntax looks like this:

$new = "INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."')";

 

It looks weird but the $result is a random username.

Link to comment
https://forums.phpfreaks.com/topic/103542-error-in-mysql-syntax/
Share on other sites

u have not gvn open bracket before..INSERT

 

$new = ("INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."'");

Try:

 

$new = "INSERT INTO travek_user_cols(1,2,3,4,5,6) VALUES('{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}','{$result['online']}')";

No, i didn't have to.. Fixed it myself, but one more thing..

 

This is my function:

function RandomUser() {

    $db = new DbConnector();

$db->connect();

 

    $sql = "SELECT * FROM travek_userstats WHERE has_pic='true' ORDER BY RAND()";

$result = $db->query($sql);

 

$result = $db->fetchArray($result);

 

$sql_2 = "INSERT INTO travek_user_cols(row1,row2,row3,row4,row5,row6) VALUES('".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."','".$result["online"]."')";

 

$write = $db->query($sql_2);

}

 

It works, and uploads to the DB.. But will $result["online"] be the same in all 6 rows? or one random in every row?

 

I want to have a random in every row..

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.