Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    UPDATE query not working correctly.... Arrrgh =D

    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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change
    if(mysql_query($update)){
    echo "updated score urn $urn into the database";}
    else{
    echo "Failed, please try again";}
    to
    PHP Code:
    f(mysql_query($update)){
    echo 
    "updated score urn $urn into the database";}
    else{
    echo 
    "Failed, please try again: "mysql_error();} 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're query is failing. 'for' is a reserved word in mysql: http://dev.mysql.com/doc/refman/5.1/...ved-words.html

    Change you're query to this:
    PHP Code:

    $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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You're query is failing. 'for' is a reserved word in mysql: http://dev.mysql.com/doc/refman/5.1/...ved-words.html

    Change you're query to this:
    PHP Code:

    $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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •