[PHP] Could some one check my code
i am getting this error returned but i dont know why :( error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pferrie/public_html/vinrev/adm/insert2.php on line 6 php file ?php include(connection.php); if(!empty($rating)){ $query=SELECT * FROM $tablename WHERE rating = '$rating'; if(mysql_query($query)) { $myrow = mysql_fetch_array($query);// This line returns an error! $id = $myrow ['id']; echoError! There is another row in the database with a rating value of $rating\n You must first edit the row with a rating of $rating ! Row id = $idbrbr; echoa href='edit2.php?tablename=$tablenameid=$id'Edit record/abr; } }else { if(!empty($_FILES['userfile']['tmp_name'])) { $name = strtolower(eregi_replace('#| |\?|!', '', $_FILES['userfile']['name'])); $destination = 'img/'.$name; if(move_uploaded_file($_FILES['userfile']['tmp_name'], $destination)) { $picture=$destination; $query = INSERT INTO $tablename (artist, title, picture, review, label, format, price, rating)VALUES ('$artist', '$title', '$picture', '$review', '$label', '$format', '$price', '$rating'); if(!mysql_query($query)) { fail(Error updating DB1); } Header(Location: main.php?success=New row has been inserted into the database); } } if(empty($userfile)) { $query2 = INSERT INTO $tablename (artist, title, picture, review, label, format, price, rating)VALUES ('$artist', '$title', '$picture', '$review', '$label', '$format', '$price', '$rating'); if(!mysql_query($query2)) { fail(Error updating DB2); } Header(Location: main.php?success=New row has been inserted into the database); } } ? I am trying to check for a duplicate entry for rating and if one is found grab the row ID and then use it to load the edit page for the row. Anyone Cheers Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could some one check my code
PAUL FERRIE wrote: i am getting this error returned but i dont know why :( error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pferrie/public_html/vinrev/adm/insert2.php on line 6 php file ?php include(connection.php); if(!empty($rating)){ $query=SELECT * FROM $tablename WHERE rating = '$rating'; if(mysql_query($query)) { $myrow = mysql_fetch_array($query);// This line returns an error! you sould write : if ($result = mysql_query($query)) { $myrow = mysql_fetch_array($result); Hope this helps -- Cordialement, --- Sophie Mattoug Développement web dynamique [EMAIL PROTECTED] --- $id = $myrow ['id']; echoError! There is another row in the database with a rating value of $rating\n You must first edit the row with a rating of $rating ! Row id = $idbrbr; echoa href='edit2.php?tablename=$tablenameid=$id'Edit record/abr; } }else { if(!empty($_FILES['userfile']['tmp_name'])) { $name = strtolower(eregi_replace('#| |\?|!', '', $_FILES['userfile']['name'])); $destination = 'img/'.$name; if(move_uploaded_file($_FILES['userfile']['tmp_name'], $destination)) { $picture=$destination; $query = INSERT INTO $tablename (artist, title, picture, review, label, format, price, rating)VALUES ('$artist', '$title', '$picture', '$review', '$label', '$format', '$price', '$rating'); if(!mysql_query($query)) { fail(Error updating DB1); } Header(Location: main.php?success=New row has been inserted into the database); } } if(empty($userfile)) { $query2 = INSERT INTO $tablename (artist, title, picture, review, label, format, price, rating)VALUES ('$artist', '$title', '$picture', '$review', '$label', '$format', '$price', '$rating'); if(!mysql_query($query2)) { fail(Error updating DB2); } Header(Location: main.php?success=New row has been inserted into the database); } } ? I am trying to check for a duplicate entry for rating and if one is found grab the row ID and then use it to load the edit page for the row. Anyone Cheers Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could some one check my code
On Wed, Nov 26, 2003 at 11:23:19AM -, PAUL FERRIE wrote: : : i am getting this error returned but i dont know why :( : error: : : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result : resource in /home/pferrie/public_html/vinrev/adm/insert2.php on line 6 : : php file : ?php : include(connection.php); : if(!empty($rating)){ : $query=SELECT * FROM $tablename WHERE rating = '$rating'; : if(mysql_query($query)) { : $myrow = mysql_fetch_array($query);// This line returns an error! mysql_query() might fail, in which case it returns a boolean FALSE. You should first check whether the query succeeded or failed. $result = mysql_query($query); if ($result === false) { // query failed, report the error echo mysql_error(); } else { // query succeeded, do your thing } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Could some one check my code
PAUL FERRIE wrote: i am getting this error returned but i dont know why :( error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pferrie/public_html/vinrev/adm/insert2.php on line 6 php file ?php include(connection.php); if(!empty($rating)){ $query=SELECT * FROM $tablename WHERE rating = '$rating'; if(mysql_query($query)) { $myrow = mysql_fetch_array($query);// This line returns an error! You need to capture the return value of mysql_query(). mysql_query() is going to return a Resource that should be passed to mysql_fetch_array(), so it knows where to get each row from. if($result = mysql_query($query)) { $myrow = mysql_fetch_array($result); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php