View Single Post
  #1 (permalink)  
Old Apr 21st, 2008, 11:18
Sphinx111 Sphinx111 is offline
New Member
Join Date: Apr 2008
Location: York
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Undefined Index error with DB

Having issues trying to combat the dreaded "Undefined index:" error with the "author_id" variable at line 6.

I can't quite see where I'm going wrong. The idea is to update some aspects of the database for my wife's book shop, but when I call the page, it loads with this variable problem. In the below example author_id is one of the fields of a table I created in an SQL database called author.

Maybe I just have my fundamentals wrong Either way, at least I can tell the missus I tried.

Code: Select all
<?php
 
include("dbinfo.inc.php");
$comm=@mysql_connect(localhost,$username,$password);
$rs=@mysql_select_db($database) or die( "Unable to select database"); 
$author_id = $_POST['author_id'];
echo "Reference: $author_id<br><BR>";
 
$sql="SELECT * FROM author WHERE reference='$author_id'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$author_name=mysql_result($result,$i,"author_name"); ?>
 
++$i;
}
?>


P.S. I tried reading all the material I could on these forums, based on the Undefined index error, but no luck with regard to this situation.
Reply With Quote