...

View Full Version : UPDATE query not working correctly.... Arrrgh =D



paddy100
01-21-2010, 01:29 PM
Hi!

I have been trawling the web for the answer to this but can't nail it! I am a newbie so apologies in advance if my coding is cringeworthy or offends the eyes!:)

I have an issue where i am trying to update a DB for match fixtures with results. the form looks like

[CODE]
<form name="form2" method="post" action="amendfixtures.php">

<label>urn
<input name="urn" type="text" id="urn" size="6" />
</label>
<select name="wl" id="wl">
<option value="won">Won</option>
<option value="lost">Lost</option>
</select>

<p>
for
<input name="for" type="text" id="for" size="3" />
against
<input name="against" type="text" id="against" size="3" />
</p>
<p>&nbsp;</p>
<p>
<input type="submit" value="update" />
</p>
</form>
[CODE]

and the php..

[CODE]
<?php

/* Program to update scores of fixtures in committee area */

include("rhino.inc");

$connection = mysql_connect($host, $user, $password)
or die ("couldn't connect to server");
$db = mysql_select_db($database, $connection)
or die ("couldn't connect to database");

$urn = ($_POST['urn']);
$wl = ($_POST['wl']);
$for = ($_POST['for']);
$against =($_POST['against']);


$update = "UPDATE fixturesresults SET wl ='$wl',for ='$for', against ='$against' WHERE urn ='$urn'";


if(mysql_query($update)){
echo "updated score urn $urn into the database";}
else{
echo "Failed, please try again";}



?>
[CODE]

All i recieve when testing is the fail echo , "Failed, please try again"


My forehead is now sore from banging it against a wall so any help would be appreciated!

my seperate codes for adding & deleting fixtures work like a charm!..

Thanks in advance!

Paddy

abduraooft
01-21-2010, 01:38 PM
Change
if(mysql_query($update)){
echo "updated score urn $urn into the database";}
else{
echo "Failed, please try again";} to

f(mysql_query($update)){
echo "updated score urn $urn into the database";}
else{
echo "Failed, please try again: ". mysql_error();}

Fou-Lu
01-21-2010, 01:41 PM
You're query is failing. 'for' is a reserved word in mysql: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

Change you're query to this:



$update = "UPDATE `fixturesresults` SET `wl` ='$wl', `for` ='$for', `against` ='$against' WHERE `urn` ='$urn'";

in order to use reserved words.
Those are backticks btw, they are hard to tell in a post.

Review my tutorial here for ideas of how to escape you're mysql data to prevent injections.

paddy100
01-21-2010, 01:42 PM
Hi ya, thanks for quick reply!!

more descriptive err which ll prob help....someone


Failed, please try again: 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 'for ='11', against ='2' WHERE urn ='2'' at line 1

paddy100
01-21-2010, 01:44 PM
You're query is failing. 'for' is a reserved word in mysql: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

Change you're query to this:



$update = "UPDATE `fixturesresults` SET `wl` ='$wl', `for` ='$for', `against` ='$against' WHERE `urn` ='$urn'";

in order to use reserved words.
Those are backticks btw, they are hard to tell in a post.

Review my tutorial here for ideas of how to escape you're mysql data to prevent injections.

Fou-Lu , You are a HERO!!!

thanks a million

will def be back here again, hopefully with more answers than questions :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum