Welcome! Log In Create A New Profile

Advanced

Update PHP

Posted by Domdice1 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Update PHP
October 31, 2012 12:45PM
Hi Mac and fellow students
I have not submitted my portfollio becuase i am not done but none the less I would like to finish it.
This could assit me when I redo this subject.
PLease help my code does not want to update when i click submit

@$res_nr = $_GET['res_nr']; //catching primary key

if(isset($_POST['Submit'])){
$rm_disc = $_POST['room_disc'];
$rm_price=$_POST['room_price'];
$res_name = $_POST['res_name'];
$rs_nr = $_POST['res_nr'];

$query1 = "UPDATE reservation_info SET room_discr = '$rm_disc', room_price = '$rm_price', res_name = $res_name' WHERE res_nr = '$rs_nr'";
$result = mysql_query($query1)
or die ("Could Not Update Database"winking smiley;
echo "Reservation Details updated";
}
else{
?>

<?php
$query = "SELECT * FROM reservation_info WHERE res_nr = '$res_nr'";
$result = mysql_query($query)
or die("Query failed"winking smiley;

The form
form method="post" action="edit.php">
<?php
while ($db_field = mysql_fetch_assoc($result)) {
$rm_disc = $db_field['room_discr'];
$rm_price = $db_field['room_price'];
$res_name = $db_field['res_name'];
}
?>

Room Type:
<input type="text" name="room_disc" value="<?php echo "$rm_disc";?>">
<br>
Room Price:
<input type="text" name="room_price" value="<?php echo "R$rm_price";?>">
<br>
Reservation Name:
<input type="text" name="res_name" value="<?php echo "$res_name";?>">

<input type="hidden" name="res_nr" value="<?php echo "$res_nr";?>">
<br>
<input type="Submit" name="Submit" value="Update">

</form>
<?php
Re: Update PHP
October 31, 2012 03:36PM
Well the flow of your code is not happening,

You are trying to update the DB then set the form.. after you catch the primary key use it to set your form 1st to display data to the user to edit then update the DB.

Also you are setting varible value at 2 places, only set variable value once.

You realy should use formatted code tab also so we can better understand your code...
avatar
Mac
Re: Update PHP
October 31, 2012 03:50PM
Also use the formatted code button when posting code as explained in the tut letter
Sorry, only registered users may post in this forum.

Click here to login