i have a following Error. i have a Sticky Fourm that should post to itself.
but i am getting undefined id on line 121 when i hit update
$query = mysqli_query($connection,'SELECT * FROM orders WHERE order_id = "'.$_REQUEST['order_id']. '"');
The URL IS THE FOLLOWING
localhost/order.php?pizzaSize=large&addAnchovies=y&addPineapple=y&addPepperoni=y&addOlives=y&addOnion=y&addPeppers=y&customerName=Test+TEST&address=12&emailAddress=123%40test.com&phoneNo=123123&update=update&id=5527b31e0aaa4
Code: Select all
//SHOW STICKY FORUM
if(isset($_POST['STICKFORUM']))
{
$query_sticky = mysqli_query($connection,'SELECT * FROM orders WHERE order_id = "' . $_GET['order_id'] . '"');
if(! $query_sticky )
{
die('Could not get data: ' . mysqli_error($connection)); // Could not find Order_id show Error
}//end die error
else{
while($row = mysqli_fetch_array($query_sticky, MYSQLI_ASSOC))
{
echo '<form action="vieworder.php?order_id="'.$row['order_id'].'" "method="POST">';
echo'<div id="pizzaSize">';
echo"<h3>What Size of Pizza Would You Like? </h3>";
echo "Small";
echo '<input id="small" type="radio" name="pizzaSize" onChange="redraw()" value="' . $row['size'] . '"' . ($row['size'] == 'small' ? ' checked="checked"' : '') . ' />';
echo "Medium";
echo'<input id="medium" type="radio" name="pizzaSize" onChange="redraw()" value="' . $row['size'] . '"' . ($row['size'] == 'medium' ? ' checked="checked"' : '') . ' />';
echo"Large";
echo'<input id="large" type="radio" name="pizzaSize" onChange="redraw()" value="' . $row['size'] . '"' . ($row['size'] == 'large' ? ' checked="checked"' : '') . ' />';
echo'</div>';
echo'<br>';
echo'<div id="ExtraToppings">';
echo" <h3>Add Extra Toppings</h3>";
echo' Anchovies';
echo' <input id="anchovies" type="checkbox" name="addAnchovies" onChange="redraw()" value="' . $row['anchovies'] . '"' . ($row['anchovies'] == 'y' ? ' checked="checked"' : '') . ' />';
echo'Pineapple';
echo'<input id="pineapple" type="checkbox" name="addPineapple" onChange="redraw()" value="' . $row['pineapples'] . '"' . ($row['pineapples'] == 'y' ? ' checked="checked"' : '') . ' />';
echo' Pepperoni';
echo' <input id="pepperoni" type="checkbox" name="addPepperoni" onChange="redraw()" value="' . $row['pepperoni'] . '"' . ($row['pepperoni'] == 'y' ? ' checked="checked"' : '') . ' />';
echo' Olives';
echo' <input id="olives" type="checkbox" name="addOlives" onChange="redraw()" value="' . $row['olives'] . '"' . ($row['olives'] == 'y' ? ' checked="checked"' : '') . ' />';
echo'Onion';
echo' <input id="onion" type="checkbox" name="addOnion" onChange="redraw()" value="' . $row['onions'] . '"' . ($row['onions'] == 'y' ? ' checked="checked"' : '') . ' />';
echo' Peppers';
echo' <input id="peppers" type="checkbox" name="addPeppers" onChange="redraw()" value="' . $row['peppers'] . '"' . ($row['peppers'] == 'y' ? ' checked="checked"' : '') . ' />';
echo' </div>';
echo'<div id="totalPrice">';
echo'<h3>Total Price is: €<span id="pricetext">18</span></h3>';
echo'</div>';
echo' <div id="yourDetails">';
echo' <h3>Enter your details</h3>';
echo'Name:';
echo'<input name="customerName" id="cname" type="text" required value="'.$row['firstname']. " " .$row['lastname']. '" />';
echo' <br/>';
echo' <br/>';
echo' Address:';
echo'<textarea name="address" id = "caddress" type="text" rows="5" cols="30" required value="'.$row['address'].'" ></textarea>';
echo'<br/>';
echo' <br/>';
echo' Email Address:';
echo' <input name="emailAddress" type="email" required value="'.$row['email']. '" />';
echo' <br/>';
echo' <br/>';
echo' <br/>';
echo'Phone Number:';
echo' <input name="phoneNo" id="phoneNumber" type="text" required value="'.$row['phone']. '" />';
echo' <br/>';
echo' <br/>';
echo'Tick here if you are student:';
echo'<input type="checkbox" id="studentdiscount" name="student" onChange="redraw()" value="' . $row['student'] . '"' . ($row['student'] == 'y' ? ' checked="checked"' : '') . ' />';
echo'<button type="update" name="update" value="update" >update</button>';
echo'<input type="hidden" name="id" value="'.$row['order_id'].'"/>';
echo'</form>';
}//close if
}}
//UPDATE ORDER
if (isset($_POST['update']))
{
session_start();
if(isset($_SESSION['order_id']))
{
$pizzaSize = $_REQUEST['pizzaSize'];
$customerName = $_REQUEST['customerName'];
//Take in Customer Name and Split it into first and last name.
list($fname, $lname ) = explode( ' ', $customerName, 2 );
$address = $_REQUEST['address'];
$emailAddress = $_REQUEST['emailAddress'];
$phoneNo = $_REQUEST['phoneNo'];
//$price = $_REQUEST['price'];
/**
The Following Code Below Checks if
Check box is Set or Not Set
if not Set, then set String to No
if it is set leave Default value of Yes set
**/
if(!isset($_REQUEST['addPeppers']))
{
$addPeppers = 'no';
}else{$addPeppers = $_REQUEST['addPeppers'];}
if(!isset($_REQUEST['addOnion']))
{
$addOnion = 'no';
}else{$addOnion = $_REQUEST['addOnion'];}
if(!isset($_REQUEST['addOlives']))
{
$addOlives = 'no';
}else{$addOlives = $_REQUEST['addOlives'];}
if(!isset($_REQUEST['addPepperoni']))
{
$addPepperoni = 'no';
}else{$addPepperoni = $_REQUEST['addPepperoni'];}
if(!isset($_REQUEST['addPineapple']))
{
$addPineapple = 'no';
}else{$addPineapple = $_REQUEST['addPineapple'];}
if(!isset($_REQUEST['addAnchovies']))
{
$addAnchovies = 'no';
}else
{$addAnchovies = $_REQUEST['addAnchovies'];}
//Do the Same to Student Discount
if(!isset($_REQUEST['student']))
{
$student = 'no';
}else{$student = $_REQUEST['student'];}
$update = "UPDATE orders SET
student ='".mysqli_real_escape_string($student)."',
firstname='".mysqli_real_escape_string($fname)."',
email='".mysqli_real_escape_string($emailAddress)."',
address ='".mysqli_real_escape_string($address)."',
phone='".mysqli_real_escape_string($phoneNo)."',
size='".mysql_real_escape_string($pizzaSize)."',
anchovies ='".mysql_real_escape_string($addAnchovies)."',
pineapples ='".mysql_real_escape_string($addPineapple)."',
pepperoni = '".mysql_real_escape_string($addPepperoni)."',
olvies='".mysql_real_escape_string($addOlives)."',
onions ='".mysql_real_escape_string($addOnion)."',
peppers='".mysql_real_escape_string($addPeppers)."',
WHERE order_id ='".$_REQUEST['order_id']."'"
;
$result = mysqli_query($connection, $update);
if($result)
{
echo 'You have updated yor Order';
}else
{
echo mysqli_error($connection);
}
}
}//end die error
?>