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:
CODE FOR INPUTTING:

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>


</tr>';

	}//end while
echo'
<tr>
<div align="center"><input type="submit" name="submit" value="Update" /></div>
	<input type="hidden" name="submitted" value="TRUE" />
</tr>
</form>
</table>';

CODE FOR CHECK SUBMITTED:

<?

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

//make a one time connection to the database
require_once('../sqlconnect/connect.php');

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

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

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

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

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

?>

Cheers

Recommended Answers

All 2 Replies

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!

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.