etherealFire
New member
I'm completely new to SQL and PHP, and I know I could probably find the answer to my own question given enough time, but I want to get a working version of my website up soon.
My problem is with a PHP page I've been writing while following a tutorial that's only vaguely parrallel to my own codes. I'm creating a page on my website so that I can update my database using a form instead of SQL codes, and I've figure out quite a bit, but the mysql_fetch_array is giving me problems. The exact error message is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/********/domains/**********.*********.***/public_html/newanime.php on line 90
Here's the code I'm using, please let me know what some possible solutions might be. The only thing I can say without a doubt is that it connects to the database, and that the tablenames and column names in the code are exactly as they are on the tables themselves.
_________________________________
<?php
if ($submit):
if ($lid == "") {
echo("<P>You must select a letter " .
"For this anime. Click 'Back' " .
"and try again.</P>");
exit();
}
$dbcnx = @mysql_connect("*******", "********", "********");
mysql_select_db("animedb");
$sql = "INSERT INTO anime SET " .
"Name='$name', " .
"Episodes='$episodes', " .
"Studio='$studio', " .
"Distro='$distro', " .
"Description='$description', " .
"Review='$review', ";
if (mysql_query($sql)) {
echo("<P>New anime series added</P>");
} else {
echo("<P>Error adding new anime: " .
mysql_error() . "</P>");
}
$aid = mysql_insert_id();
$genres = mysql_query("SELECT ID, Name FROM animegenres");
while ($genre = mysql_fetch_array($genres)) {
$gid = $genre["ID"];
$gname = $genre["Name"];
$var = "genre$gid";
if ($$var) {
$sql = "INSERT IGNORE INTO genrelookup " .
"SET AID=$aid, GID=$gid";
$ok = mysql_query($sql);
if ($ok) {
echo("<P>Anime added to genre: $gname</P>");
} else {
echo("<P>Error inserting anime into genre $gname:" .
mysql_error() . "</P>");
}
}
}
?>
<P><A HREF="<?php echo($PHP_SELF); ?>">
Add another anime</A></P>
<P><A HREF="anime.php">Return to Anime Search</A></P>
<?php
else:
$dbcnx = @mysql_connect("*******", "*********", "*******");
mysql_select_db("animedb");
$genres = mysql_query(
"SELECT ID, Name FROM animegenres");
$letters = mysql_query(
"SELECT ID, Name FROM animeletters");
?>
<Form Action="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Enter the new anime name:<BR>
<TEXTAREA NAME="Name" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<P>Enter the starting letter:
<SELECT NAME="lid" SIZE=1>
<OPTION SELECTED VALUE="">SELECT ONE
<OPTION VALUE="">--------------
<?php
while ($letter = mysql_fetch_array($letters)) {
$lid = $letter["ID"];
$lname = $letter["Name"];
echo("<OPTION VALUE='$lid'>$lname\n");
}
?>
</SELECT></P>
<BR>
<P>Enter the number of episodes:<BR>
<TEXTAREA NAME="Episodes" ROWS=1 COLS=1 WRAP>
</TEXTAREA>
<BR>
<P>Place the genres this anime applies to:<BR>
<?php
while ($genre = mysql_fetch_array($genres)) {
$gid = $genre["ID"];
$gname = $genre["Name"];
echo("<INPUT TYPE=CHECKBOX NAME='genre$gid'>" .
"$gname<BR>\n");
}
?>
</P>
<BR>
<P>Enter the Production Studio:<BR>
<TEXTAREA NAME="Studio" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<P>Enter the US Distributor:<BR>
<TEXTAREA NAME="Distro" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<Center>
<P>Enter the anime description:<BR>
<TEXTAREA NAME="Description" ROWS=10 COLS=75 WRAP>
</TEXTAREA>
<BR>
<P>Enter the anime review:<BR>
<TEXTAREA NAME="Review" ROWS=10 COLS=75 WRAP>
</TEXTAREA></Center>
<P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
</Form>
<?php endif; ?>
My problem is with a PHP page I've been writing while following a tutorial that's only vaguely parrallel to my own codes. I'm creating a page on my website so that I can update my database using a form instead of SQL codes, and I've figure out quite a bit, but the mysql_fetch_array is giving me problems. The exact error message is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/********/domains/**********.*********.***/public_html/newanime.php on line 90
Here's the code I'm using, please let me know what some possible solutions might be. The only thing I can say without a doubt is that it connects to the database, and that the tablenames and column names in the code are exactly as they are on the tables themselves.
_________________________________
<?php
if ($submit):
if ($lid == "") {
echo("<P>You must select a letter " .
"For this anime. Click 'Back' " .
"and try again.</P>");
exit();
}
$dbcnx = @mysql_connect("*******", "********", "********");
mysql_select_db("animedb");
$sql = "INSERT INTO anime SET " .
"Name='$name', " .
"Episodes='$episodes', " .
"Studio='$studio', " .
"Distro='$distro', " .
"Description='$description', " .
"Review='$review', ";
if (mysql_query($sql)) {
echo("<P>New anime series added</P>");
} else {
echo("<P>Error adding new anime: " .
mysql_error() . "</P>");
}
$aid = mysql_insert_id();
$genres = mysql_query("SELECT ID, Name FROM animegenres");
while ($genre = mysql_fetch_array($genres)) {
$gid = $genre["ID"];
$gname = $genre["Name"];
$var = "genre$gid";
if ($$var) {
$sql = "INSERT IGNORE INTO genrelookup " .
"SET AID=$aid, GID=$gid";
$ok = mysql_query($sql);
if ($ok) {
echo("<P>Anime added to genre: $gname</P>");
} else {
echo("<P>Error inserting anime into genre $gname:" .
mysql_error() . "</P>");
}
}
}
?>
<P><A HREF="<?php echo($PHP_SELF); ?>">
Add another anime</A></P>
<P><A HREF="anime.php">Return to Anime Search</A></P>
<?php
else:
$dbcnx = @mysql_connect("*******", "*********", "*******");
mysql_select_db("animedb");
$genres = mysql_query(
"SELECT ID, Name FROM animegenres");
$letters = mysql_query(
"SELECT ID, Name FROM animeletters");
?>
<Form Action="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Enter the new anime name:<BR>
<TEXTAREA NAME="Name" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<P>Enter the starting letter:
<SELECT NAME="lid" SIZE=1>
<OPTION SELECTED VALUE="">SELECT ONE
<OPTION VALUE="">--------------
<?php
while ($letter = mysql_fetch_array($letters)) {
$lid = $letter["ID"];
$lname = $letter["Name"];
echo("<OPTION VALUE='$lid'>$lname\n");
}
?>
</SELECT></P>
<BR>
<P>Enter the number of episodes:<BR>
<TEXTAREA NAME="Episodes" ROWS=1 COLS=1 WRAP>
</TEXTAREA>
<BR>
<P>Place the genres this anime applies to:<BR>
<?php
while ($genre = mysql_fetch_array($genres)) {
$gid = $genre["ID"];
$gname = $genre["Name"];
echo("<INPUT TYPE=CHECKBOX NAME='genre$gid'>" .
"$gname<BR>\n");
}
?>
</P>
<BR>
<P>Enter the Production Studio:<BR>
<TEXTAREA NAME="Studio" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<P>Enter the US Distributor:<BR>
<TEXTAREA NAME="Distro" ROWS=1 COLS=25 WRAP>
</TEXTAREA>
<BR>
<Center>
<P>Enter the anime description:<BR>
<TEXTAREA NAME="Description" ROWS=10 COLS=75 WRAP>
</TEXTAREA>
<BR>
<P>Enter the anime review:<BR>
<TEXTAREA NAME="Review" ROWS=10 COLS=75 WRAP>
</TEXTAREA></Center>
<P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
</Form>
<?php endif; ?>