Could some one check my code
| From: | PAUL FERRIE | Date: | Wed, 26 Nov 2003 11:23:19 +0000 |
| Subject: | Could some one check my code | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-171025@lists.php.net to get a copy of this message | ||
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'];
echo"Error! 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 =
$id<br><br>";
echo"<a href='edit2.php?tablename=$tablename&id=$id'>Edit
record</a><br>";
}
}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