Jump to content

Updateing a data base row...


Lee-Bartlett

Recommended Posts

Ok i think i am close but im not sure how to get this to work, i want my button in the update row, to update that row of data, here my code. Im not sure what to do, to get the data from the first page to use on the second

 

<?php  require_once("includes/db_connection.php"); ?>
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$location = $_POST['location'];
$type = $_POST['type'];
$buissnes_name = $_POST['buissnes_name'];
$id = $_POST['id'];
?>

<?php

if(isset($_POST['id']))
{
	$id = $_POST['id'];

	$delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); 
}

$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());

echo "<table border=1 align=centre>";
echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete</td><td>Update</td></tr>";
while($row = MYSQL_FETCH_ARRAY($res))
{
echo "<tr><td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['buissnes_name']."</td>";
echo "<td>".$row['location']."</td>";
echo "<td>".$row['type']."</td>";
echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST">
<input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="button=" id="button" value="Delete Record"></form></td>';
echo "<td>( <a href=form2.php>Update</a> ) </td></tr>";
}
echo "</table><br>"; 
?>

<a href="userform.php">Add a new user.</a>

 

it then links to 

 

<?php  require_once("includes/db_connection.php");


$name = $_POST['name'];



echo "<form action=\"form3.php\" method=\"post\">";
$sql = "SELECT * from tblbasicform WHERE name = '$name'";
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($res)){
$id = $row['id'];
$name = $row['name'];
    $email = $row['email'];
$buissnes_name = $row['buissnes_name'];
$location = $row['location'];
$type = $row['type'];

?>

  Input Name: <input type="text" name="name" value="<? echo $name ?>" /><br />
  Input Email: <input type="text" name="email" value="<? echo $email?>" /><br />
  Input Buissnes Name: <input type="text" name="buissnes_name" value="<? echo $buissnes_name?>" /><br />
  Input Location: <input type="text" name="location" value="<? echo $location?>" /><br />
  Input Free or Paid: <input type="text" name="type" value="<? echo $type?>" /><br />
<input type="hidden" name="id" value="<? echo $id?>">
<input type="submit" name="submit" value="Update Data" />
</form>

<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/127303-updateing-a-data-base-row/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.