hi,
I am creating a form for user to update their details which is saved in the database. So far i can show their details in the form where i have a submit button but the updating part doesnt work(it doesnt update at all). here is the code:
<html>
<?php
session_start();
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="123456"; // Mysql password
$db_name="db"; // Database name
$tbl_name="member"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = $_SESSION['myusername'];
if(!isset($_SESSION['myusername']))
{
header("location: main_login.php");
}
else
{
$query=" SELECT * FROM $tbl_name WHERE LoginName='$username'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$phone=mysql_result($result,$i,"telephone");
$add=mysql_result($result,$i,"address");
$town=mysql_result($result,$i,"town");
$email=mysql_result($result,$i,"email");
$city=mysql_result($result,$i,"city");
$postcode=mysql_result($result,$i,"postcode");
++$i;
}
$u_phone=$_POST['phone'];
$u_add=$_POST['add'];
$u_town=$_POST['town'];
$u_city=$_POST['city'];
$u_postcode=$_POST['postcode'];
$u_email=$_POST['email'];
$query1="UPDATE $tbl_name SET memberNo = NULL, LoginName=NULL, title=NULL, firstName=NULL, lastName=NULL, gender= NULL, address='$u_add', town='$u_town', city='$u_city', postcode='$u_postcode', telephone='$u_phone', email='$u_email', mshipType = NULL";
mysql_query($query1);
echo "Record Updated";
mysql_close();
}
?>
<form action="changedetails.php" method="post">
<table>
<tr>
<td>Phone Number :</td>
<td><input type="text" name="phone" size="30" value="<?php echo $phone; ?>"></td>
</tr>
<tr>
<td>Address :</td>
<td><input type="text" name="add" size="30" value="<?php echo $add; ?>"></td>
</tr>
<tr>
<td>Town :</td>
<td><input type="text" name="town" size="30" value="<?php echo $town; ?>"></td>
</tr>
<tr>
<td>City :</td>
<td><input type="text" name="city" size="30" value="<?php echo $city; ?>"></td>
</tr>
<tr>
<td>Post Code :</td>
<td><input type="text" name="postcode" size="30" value="<?php echo $postcode; ?>"></td>
</tr>
<tr>
<td>E-mail Address :</td>
<td><input type="text" name="email" size="30" value="<?php echo $email; ?>" ></td>
</tr>
</table>
<p>
<input type="Submit" value="Update">
<input type="Submit" value="Cancel">
</form>
</html>
here is the table:
CREATE TABLE Member(
memberNo INT(8) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
LoginName VARCHAR(6) NOT NULL UNIQUE,
title VARCHAR(5),
firstName VARCHAR(20) NOT NULL,
lastName VARCHAR(20) NOT NULL,
gender VARCHAR(6) NOT NULL
CHECK(gender IN('MALE','FEMALE')),
address VARCHAR(30),
town VARCHAR(20),
city VARCHAR(20),
postcode VARCHAR(8) NOT NULL,
telephone INT(11),
email VARCHAR(50) NOT NULL,
mshipType VARCHAR(15) NOT NULL
CHECK(mshipType IN('STUDENT','STAFF','ALUMNI')),
password VARCHAR(20) NOT NULL,
PRIMARY KEY(memberNo)
);