Hey guys,

I'm trying to write a peice of code that basically checks if the input field have been submitted, it is an update code so I have designed it so that when the user clicks "update" another page displays saying "well done object updated".

However when i do this the (isset($_POST)) bit of code is not reading it as being completed, it just comes up with my errors, "You forgot to enter an id" etc.

My code is:

echo '<html><head><link rel= stylesheet  href= style.css ></head>
<p><h2>Update Existing Event&hellip;</h2></p>
<strong>Please do not leave blanks</strong>
<table background="#29552E" border = 1 align = "center" width = 120% cellspacing ="1" cellpadding = "4">
<form action = updateprice.php method = POST>
<tr bgcolor = #00688B >
<td width = 4%><b>ID</b></td>
<td width = 4%><b>Name</b></td>
<td width = 8%><b>Price</b><font size = 1><br>(numbers only)</b></td></tr>

if ($result){	
//fetch and print
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
	   $bg =($bg =='#FFCC99 '? '#ffffff': '#FFCC99');
echo '<tr >

<td>    <input type = text size = 30 id = id  value ="' .  $row['id']     . '" disabled></text></td>
<td>    <input type = text size = 30 id = it value = "' .  $row['item']   . '"</text></td>
<td>    <input type = text size = 10 id = pr value = "' .  $row['price']  . '"</text></td>


	}//end while
<div align="center"><input type="submit" name="submit" value="Update" /></div>
	<input type="hidden" name="submitted" value="TRUE" />



//check form values
if (isset($_POST['submitted'])){	

//make a one time connection to the database

//set up an errors array
   $errors = array ();

//check id
   $errors[] ='You forgot to enter an id ';
   $ud_id = escape_data(htmlspecialchars($_POST['id']));
}//end id

//check item
   $errors[] ='You forgot to enter a name ';
   $ud_item = escape_data(htmlspecialchars($_POST['item']));
}//end item

//check price
   $errors[] ='You forgot to enter a price ';
   $ud_price = escape_data(htmlspecialchars($_POST['price']));
}//end price

}//end if $_POST['submitted']



The $_POST is empty.

<td> <input type = text size = 30 id = id value ="' . $row['id'] . '" disabled></text></td>

You never gave the inputs a name attribute. While assigning both a name and id is good practice, php is looking specifically for the name attribute. Also remember to put quotes around the attributes values.

<td> <input type = "text" size = "30" name="id" id = "id" value ="' . $row['id'] . '" disabled="disabled" /></td>

From now on, please wrap your code in code tags instead of inlinecode so it's easier to read. Thanks!

Edited 3 Years Ago by pritaeas: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.