Originally Posted by
xan
Whats the code you are actually using at the moment.
My current code:
<?php
error_reporting(E_ALL);
$record = $_POST['record'];
echo "Reference: $record<br><BR>";
$host = "localhost";
$user = "xxx";
$pass = "xxx";
$db = "phonebook";
//Connecting to MYSQL
MySQL_connect("$host","$user","$pass");
//Select the database we want to use
mysql_select_db($db) or die("Could not find database");
// Check to see if the link from the previous page was clicked
if(isset($_REQUEST['id'])) {
// Check that the id value in the URL is a number
if(is_numeric($_REQUEST['id'])) {
$id=$_REQUEST['id'];
mysql_query("SELECT * FROM people WHERE id = '$id'") or die(mysql_error);
if(mysql_num_rows > 0) {
$row=mysql_fetch_row($result);
} else {
echo 'No Record';
}
}
}
// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_POST['Submit']){
// Get parameters from form.
$id=$_REQUEST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone_num=$_POST['phone_num'];
$ext=$_POST['ext'];
$title=$_POST['title'];
$dept=$_POST['dept'];
// Do update statement.
mysql_query("update phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept' where id='$id'");
// Re-direct this page to select.php.
header("location:phoneupdate.php");
exit;
}
// ************* End update part *************
// *** Select data to show on text fields in form. ***
// Get id parameter (GET method) from select.php
$id=$_POST['id'];
// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from people where id='$id'");
// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);
// Close database connection.
mysql_close();
?>
<!-- END OF PHP CODES AND START HTML TAGS -->
<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>?id=$id">
<p>First Name :
<!-- name of this text field is "fname" -->
<input name="fname" type="text" id="fname" value="<? echo $row[1]; ?>"/>
<br />
Last Name :
<!-- name of this text field is "lname" -->
<input name="lname" type="text" id="lname" value="<? echo $row[2]; ?>"/>
<br />
Phone Number :
<!-- name of this text field is "phone_num" -->
<input name="phone_num" type="text" id="phone_num" value="<? echo $row[3]; ?>"/>
</p>
Extension :
<!-- name of this text field is "ext" -->
<input name="ext" type="text" id="ext" value="<? echo $row[4]; ?>"/>
<br />
Title :
<!-- name of this text field is "title" -->
<input name="title" type="text" id="title" value="<? echo $row[5]; ?>"/>
<br />
Department :
<!-- name of this text field is "dept" -->
<input name="dept" type="text" id="dept" value="<? echo $row[6]; ?>"/>
<br />
Fax Number :
<!-- name of this text field is "fax" -->
<input name="fax" type="text" id="fax" value="<? echo $row[7]; ?>"/>
<br />
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html> Last edited by rickarro : May 8th, 2008 at 5:22 pm.