473,671 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Notice: Undefined index ERROR - Help!

38 New Member
Hey there, it has to be said that I am a complete novice in PHP, I know this is a common error and has probably been covered to some degree already - but my head really does hurt - so I couldn't stand trawling through anymore forums hunting for the right answer. Anyway - here goes.

The page I'm having trouble with is a simple edit row type form, which brings up the specific row content specified by the id(albumNumber) passed from the previous page, select.php. The page allows the user to edit, and then update the row displayed.


The full error message...

Notice: Undefined index: submit in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 12

The full php - taken and adapted from a tutorial I found...
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. // Connect database 
  4. mysql_connect("","",""); 
  5.  
  6. //select which database you want to edit
  7. mysql_select_db(""); 
  8.  
  9. // ***** This part will process when you Click on "Submit" button ***** 
  10. // Check, if you clicked "Submit" button 
  11. if($_POST['submit']) 
  12. {
  13.  
  14. // Get parameters from form. 
  15. $albumNumber=$_POST['albumNumber'];
  16. $artistName=$_POST['artistName'];
  17. $albumName=$_POST['albumName'];
  18. $albumInfo=$_POST['albumInfo'];
  19. $albumReview=$_POST['albumReview'];
  20.  
  21. // Do update statement. 
  22. mysql_query("UPDATE Albums SET artistName='$artistName', albumName='$albumName', albumInfo='$albumInfo', albumReview='$albumReview' WHERE albumNumber='$albumNumber'");
  23.  
  24. // Re-direct this page to select.php.
  25.    echo "Query Finished";
  26.    header("location:select.php");
  27.  
  28.  
  29. }
  30. // ************* End update part *************
  31.  
  32. // *** Select data to show on text fields in form. ***
  33.  
  34. // Get id parameter (GET method) from select.php 
  35. $albumNumber=$_GET['albumNumber'];
  36.  
  37. // Get records in all columns from table where column id equal in $id and put it in $result.
  38. $result=mysql_query("select * from Albums where albumNumber='$albumNumber'");
  39.  
  40. // Split records in $result by table rows and put them in $row. 
  41. $row=mysql_fetch_assoc($result);
  42.  
  43. // Close database connection. 
  44. mysql_close();
  45. ?>
  46.  
  47. <!-- END OF PHP CODES AND START HTML TAGS -->
  48.  
  49. <html>
  50. <body>
  51. <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> 
  52. <form id="form1" name="form1" method="post" action="update.php">
  53.   <p>albumName : <br>
  54.     <input name="albumName" type="text" id="albumName" value="<? echo $row['albumName']; ?>" size="40"/>
  55.     <br />
  56.     artistName :<br>
  57.     <input name="artistName" type="text" id="artistName" value="<? echo $row['artistName']; ?>" size="40"/>
  58.     <br />
  59.     albumInfo : <br>
  60.     <textarea name="albumInfo" cols="40" rows="4" id="albumInfo"><? echo $row['albumInfo']; ?></textarea>
  61.     <br />
  62.     albumReview :<br>
  63.     <textarea name="albumReview" cols="40" rows="10" id="albumReview"><? echo $row['albumReview']; ?></textarea>
  64.     <br />
  65.   </p>
  66. <p>
  67. <input type="submit" name="Submit" value="Submit" />
  68. </p>
  69. </form> 
  70. </body>
  71. </html>
  72.  

Any help would be much appreciated. The line if($_POST['submit']) work perfectly well in another scripts which adds new rows to the database.

Thanks in advance.
Oct 12 '07 #1
7 2529
Motoma
3,237 Recognized Expert Specialist
Hey there, it has to be said that I am a complete novice in PHP, I know this is a common error and has probably been covered to some degree already - but my head really does hurt - so I couldn't stand trawling through anymore forums hunting for the right answer. Anyway - here goes.

The page I'm having trouble with is a simple edit row type form, which brings up the specific row content specified by the id(albumNumber) passed from the previous page, select.php. The page allows the user to edit, and then update the row displayed.


The full error message...

Notice: Undefined index: submit in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 12

The full php - taken and adapted from a tutorial I found...

<?

// Connect database
mysql_connect(" ","","");

