Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP mysql update problem

Options
  • 29-08-2007 11:20am
    #1
    Registered Users Posts: 673 ✭✭✭


    Hi,

    Im running the script below and am getting a strange problem. If i echo out all the variables they are correct, if i echo out the $sql query everything is as it should be but when i check the updated row in the database everything is entered as a blank value.

    Also, if i remove the variables from the sql query and just type the required values in it works fine.

    Here's the script:

    [PHP]$address = $_POST;
    echo "address = ".$address."<br>";

    $descirption = $_POST;
    echo "description = ".$descirption."<br>";

    $status = $_REQUEST;
    echo "status = ".$status."<br>";

    $contact = $_REQUEST;
    echo "contact = ".$contact."<br>";

    $guide_price = $_POST;
    echo "guide price = ".$guide_price."<br>";

    $location = $_REQUEST;
    echo "location = ".$location."<br>";

    $bedrooms = $_REQUEST;
    echo "bedrooms = ".$bedrooms."<br>";

    $active = $_REQUEST;
    echo "active = ".$active."<br><br>";

    $sql = "UPDATE wiltshire_listings
    SET address = '".$address."',
    description = '".$descirption."',
    status = '".$status."',
    contact = '".$contact."',
    guide_price = '".$guide_price."',
    location = '".$location."',
    bedrooms = '".$bedrooms."',
    active = '".$active."'
    WHERE row_id = '".$_REQUEST."'
    ";

    $results = mysql_query ($sql)
    or die ("<br><br>Invalid query: " . mysql_error());[/PHP]

    And here's what is echo'd out:

    address = my address here
    description = My description Here
    status = To Let
    contact = Main Office
    guide price = 1500
    location = Kildare North
    bedrooms = 2
    active = Yes

    SQL = UPDATE wiltshire_listings SET address = 'my address here', description = 'My description Here', status = 'To Let', contact = 'Main Office', guide_price = '1500', location = 'Kildare North', bedrooms = '2', active = 'Yes' WHERE row_id = '7'

    Listing Edited Successfully.


    Anyone know why this might be happening?

    Thanks


Comments

  • Registered Users Posts: 3,594 ✭✭✭forbairt


    having a quick glance it looks to be ok .. row_id is a unique primary key ?


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Yep, its a strange one alright :confused:


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    Yep, its a strange one alright :confused:

    er you didn't answer .. :) ... possible you've got two row_id's 7 and one is getting updated and you're looking at the other ?

    possible you're pointing at the wrong database when you're viewing or when you're updating ? production / testing databases?


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Its a unique row_id alright. Just been playing around with it a bit more. If i add this:

    $address = $_POST;
    echo "address = ".$address."<br>";

    $descirption = $_POST;
    $descirption = 'test desciption';
    echo "description = ".$descirption."<br>";

    $status = $_REQUEST;
    echo "status = ".$status."<br>";

    $contact = $_REQUEST;
    $contact = 'main Office';
    echo "contact = ".$contact."<br>";

    $guide_price = $_POST;
    echo "guide price = ".$guide_price."<br>";

    $location = $_REQUEST;
    echo "location = ".$location."<br>";

    $bedrooms = $_REQUEST;
    echo "bedrooms = ".$bedrooms."<br>";

    $active = $_REQUEST;
    echo "active = ".$active."<br><br>";

    which is just hard coding two of the values, it adds these two but not any of the variable values even though when i echo them out they are all as they should be. Im totally stumped on this one. If i had echo'd out $description for example it would be main office so how it wont go into the database is beyond me.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    If i had echo'd out $description for example

    ....you'd have got nothing.....

    Didn't initially comment on the typo in the variable name, because I don't think it's relevant/causing the problem (I think it's misspelt everywhere), but after your last post spelling it correctly maybe there's somewhere that it does matter ?


  • Advertisement
  • Registered Users Posts: 3,594 ✭✭✭forbairt


    Liam Byrne wrote:
    ....you'd have got nothing.....

    Didn't initially comment on the typo in the variable name, because I don't think it's relevant/causing the problem (I think it's misspelt everywhere), but after your last post spelling it correctly maybe there's somewhere that it does matter ?

    didn't comment on it as it was consistent mostly throughout ... it was wrecking my head not commenting on it though :)


  • Registered Users Posts: 673 ✭✭✭Bananna man


    I see the mispelling now but its not to do with that. Its happening on all the variables.


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    next one then ... you're mixing your request and post variables up ...


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Maybe so, i thought you had to use request for dropdown lists. Either way all the variables are in the $sql query as they should be.


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    your $_REQUEST contains data from post / get and cookie information ...

    Your $_POST contains only data posted
    Your $_GET contains only get data

    usually forms will post data (but not necessarily)

    As to your main problem ... I'm kinda stumped ...nothing I can see at the moment without having access to the code / setup


  • Advertisement
  • Registered Users Posts: 673 ✭✭✭Bananna man


    I just did a mysql query directly in phpMYadmin and inserted what is echo'd in the $sql query, i.e.

    UPDATE my_listings SET address = 'gdfgdf', description = 'test desciption', status = 'To Let', contact = 'Main Office (045) 898022', guide_price = '555', location = 'Kildare North', bedrooms = '1', active = 'Yes' WHERE `row_id` = 11

    and its updates as expected. It must have something to do with the mysql_query() in the

    $results = mysql_query($sql)
    or die(mysql_error());

    line of code.

    The only other code included in this file is the database connection file and my transact user file so i'll have to have a dig around them and see if they could be causing a problem.... dont see how though.


  • Closed Accounts Posts: 7 AlbertH


    Query from original post
    SQL = UPDATE wiltshire_listings SET address = 'my address here', description = 'My description Here', status = 'To Let', contact = 'Main Office', guide_price = '1500', location = 'Kildare North', bedrooms = '2', active = 'Yes' WHERE row_id = '7'

    The row_id number shouldn't be in quotes assuming it is an integer - which it would be if it is a unique primary key.

    Compare this to your last post - no quotes around the number.

    UPDATE my_listings SET address = 'gdfgdf', description = 'test desciption', status = 'To Let', contact = 'Main Office (045) 898022', guide_price = '555', location = 'Kildare North', bedrooms = '1', active = 'Yes' WHERE `row_id` = 11

    Just remove the quotes from your query builder and all should be find.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    I had tried with quotes and without quotes.

    Anyway, i stripped all the html code out of this page and now just have the query and then a redirect to a new domain when its done and its working fine. Very strange indeed because i havent a clue what could have been causing this problem from my other html code... it didnt even conatin any variables or php.

    Alll very strange. Anyway its working now so thanks for all the input... the joys of coding ehhh :rolleyes:


Advertisement