Lee-Bartlett
asked on
Updating a row with an update button.
Ok my old piece of code had a drop down box where the name of the user is pulled from the database and all his information was then i could update it. I want to get rid of the drop down and combine it with this page, see script below. if possible could someone help me or tell me how to make my update button, pull the data from the current page it is on then use it to update that user.
<?php require_once("includes/db_connection.php"); ?>
<?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>".$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>
///////////////////////////////////////////
THIS IS MY DROP DOWN BOX PAGE IF THIS HELPS
///////////////////////////////////////////
<?php require_once("includes/db_connection.php");
$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());
echo "<form action=\"form2.php\" method=\"post\">";
echo "<select name=\"name\">";
while($row = mysql_fetch_array($res)){
echo "<option>". $row['name'];
echo "</option>";
$name = $row['name'];
$email = $row['email'];
$location = $row['location'];
$buissnes_name = $row['buissnes_name'];
$type = $row['type'];
$id = $row['id'];
}
echo "</select><br>";
echo "<input type=submit value=\"Update Record\">";
echo "</form>";
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the error im getting is
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/nexodom/public_html/ test/updat e/updatede lete.php on line 20
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/nexodom/public_html/
ASKER
I tried somthing like this and that failed, all im trying to do is use the update button go to my update page with the rows data
<?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>".$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>';
$sql = "SELECT * from tblbasicform";
$res = mysql_query($sql) or die(mysql_error());
echo "<td><form action="form2.php" method="POST">";
while($row = mysql_fetch_array($res)){
echo "<input type="hidden" name="name" value="$row['name']">"
echo "<input type="submit" name="button=" id="button" value="Update Record"></form></td>";
}
echo "</tr>";
}
echo "</table><br>";
?>
<a href="userform.php">Add a new user.</a>
ASKER
Open in new window