//select which database you want to edit
mysql_select_db ("");

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['submit'])
{

// Get parameters from form.
$albumNumber=$_ POST['albumNumber'];
$artistName=$_P OST['artistName'];
$albumName=$_PO ST['albumName'];
$albumInfo=$_PO ST['albumInfo'];
$albumReview=$_ POST['albumReview'];

// Do update statement.
mysql_query("UP DATE Albums SET artistName='$ar tistName', albumName='$alb umName', albumInfo='$alb umInfo', albumReview='$a lbumReview' WHERE albumNumber='$a lbumNumber'");

// Re-direct this page to select.php.
echo "Query Finished";
header("locatio n:select.php");


}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$albumNumber=$_ GET['albumNumber'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_q uery("select * from Albums where albumNumber='$a lbumNumber'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetc h_assoc($result );

// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="update. php">
<p>albumName : <br>
<input name="albumName " type="text" id="albumName" value="<? echo $row['albumName']; ?>" size="40"/>
<br />
artistName :<br>
<input name="artistNam e" type="text" id="artistName " value="<? echo $row['artistName']; ?>" size="40"/>
<br />
albumInfo : <br>
<textarea name="albumInfo " cols="40" rows="4" id="albumInfo"> <? echo $row['albumInfo']; ?></textarea>
<br />
albumReview :<br>
<textarea name="albumRevi ew" cols="40" rows="10" id="albumReview "><? echo $row['albumReview']; ?></textarea>
<br />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>



Any help would be much appreciated. The line if($_POST['submit']) work perfectly well in another scripts which adds new rows to the database.

Thanks in advance.

Indexes are case sensitive: in your HTML you use the name "Submit" however, in your $_POST you are asking for "submit" instead.

Typically, checks on POST and GET variables are coupled with an isset in order to ensure no NOTICEs are sent in the (typically acceptable) cases where no data is sent to the page:

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
  2.  
In your case, being that there is only one potential value for Submit, you really only need to check isset().
Oct 12 '07 #2
Philth
38 New Member
Thanks for that!

Seems to have done the job - no more error messages!

Only thing now is that it doesn't actually update the row. Nothing happens. Hmmm!
Oct 12 '07 #3
Motoma
3,237 Recognized Expert Specialist
Thanks for that!

Seems to have done the job - no more error messages!

Only thing now is that it doesn't actually update the row. Nothing happens. Hmmm!
Take out the header() call to make sure that the MySQL query isn't giving you an error.
Oct 12 '07 #4
Philth
38 New Member
Oh right, I see! New problem I think.

Notice: Undefined index: albumNumber in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 16


Notice: Undefined index: albumNumber in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 35
Oct 12 '07 #5
Motoma
3,237 Recognized Expert Specialist
Oh right, I see! New problem I think.

Notice: Undefined index: albumNumber in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 16


Notice: Undefined index: albumNumber in /home/fhlinux162/g/greatestalbumse ver.com/user/htdocs/php/update.php on line 35
Same problem as before. Please read the error message before posting a question.

Cypher:
"Undefined index on Line 16"
Translation:
On line 16, you are using a variable as an array, and you are trying to look at an element in that array which does not exist.
Oct 12 '07 #6
Philth
38 New Member
Same problem as before. Please read the error message before posting a question.

Cypher:
"Undefined index on Line 16"
Translation:
On line 16, you are using a variable as an array, and you are trying to look at an element in that array which does not exist.

I had read the error report. Is is not the case that once this 'if' statement is read the variable in this array would exist? Please bare with me - I'm a completely ignoramous. The 'albumNumber' variable in line 16 has already been passed to this form and does exist. It's strange that this script is supplied by php tutorial websites when there are parts which are fundamentally wrong.
Oct 12 '07 #7
Motoma
3,237 Recognized Expert Specialist
I had read the error report. Is is not the case that once this 'if' statement is read the variable in this array would exist? Please bare with me - I'm a completely ignoramous. The 'albumNumber' variable in line 16 has already been passed to this form and does exist. It's strange that this script is supplied by php tutorial websites when there are parts which are fundamentally wrong.
I am running under the assumption that line 16 is:

$albumNumber=$_ POST['albumNumber'];

Take a look at your code to verify this.

$albumNumber and $_POST are variables, 'albumNumber' is an index into the $_POST variable. In order for $_POST['albumNumber'] to have a value, there needs to be a field named 'albumNumber' in your HTML.
Oct 12 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4698
by: siliconmike | last post by:
apache error log: /var/log/httpd-error.log gets filled up with various notices such as: php notice: Use of undefined constant name - assumed 'name' in xxxxx on line 1, referer: yyyy the size of the file is 200 mb now..
6
20847
by: jsgoodrich | last post by:
I am looking for some help if anyone can lend a hand. I have a simple php website that displays a table from my mysql database. To prep for my MCSE I moved my home server to Windows 2003 Standard, I installed mysql and php 5 to run some of my databases and websites. Under Linux the site worked fine, under windows I keep getting Notice Undefined Index error on line 67
3
5494
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email...
2
10631
by: Reggie | last post by:
am trying to create a a upload file.am uploading files ok but i recieve this message. Notice: Undefined variable: uploaded_size in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on line 7 Notice: Undefined variable: uploaded_type in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on line 14 Notice: Undefined index: uploadedfile in /home/fhlinux169/c/
3
3868
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if (empty($info)) { $info='noinfo'; } changeinfo($info); Hey everyone, I keep getting an error regarding the above code. These are the errors: Notice: Undefined index: channels in /home/forcefed/public_html/index.php on line 5
5
7361
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : $http_ref= $HTTP_REFERER; $prog = $_COOKIE;
1
2736
by: francsutherland | last post by:
Notice: Undefined index: send in D:\Domains\workingdata.co.uk\wwwroot\contact_text.php on line 7 Hi, I've started getting this error in the contact page form of my website. The web hosting company did an upgrade and it seems to coincide with that. The Notice is at the top of the page, but the rest of the page displays normally and form still works. I don't get the Notice when I test the page on the local Apache server in the XAMPP...
11
6729
by: stealthmode666 | last post by:
New to .php so need script help. I want to know how to stop this being displayed when I click submit. Notice: Undefined index: homeowner in E:\domains\r\...\user\htdocs\...\form.php on line 166 I have an array which takes filled in fields and blank fields and sends them via email. I DON'T need the user to fill in all the fields which is resulting in this notice on every field that is not filled in. I do need the fields to be sent tho'...
2
4583
by: Smellydog | last post by:
I'm having a strange issue with PHP version 5.2.8 running on Windows Vista with Lighttpd. I receive a Notice that says the following: Notice</b>: Undefined index: name in <b>E:\LightTPD\htdocs\go\go\form.php</b> on line <b>160</b> Here is the odd part. No matter what I do, no matter how many times I change the script, add lines, remove lines, the notice keeps referencing the same file and line number. Even when I comment out the line,...
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.