6020 Shares

How to fix "undefined index" error in php?

How to fix "undefined index" error in php? Topic: Case select php mysql
July 18, 2019 / By Camryn
Question: I'm following a user photo album tutorial. For create the album I have this script. createalbum.php Please give a description to album $albumname
"; } ?> It comes on createalbum.php page after entering the name in this code on album.php Create an album
Now when I enter the name of album and hit create, I got this error on createalbum.php page. " Notice: Undefined index: albumdescription in C:\wamp\www\post\createalbum.php on line 12 " I tried to fix it by "isset" it dont show the error but also don't take the album description. Tell me please how to fix it?
Best Answer

Best Answers: How to fix "undefined index" error in php?

Amalee Amalee | 5 days ago
Okay, the problem is with this code here: $albumname = $_POST['albumname']; $albumdescription = $_POST['albumdescription']; if ($albumdescription){ The problem is that you're attempting to access and store submitted data ($_POST['albumname'], $_POST['albumdescription']) regardless of whether it's been submitted in the form or not which is triggered even if you aren't). Then, you're loosely attempting to see if $albumdescription is - to read it literally - not 0/false/NULL before feeding it into the database. PHP's basically trying to tell you that you're trying to access and use something that doesn't exist (because, again, it's not been submitted in the form yet!). So, given that you're *also* using this data as default values in your form, you might try, firstly, assigning default values to $albumname and $albumdescription (i.e. '') to make sure that they're able to be used in your below form regardless and THEN checking to see if the form data's been submitted BEFORE setting $albumname and $albumdescription to the submitted form data & inserting them to the database. There's quite a few ways you can go about this, but one solution might look something like this (please note that I tried to keep it as close to your original logic as I could, but please read over the comments): // Give the album name & description default values first. $albumname = ''; $albumdescription = ''; // Make sure they exist before setting it to it to avoid the notice. if (isset($_POST['albumdescription'])) $albumdescription = $_POST['albumdescription']; if (isset($_POST['albumname'])) $albumname = $_POST['albumname']; // Make sure that neither the album description nor name are empty if (!empty($albumdescription) && !empty($albumname)) { // NOTE: Be careful with your input here. // You'll want to make sure it's validated before going in to prevent anything nasty from happening. // MySQL supports a general function for that; mysql_real_escape_string(), which is cited in the source, however you should STILL make sure input is only what YOU want it to be. $create = mysql_query(" INSERT INTO albums VALUES ('','$id','$albumname','$albumdescriptio... 'store/nocover.jpg')"); echo "Album Created."; } // You're checking if the albumname is set here, not sure if that needs to be the case (sample doesn't indicate it). I've left it in here just in case. if (!empty($albumname)) { echo "
Please give a description to album $albumname
"; } Good luck!
👍 98 | 👎 5
Did you like the answer? How to fix "undefined index" error in php? Share with your friends

We found more questions related to the topic: Case select php mysql


Amalee Originally Answered: Can someone explain the "not used" or "undefined" interval in the binary representation?
All digital binary logic systems have a range of voltages which are valid for each of the two possible logic values. The numbers referred to in your question are the voltages for Standard TTL logic, which use a 5V± 0.25V chip supply. A valid Logic ' 0 ' is guaranteed to be recognized by the gate inputs, if it is in the range 0V to 0.8V While a Logic ' 1 ' guaranteed to be recognized by the gate inputs, if it is in the range 2v to 5.25V. From the two statements, any voltage exceeding 0.8V and less than 2.0V, is not a ' 0 ' or a ' 1 ' voltage. Terms for this range are, ' invalid ', ' undefined '. The voltage of any active digital input is switching between '1' and '0', and '0' and '1', and must pass through this undefined voltage range. For this reason it is also called the 'transition zone'. It should be pointed out that these are both worst case voltages. Logic ' 0 ' would be typically 0.2V, and Logic ' 1 ' close to 4.75V. These undefined voltages will never occur in a circuit that has been designed using the manufacturers guidelines. For 74LS07 IC voltages a see table on page 2 at LINK.
Amalee Originally Answered: Can someone explain the "not used" or "undefined" interval in the binary representation?
Typically when you transmit in a binary sequence, you send that data in groups, such as bytes. This makes it easier when sending data to devices when you are coding. The not used or undefined in data sheets refer to portions of the code that are just filler in the implementations. They have no affect on the system weather it is a 0 or a 1, but is needed to complete the sequence.
Amalee Originally Answered: Can someone explain the "not used" or "undefined" interval in the binary representation?
I see the problem in the web page that you referenced. It is quite vague and does not address the underlying reasoning/purpose of voltage logic levels. The link given below is a simple page that describes logic voltage levels with just a bit more detail. I believe that this page contains the answer that you desire. (Why such voltage levels exist. Relationship of output voltage levels to input voltage levels. Noise immunity/noise margin, etc.) http://www.allaboutcircuits.com/vol_4/ch...

Wainamoinen Wainamoinen
"Undefined index: ..." means that you're attempting to use an array index that doesn't exist. In this case, you're attempting to assign values that do not exist from the $_POST array into global variables. It would seem that your form doesn't use the names that your script is attempting to use (e.g. )
👍 30 | 👎 -1

Wainamoinen Originally Answered: (! ) Notice: Undefined variable: start in C:\wamp\www\view1.php on line 64 Call Stack # Time Memory Function?
The problem lies in the setting of the $start variable, there is a condition where the $start variable does not get defined. Here's a re-work of your code, to be a little more efficient: http://pastebin.com/UVGz1cPe Cheers, Gitlez Contact Gitlez (form) http://4a35d504.yyv.co/
Wainamoinen Originally Answered: (! ) Notice: Undefined variable: start in C:\wamp\www\view1.php on line 64 Call Stack # Time Memory Function?
uninvited visitors,,uh huh its 6 AM..TBO is going to sleep at 4 usually. already replaced a flat on a acquaintances motor vehicle. i wager this poem is about me? Or my visitor? very pleased poem about a making a song fly.. very dreamlike.

If you have your own answer to the question case select php mysql, then you can write your own version, using the form below for an extended answer.