|
-
Apr 12th, 2006, 11:24 AM
#1
Thread Starter
New Member
[RESOLVED] Update
hi i am trying to update information in a database from a form and i'm not sure how to do it this is the code i got so far it brings up the information from the database but it won't update when i change something. Can anyone help me.
PHP Code:
<?php
include("dbinfo.php");
$conn = mysql_connect($dbhost, $dbuser, $dbpass)or die('Error connecting to mysql');
$dbname = 'db_02023334';
mysql_select_db($dbname)or die('error finding DB');
$univerpass = $_POST['univerpass'];
$date = $_POST['date'];
$query= "SELECT * FROM info WHERE uni_pass = '$univerpass' and dob = '$date'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$title=$row['title'];
$fname=$row['first_name'];
$sname=$row['second_name'];
$dob=$row['dob'];
$gender=$row['gender'];
$homead=$row['home_ad'];
$city=$row['city'];
$country=$row['home_country'];
$homepost=$row['home_post'];
$homephone=$row['home_phone'];
$termad=$row['term_ad'];
$termpost=$row['term_post'];
$termphone=$row['term_phone'];
$email=$row['email'];
$ethnic=$row['ethnic'];
$ethnicother=$row['ethnicother'];
$disability=$row['disability'];
$qual=$row['qual'];
$type=$row['course'];
$years=$row['years_study'];
$unipass=$row['uni_pass'];
}
?>
<form action="amend2.php" method="post">
Title: <input type="text" value="<?php echo "$title"?>" name="title"><br>
First Name: <input type="text" value="<?php echo "$fname";?>" name="fname"><br>
Second Name: <input type="text" value="<?php echo "$sname";?>" name="sname"><br>
Date of Birth: <input type="text" value="<?php echo "$dob";?>" name="dob"><br>
Gender: <input type="text" value="<?php echo "$gender";?>" name="gender"><br>
Home Address: <input type="text" value="<?php echo "$homead";?>" name="homead"><br>
City: <input type="text" value="<?php echo "$city";?>" name="city"><br>
Country: <input type="text" value="<?php echo "$country";?>" name="country"><br>
Home Postcode: <input type="text" value="<?php echo "$homepost";?>" name="homepost"><br>
Home Telephone: <input type="text" value="<?php echo "$homephone";?>" name="Title"><br>
Term Address: <input type="text" value="<?php echo "$termad";?>" name="termad"><br>
Term Postcode: <input type="text" value="<?php echo "$termpost";?>" name="termpost"><br>
Term Telephone: <input type="text" value="<?php echo "$termphone";?>" name="termphone"><br>
E-mail: <input type="text" value="<?php echo "$email";?>" name="email"><br>
Ethnic Origin: <input type="text" value="<?php echo "$ethnic";?>" name="ethnic"><br>
Ethnic Other: <input type="text" value="<?php echo "$ethnicother";?>" name="ethnicother"><br>
Disability: <input type="text" value="<?php echo "$disability";?>" name="disability"><br>
Qualification: <input type="text" value="<?php echo "$qual";?>" name="qual"><br>
Type of Course: <input type="text" value="<?php echo "$type";?>" name="type"><br>
Years of Study: <input type="text" value="<?php echo "$years";?>" name="years"><br>
<input type="submit" value="Submit">
</form>
-
Apr 12th, 2006, 12:28 PM
#2
Fanatic Member
Re: Update
you then have to submit the form containing the updated value and query the db with an UPDATE query
PHP Code:
$query = "UPDATE info SET title='" . $_POST['title'] . "', first_name='" . $_POST['fname'] . " ... WHERE uni_pass = '" . $_POST['univerpass'] . "' and dob = '" . $_POST['date'] . "'";
EDIT: Also, you should use
PHP Code:
<?php echo $email; ?>
without quote...
-
Apr 13th, 2006, 06:04 AM
#3
Thread Starter
New Member
Re: Update
PHP Code:
$query = "UPDATE info SET title='" . $_POST['title'] . "', first_name='" . $_POST['fname'] . " ... WHERE uni_pass = '" . $_POST['univerpass'] . "' and dob = '" . $_POST['date'] . "'";
Tried this line and now it says that univerpass and date are undefined index
What i done with this code is put it on the page where the form submits to is this right or should i of put the code on the page where the information is changed (the code i showed on the first post).
-
Apr 14th, 2006, 11:07 AM
#4
Fanatic Member
Re: [RESOLVED] Update
is this resolved, really?
-
Apr 14th, 2006, 01:30 PM
#5
Thread Starter
New Member
Re: [RESOLVED] Update
yes it is resolved sotred it out after doing the post thanks for the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|