Page 1 of 1

select current record (for editing with PHP)

Posted: Thu Jul 10, 2003 3:26 pm
by cbcampbell
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.

Posted: Thu Jul 10, 2003 9:42 pm
by macewan

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) &#123;  
			echo "<P>Couldn't get list!";
		&#125; else &#123;
			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)) &#123;
	$blah_id = $row&#1111;"blah_id"];
	$author = $row&#1111;"author"];
	$title = $row&#1111;"title"];
	echo "
	<option value="$blah_id">$content_id : $author - $title</option>
	";
&#125;
echo "
</select> <input type="submit" value="let's edit">
</td>
</tr>
</table>
</form>
</body>
</html>
";
		&#125;
?>


then on 2.php


start displaying



		if (!$record) &#123;
		$sql = "select * from blah where blah_id='$blah_id'";
		&#125; else &#123;

		$sql = "select * from blah where blah_id='$record'";
		&#125;
		$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) &#123;  
		echo "<P>Couldn't get item!";
		&#125; else &#123;
			$row = mysql_fetch_array($sql_result);
			$blah_id = $row&#1111;"blah_id"];
			$title = $row&#1111;"title"];
			$author = $row&#1111;"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>

Posted: Fri Jul 11, 2003 12:17 am
by cbcampbell
thanks so much. i will try that and post on my results.

Posted: Mon Jul 14, 2003 4:00 pm
by cbcampbell
it worked! thanks a million

Posted: Wed Jul 23, 2003 4:28 am
by macewan
=)