Thread: Help with

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Finland, Hanko
    Posts
    17
    Rep Power
    0
    I´m trying to check whether update is succesful or not, and I use the mysql_affected_rows function to do it. I used this script below earlier in my workstation (nt/php3/mysql 3.3x?) and it worked fine, but I moved my scripts to our webserver(linux/php4/mysql???) and now they aren´t working right anymore. I get this warning:
    Supplied argument is not a valid MySQL-Link resource in "scriptpath"
    on line 27. Warnings come from both mysql_affected_rows function:

    My Script:
    //mysql clause
    $kaikki = mysql_query("select * from henkilo");

    //update clause
    $lisays = mysql_query("update henkilo
    set sukunimi = '$sukunimi', etunimi = '$etunimi', titteli = '$titteli', yritys_id = '$yritys_id', osoite = '$osoite', postinumero = '$postinumero', kaupunki = '$kaupunki' ,maa = '$maa', puhelin = '$puhelin', gsm = '$gsm', email ='$email', kuvapolku ='$kuvapolku', muuta ='$muuta'
    where henkilo_id = '$henkilo_id'
    ");
    //mysql check
    if (mysql_affected_rows($lisays)==1){
    echo "<b>Päivitys onnistui:</b>" ;
    echo "<i><br>" , $sukunimi , " tiedot päivitetty</i>";
    }
    elseif (mysql_affected_rows($lisays) != 1){
    echo "<b>Päivitys epäonnistui</b>" , mysql_error();
    exit;
    }
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    Are you sure the two databases are set up the same? An error like that usually means the UPDATE failed, and nothing was assigned to $lisays.

    I usually check my updates the following way:

    $lisays = mysql_query("update ... ");
    if ($lisays)
    {
    echo "UPDATE successful";
    }
    else
    {
    echo "Database Error: " . mysql_error();
    }

    This works because if the update is successful, $lisays will be assigned some value, but if it fails, then $lisays will be zero.

    ---JH
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Finland, Hanko
    Posts
    17
    Rep Power
    0
    The updates don´t fail, they assigns the new values to tables, but the script goes to warnings and jumps to here:
    elseif (mysql_affected_rows($lisays) != 1){
    ...
    }

    But still the updates happens right.
    And my scripts works fine in my NT-workstation with php3, but not with Linux-webserver with PHP4.
    Maybe I have to change the update/delete checks like you are doing them.
    Thanx for help.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    The problem is that mysql_affected_rows() uses the link identifier as the argument, NOT the result index. You can also safely omit the argument if you have only one link to a mysql server open at the time.

IMN logo majestic logo threadwatch logo seochat tools logo