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 11 of 11
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts

    unable to update one column based on id

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());

    $sql ="SELECT * FROM table1 WHERE cat_id='{$_GET['cat_id']}' AND memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());

    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    mysql_query("UPDATE table1 SET url_path = 'http://www.website.com/prod_info.php?info_id=$info_id&main_id=$grouped_id&id=$abrev_id&cat_id=$cat_id' WHERE cat_id='{$_GET['cat_id']} AND memberid = '".$_SESSION['memberid']."'");
    }

    It echos http://www.website.com/prod_info.php...id=1&cat_id=29 so i know it passes ok, but it doesnt update the url_path.

    Please help.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Code:
    if(mysql_num_rows($result)){
    mysql_num_rows returns an integer or false if it fails, so what are you trying to with the above IF - do you need a minimum number of rows?

    Also echo out to the browser the actual evaluted "update" sql to see exactly what the query about to be run actually is.

  • #3
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I would i do that? Just echo the $url_path or the update query. Example please.

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    You can put the code for the sql query in a separate variable and then echo that variable to see the evaluated query about to be run.

  • #5
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());

    $sql ="SELECT * FROM table1 WHERE cat_id='{$_GET['cat_id']}' AND memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());

    while (
    $row mysql_fetch_array($result)) {

    $update mysql_query("UPDATE table1 SET url_path = 'http://www.website.com/prod_info.php?
    info_id=$info_id&main_id=$grouped_id&id=$abrev_id&cat_id=$cat_id' WHERE cat_id='{$_GET['cat_id']} AND memberid = '"
    .$_SESSION['memberid']."'");
    }


    if (!
    mysql_query($sql,$connection)) 

    die(
    'Could not add image Data. Report this error to the Administrator:' mysql_error()); 



    Echo 
    "$update"
    Like this?

    Nothing is being echoed.

  • #6
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Like this?
    no, and since you haven't answered my original question, it appears to me you didn't actually write the code you posted, but are looking for someone to fix the code you probably copied and pasted from somewhere.

  • #7
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Actually i did right the code and used a bunch of code from other files that i also wrote, which the update works on those files. I have never used the update query to update a table after an insert query which post info in the database with unique ids.

    I have spent hours and days writing this code. Well all the you see is 1/10th of it. Like i said, everything works but the update query.

    So i do need a little help on this update query.
    Last edited by twobyfour; 05-02-2011 at 02:06 AM.

  • #8
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    ok no problem, but since you still haven't answered my original question, I can't help anymore. Hopefully someone else will come along to help you.

  • #9
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    ok, got it.

    UPDATE table1 SET url_path = 'http://www.website.com/prod_info.php?info_id=38&main_id=1&id=1&cat_id=38' WHERE cat_id='38 AND memberid = '160211906'

  • #10
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Thumbs down

    Quote Originally Posted by bullant View Post
    ok no problem, but since you still haven't answered my original question, I can't help anymore. Hopefully someone else will come along to help you.
    Thanks for the help, although you gave up on me to quickly. Maybe you might try and help the person that you are going to respond too instead of accusing them of needing you to fix there coding issues. But anyway, I did get the code to work.

  • #11
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    no problem glad you sorted it out.

    But the reason I moved onto a higher priority request is because you didn't provide the information I asked for.

    ok no problem, but since you still haven't answered my original question, I can't help anymore.
    If you don't answer other peoples' questions it's only reasonable imo that they can then choose to move onto something else

    I also didn't accuse you of anything. What I said was
    ....it appears to me you didn't actually write the code you posted....
    Last edited by bullant; 05-03-2011 at 12:58 AM.


  •  

    Posting Permissions

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