Jump to content

Update


Mamo

Recommended Posts

hi

i want to update my database, but it doesn't work..........here is it code

<form action="mysql_2.php" method="POST"> 
Firstname &nbsp :  &nbsp <input type="text" name="first" ><br>
Lastname  &nbsp&nbsp  :  &nbsp <input type="text" name="last" ><p>
&nbsp&nbsp&nbsp&nbsp <input type="submit" name="submit" value="Get Data">
<b> If you want to Update any of these record </b><br>
<p>First name :  <input type="text" name="firstname1" ><br ></p>
<p>Last name  :  <input type="text" name="lastname1"  ><br ></p>
<p>dob		  :  <input type="text" name="dob1" ><br ></p>
<p>Gender     :  <input type="text" name="gender1" ><br ></p>
<p>&nbsp&nbsp&nbsp&nbsp<input type="submit" name="sub" value="Update"></p>
</form>

 

the php code read the first, last from the first two text box and select there information from the database, and update these information with the information taken from firstname1, lastname1, dob1, gender1. but it doesnot update


<?php

require("connect.php");
if (isset($_POST['submit'])) {

$firstname_form = $_POST['first'];
$lastname_form = $_POST['last'];
$carry = $_POST['submit'];
$select = mysql_query("SELECT * FROM people WHERE firstname='$firstname_form' AND lastname='$lastname_form' ") or die (mysql_error());

while ($data = mysql_fetch_assoc($select)) {
echo '<br>';

	$id    =       $data['id']; 
	$firstname =   $data['first'];
	$lastname  =   $data['last'];
	$dob       =   $data['dob'];
	$gender    =   $data['gender'];
	
	echo " My name is $firstname_form $lastname_form and i was born in $dob and i am $gender <br>";
}
if (isset($_POST['sub'])) {

$firstname_form_1 = $_POST['firstname1'];
$lastname_form_1 = $_POST['lastname1'];
$dob_form = $_POST['dob1'];
$gender_form = $_POST['gender1'];

$firstname_form_2 = $_POST['first'];
$lastname_form_2  = $_POST['last'];

$query = "UPDATE people SET firstname='$firstname_form_1' , lastname='$lastname_form_1' , dob='$dob_form' , gender='$gender_form' WHERE firstname='$firstname_form_2' AND lastname='$lastname_form_2' ";

$holder = mysql_query($query) or die ("Updates Failed");
}
?>
 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.