<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test2", $con);
$result = mysql_query("SELECT * FROM cars WHERE color='' ORDER BY id DESC");
$rownumbers=0;
while ($row = mysql_fetch_array($result))
{
$rownumbers++;
echo "(".$rownumbers.")<br />";
echo "<div><font color='green'>Record# - </font><a href='../editrecord.php' id='" . $row['id'] . "' />".$row['id']."</a>: <br />Make is: " . $row['make'] . "<br /> Model Type: ".$row['model']."</div>";
echo "<div><font color='red'>What color is it: </font>" . $row['color'] . "</div>";
echo "<div><hr></hr></div>";
}
mysql_close($con);?>
</body>
</html>
My goal is to be able to click on the Record # which i have as a href and that it will update the record thereby removing it from the list and populate another page where I can edit the record completly. Im not sure about how to go about doing that though. Anyone out there with some ideas and an example or two?
Record# - 7:
Make is: plymouth
Model Type: SUV
What color is it:
edit this record? {yes} This is a checkbox
(2)
Record# - 5:
Make is: chevy
Model Type: truck
What color is it:
edit this record? {yes}
(3)
Record# - 4:
Make is: ford
Model Type: car
What color is it:
edit this record? {yes}
(4)
Record# - 3:
Make is:
Model Type:
What color is it:
edit this record? {yes}
(5)
Record# - 2:
Make is: dodge
Model Type: truck
What color is it:
edit this record? {yes}
[SUBMIT BUTTON]
The above list is the output of the code from the opening post.
The code generates a list from the table where the field for color is empty.
So what i am trying to do is to select a record from the list, pass the data from the selected record to a new page that will allow me to update the record.
When a record has a color then it does not get included in the list.
I am not sure how to go about doing that.
<form action=update.php method=post>
// pseudocode ish
foreach vehicle with no color{
<p>Make is: plymouth<br />
Model Type: SUV<br />
What color is it? <input type=text name="7" value=""></p>
}
// close off your single form
<input type=submit>
</form>
Your postback form handler
update.php
<?php
// check what is passed back to this handler
var_dump($_POST);
unset($_POST['submit']); // get rid of submit button
var_dump($_POST); // check that worked, is submit gone?
// now update your db
foreach($_POST as $k=>$val){
// escape the string to avoid sql injection, and turn a numerical id into an integer (or set to 0 on fail)
$sql = "update cars set color = '". mysql_real_escape_string($_POST[$k]). "' where id=" . (int)$k;
// send query to dbase here
}
Not tested, but in theory this is one way you could do it.
It is possible to update all cars with one query but that should get you going.