Web Design and Development Forums

Undefined Index error with DB

This is a discussion on "Undefined Index error with DB" within the PHP Forum section. This forum, and the thread "Undefined Index error with DB are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 21st, 2008, 11:18   #1 (permalink)
New Member
 
Join Date: Apr 2008
Location: York
Posts: 2
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.
Sphinx111 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 12:35   #2 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 517
Blog Entries: 4
Re: Undefined Index error with DB

Line six is this line:

PHP: Select all

$author_id $_POST['author_id']; 

And undefined index means one PHP can't find a certain section of an array, in this case $_POST['author_id']. So $_POST['author_id'] must not be set.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 14:25   #3 (permalink)
New Member
 
Join Date: Apr 2008
Location: York
Posts: 2
Re: Undefined Index error with DB

Thank you for the swift response.

Excuse my illiteracy, but would I need to set the $_POST['author_id'] in a previous PHP page? Or amend the SQL database?

The table I am trying to access (a list of author's of books) has the primary key author_id; I thought it would be possible to identify the fields of this table via the key, and was using the aforementioned code to call that data, so that it could be edited if neccesary.

Regards.
Sphinx111 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 21st, 2008, 20:37   #4 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 517
Blog Entries: 4
Re: Undefined Index error with DB

Undefined index 'author_id' means (In your situation) that there is no post data for author_id. So whatever form is submitting data to this query is not sending any information for author_id through POST. Either you've made an error and misnamed 'author_id' or the form data is being sent through GET or not at all.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined index problem andrewlondon PHP Forum 12 Sep 2nd, 2007 12:19
Another with IE woes - Element is undefined weasel HTML Forum 3 Jul 5th, 2007 18:18
Undefined variable: row csun PHP Forum 3 Jun 5th, 2007 12:44
Undefined index using $GET_ LostProphet PHP Forum 7 Aug 22nd, 2006 11:15
Having trouble with scripts. Fatal error: Call to undefined function: imagegif() cargi PHP Forum 5 Jan 6th, 2006 18:59



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 10:56.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59