how can i add a link next to each individual record that will allow me to edit that record (in PHP). i think it would be a mysql_fetch_row(), but if it is, I wouldn't know how to get that to work...basically i'd like the output of my table to look like this:
Edit Record1 Name1 City1
Edit Record2 Name2 City2
Edit Record3 Name3 City3
etc...
And I want each of the edit buttons to open up a new page that allows be to edit each of the fields to update the records through PHP.
select current record (for editing with PHP)
Moderator: General Moderators
- cbcampbell
- Forum Newbie
- Posts: 19
- Joined: Mon Jun 09, 2003 12:12 am
Code: Select all
<?
$sql = "select blah_id, title, author from blah order by blah_id desc";
$connection = mysql_connect("localhost", "user", "pass") or die ("no 1");
$db = mysql_select_db("databasename", $connection) or die ("no 2");
$sql_result = mysql_query($sql, $connection) or die ("no 3");
if (!$sql_result) {
echo "<P>Couldn't get list!";
} else {
echo "
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="2.php">
<table cellspacing=1 cellpadding=1>
<tr>
<td valign=top>
<select name="record">
<option value=""> -- Select a story to edit -- </option>
";
while ($row = mysql_fetch_array($sql_result)) {
$blah_id = $rowї"blah_id"];
$author = $rowї"author"];
$title = $rowї"title"];
echo "
<option value="$blah_id">$content_id : $author - $title</option>
";
}
echo "
</select> <input type="submit" value="let's edit">
</td>
</tr>
</table>
</form>
</body>
</html>
";
}
?>
then on 2.php
start displaying
if (!$record) {
$sql = "select * from blah where blah_id='$blah_id'";
} else {
$sql = "select * from blah where blah_id='$record'";
}
$connection = mysql_connect("localhost", "user", "pass") or die ("no 1");
$db = mysql_select_db("databasename", $connection) or die ("no 2");
$sql_result = mysql_query($sql, $connection) or die ("no 3");
if (!$sql_result) {
echo "<P>Couldn't get item!";
} else {
$row = mysql_fetch_array($sql_result);
$blah_id = $rowї"blah_id"];
$title = $rowї"title"];
$author = $rowї"author"];
echo "
<html>
<head>
<title>Modify - Step 2:</title>
</head>
<body>
<h1>Modify - Step 2:</h1>
<form method="post" action="3.php">
<table cellspacing=5 cellpadding=5>
<tr>
<td valign=top><strong>Story#:</strong></td>
<td valign=top>
$blah_id
<input type="hidden" name="blah_id" value="$blah_id" size=35 maxlength=150>- cbcampbell
- Forum Newbie
- Posts: 19
- Joined: Mon Jun 09, 2003 12:12 am