Jump to content

Recommended Posts

my update query will not work:

[code]$q= "SELECT `Name` , `Position` FROM `temp`";
$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());

while ($row = mysql_fetch_assoc($result)){
    
    $name=$row['Name'];
    $pos=$row['Position'];
    
$query = mysql_query("UPDATE '$compl' SET '$colnom' = '$pos' WHERE `Name`='$name'") or die(mysql_error() . $query);
echo ("Updated sailor: " . $name . "<br>");
}[/code]

it just returns the error:

[code]
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 ''topper main points' '22/03/06 Race 1' = '2' WHERE CONVERT( `Name` USING utf8 ) ' at line 1[/code]

what could be wrong with the query?
Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/
Share on other sites

UPDATE '[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]$compl' [!--colorc--][/span][!--/colorc--]SET '$colnom' = '$pos' WHERE `Name`='$name'")


I am not seeing anywhere where you are declaring what $compl is.
If it doesnt know what $compl is supposed to be, then the update query doesnt know what table it is meant to update. hope this helps.
Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19606
Share on other sites

i have declared '$compl' earlier, thats not the problem

wickning1, my col names and table name have been changed to the `` and it has made some progress.

Now when i send $name to be "Stewart Brown" i get this error:

[code]Unknown column 'Stewart Brown' in 'where clause'[/code]

i dont see why it should do this since i am declaring '$colnom' as the column name.

Heres my latest full code:

[code]$comp = $_REQUEST['comp'];
$tdate = date('j/m/y');//Get todays date
$raceno = $_REQUEST['raceno'];
$compl = strtolower($comp);
$colnom = ($tdate . " Race " . $raceno); //Find Name for column
echo ($colnom);

$q= "SELECT `Name` , `Position` FROM `temp`";
$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());

while ($row = mysql_fetch_assoc($result)){
    
    $name=$row['Name'];
    $pos=$row['Position'];
    
$query = mysql_query("UPDATE `$compl` SET `$colnom` = `$pos` WHERE `Name`=`$name`") or die(mysql_error() . $query);
echo ("Updated sailor: " . $name . "<br>");
}
[/code]

any ideas as to the problem??
Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19706
Share on other sites

[!--quoteo(post=357282:date=Mar 22 2006, 01:46 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 22 2006, 01:46 PM) [snapback]357282[/snapback][/div][div class=\'quotemain\'][!--quotec--]
There is really no need to put backticks at all unless your tables or field names contain spaces. You shouldn't put spaces in them anyway, but to each his own. Underscores work alot better and help making your code look cleaner.

Ray
[/quote]

You also HAVE to use backticks if your field names are reserved mysql words..
Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19707
Share on other sites

Backticks are killing me :p

Try this out
[code]$q= "SELECT Name, Position FROM temp";
$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());

while ($row = mysql_fetch_assoc($result)){
    
    $name=$row['Name'];
    $pos=$row['Position'];
    
$query = mysql_query("UPDATE $compl SET $colnom = '$pos' WHERE Name = '$name'") or die(mysql_error() . $query);
echo ("Updated sailor: " . $name . "<br>");
}[/code]

Looks like you are creating a new column name everytime you run the script??
[code]$colnom = ($tdate . " Race " . $raceno); //Find Name for column[/code]
Not going to work if the column name does not exist.

What are you trying to do anyway??

Ray

Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19744
Share on other sites

with the code you gave me i get the error:

[code]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 'points SET 22/03/06 Race 1 = '1' WHERE Name = 'Will Williams'' at line 1[/code]

No, im not creating a new column im just inserting into a column that was just created. It's a sailing system that is supposed to transfer what I have in temp into the proper results table with the corrects positions etc..

Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19765
Share on other sites

Wow, if that really is the column name, you have a very bad database design. You should find someone to help you redesign it and port the data over.

For now this should work for you:

[code]$query = mysql_query("UPDATE `$compl` SET `$colnom` = '$pos' WHERE `Name`='$name'") or die(mysql_error() . $query);[/code]
Just remember - backticks `` for tables and columns, single quotes '' for string values.
Link to comment
https://forums.phpfreaks.com/topic/5480-update-query-help/#findComment-19779
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.