Hello..
I'm the newbie one.

I have the file in php.

I cannot solving the notice about Notice: Undefined index: add_item1 in C:\xampp\htdocs\guideline\xmladd_evidence.php on line 44

How to solving that?

here my code

<html>
<font size="20" face="arial" color="black">
<center><b> Add item evidence </b></center><br><hr/>
</font>

<form ACTION="" METHOD="POST">

<select name='add_item1[]' size=5 multiple>
<option value='call log'> call log</option>
<option value='SMS'> SMS </option>
<option value='people'> People </option>
<option value='Browser bookmarks '> Browser bookmarks </option>
<option value='Browser searches'>Browser searches </option>
<option value='MMS'>MMS</option>
<option value='MMS parts'>MMS parts</option>
<option value='external media'>external media</option>
<option value='external videos'>external videos</option>
<option value='internal image media'>internal image media </option>
<option value='internal video'>internal video </option>
<option value='internal thumb media'>internal thumb media</option>
<option value='IM Account'>IM Account</option>
<option value='IM Accounts'>IM Accounts</option>
<option value='IM chats'>IM chats</option>
<option value='IM contacts'>IM contacts</option>
<option value='IM invitation'>IM invitation</option>
<option value='IM providers'>IM providers</option>
<option value='IM provider setting'>IM provider setting</option>	
<option value='Contact methods'>Contact methods</option>
<option value='Contact extensions'>Contact extensions</option>
<option value='Contact groups'>Contact groups</option>
<option value='Contact Organizations'>Contact Organizations</option>
<option value='Contact Phones'>Contact Phones</option>
<option value='Contact Settings'>Contact Settings</option>	
</select>

<input type=submit name="add_item" value="add item">

</form>
</html>	

<?php
$add_item=0;
$add_item=$_POST['add_item1'];
if(is_array($add_item)){
while (list($key,$val)=each($add_item)){
echo "$val<br>";
echo "<a href='index.php?page=$val'> fill in the form </a>";
}

}
?>

thanks for your help..

First, to be clear, you *can* use elements of arrays as the 'name=' in forms, as in

<input type="checkbox" name="slotsel[$i]" $slotchk[$i]>
  <input type='hidden' name="titles[$topic]" value="$titles[$topic]">

as you seem to be trying. I've been doing it for years; associative arrays also work. The result is that all the inputs of a form can be put into an array, be retrieved in PHP using a single read of $_POST, and be iterated in a loop in PHP; I believe they can also be iterated in a loop in javascript. Contrast this with putting each input value into a separate variable.

$_POST is empty (undefined) the first time a script is run; in this case, that warning is to be exxpected.

In line 9 (<select name='add_item1[]' size=5 multiple>), try putting an index between the brackets.

First, to be clear, you *can* use elements of arrays as the 'name=' in forms, as in

<input type="checkbox" name="slotsel[$i]" $slotchk[$i]>
  <input type='hidden' name="titles[$topic]" value="$titles[$topic]">

as you seem to be trying.

I have already trying to use elements of arrays but still undefined index.

$_POST is empty (undefined) the first time a script is run; in this case, that warning is to be exxpected.

So, I can get input the warning. on java script isn't? how can I put in to my php syntax? any code?

In line 9 (<select name='add_item1[]' size=5 multiple>), try putting an index between the brackets.

I have already trying but still cannot solve.

do i have to give warning at an early stage?
any syntax?

thanks for your help..

Do you mean something like

if (isset($_POST['add_item1'] {

Undefined index is just a warning, not an error and it is just advising to check if the variable exists or has a value so all you have to do is out an if statement in your code and in your case around the whole php by the look of it:

<?php
if (isset($_POST['add_item1'])) { 
// Your current php code here
}
?>

Thank you very much for Fest3er and simplypixie ...

No problem - please now mark as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.