Jump to content

What is wrong with this query?


Nexus10

Recommended Posts

Empty database (Users_recover), no rows in it.

 

user_name    (varchar(20))

email    (varchar(150))

key    (varchar(150))

 

$query = "INSERT INTO Users_recover (user_name, email, key) VALUES ('$user_name', '$email', '$key')";
	mysql_query($query) or die("Erro");

 

I echo'ed $user_name, $email and $key above the query and these are all fine.

Link to comment
https://forums.phpfreaks.com/topic/206675-what-is-wrong-with-this-query/
Share on other sites

$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} ";
	mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());

 

Problem with the query: INSERT INTO `Users_recover` SET `user_name`='admin' , `email`='[email protected]' , `key`='78bef654a197cdc4189342034a3c5c1b

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 ''78bef654a197cdc4189342034a3c5c1b' at line 1

In this case you forgot the closing quote on the {$key}

Change

<?php
$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key} ";
?>

to

<?php
$query = "INSERT INTO `Users_recover` SET `user_name`='{$user_name}' , `email`='{$email}' , `key`='{$key}' ";
?>

You don't really need all the "{ }" and back-ticks, so this should work fine:

<?php
$query = "INSERT INTO Users_recover SET user_name='$user_name' , email='$email' , `key`='$key' ";
?>

You only need the back-ticks if your using a MySQL reserved word for a fieldname.

 

Ken

Okay, I'm having problems with another query now also related to the above:

 

	$query = "UPDATE Users_recover SET 'key' = '$key' WHERE user_name = '$user_name'"; 
	mysql_query($query) or die("Error: Action could not be completed. Please email [email protected] about this.<br />" . mysql_error());

 

Error:

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 ''key' = 'baea9f5fb6eea96384efae608716d819' WHERE user_name = 'admin'' at line 1

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.