0

I am trying to run the following but am getting the following mysql 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 'INSERT INTO hqfjt_chronoforms_data_addupdatelead SET f9f2ec4270a751f4f34980c325e' at line 2

 <?php
$user = $_POST[cf_uid];
$form = $_POST[uid];
$date = date("d-m-Y"); 
$query = mysql_query("UPDATE hqfjt_chronoforms_data_addupdatelead SET $form = $date 
 WHERE cf_uid = $user
") 
or die(mysql_error());
?>

what I am trying to do, is use the $USER to find the correct user record, then in that user record find the column $form and insert the $date into it,

EDIT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Ok this gets me halfway there, but still an error >>

<?php
$user = $_POST[cf_id];
$form = $_POST[uid];
$date = date("d-m-Y"); 
$query = mysql_query("UPDATE hqfjt_chronoforms_data_addupdatelead SET '".$form."' =     '".$date."' WHERE cf_id = '".$user."'")
or die(mysql_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 ''185cfb5654aacf3038e3f26491f227356b5d768f' = '30-12-2011' WHERE cf_id = '14'' at line 1

2 Answers 2

1

This is not correct:

First you are trying to execute both select and insert together and second insert don't have set command ... I think you need an update command

update hqfjt_chronoforms_data_addupdatelead SET $form = $date 
WHERE $user = $user

OR, I think you are trying to do something like this

 INSERT INTO hqfjt_chronoforms_data_addupdatelead SELECT * FROM
hqfjt_chronoforms_data_addupdatelead WHERE $user = $user

EDIT: Try This:

<?php $user = $_POST["cf_uid"]; 
$form = $_POST["uid"]; 
$date = date("d-m-Y"); 
mysql_query('UPDATE hqfjt_chronoforms_data_addupdatelead SET "$form" = "$date" 
WHERE cf_uid = "$user"')   or die(mysql_error()); ?> 
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, what I am trying to do, is use the $USER to find the correct user record, then in that user record find the column $form and insert the $date into it, sounds easy when you say it like that lol, as for coding it though....
Well, then you need the update command I have mentioned in my answer
I have tried using this >>, but am getting Unknown column '6dd52fad65bf18b824db855ea325deb8' in 'where clause', 6dd52fad65bf18b824db855ea325deb8, exists and is id of the record, so im not sure why I get the error >>
<?php $user = $_POST[cf_uid]; $form = $_POST[uid]; $date = date("d-m-Y"); $query = mysql_query(" UPDATE hqfjt_chronoforms_data_addupdatelead SET $form = $date WHERE cf_uid = $user ") or die(mysql_error()); ?>
0

as per your comment you'd be fine just doing a

$query = "UPDATE table SET $forms = $date WHERE cf_uid = $user";
$success = mysql_query($query);

or you can put it all into one line as well. But if you're just looking to update there's no need to SELECT ALL the data from the user. That's what the "WHERE" is for.

6 Comments

Hi, I think I might have been using the select when I didnt need it, what I am trying to do, is use the $USER to find the correct user record, then in that user record find the column $form and insert the $date into it,
updated my answer. but i think the gentleman below me answered it correctly first.
I have tried using this >>, but am getting Unknown column '6dd52fad65bf18b824db855ea325deb8' in 'where clause', 6dd52fad65bf18b824db855ea325deb8, exists and is id of the record, so im not sure why I get the error >>
<?php $user = $_POST[cf_uid]; $form = $_POST[uid]; $date = date("d-m-Y"); $query = mysql_query(" UPDATE hqfjt_chronoforms_data_addupdatelead SET $form = $date WHERE cf_uid = $user ") or die(mysql_error()); ?>
hmmm try doing $query = "UPDATE table SET '".$forms."' = '".$date."' WHERE cf_uid = '".$user."'"); the quotations might help? took a look around and saw that as a solution
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.