cory011202 Posted April 16, 2009 Share Posted April 16, 2009 Hello You have helped me out before lets hope we can keep the streak alive! My problem is I am working on a page for a racer that wants to be able to update his schedule of races and have it display on his web page. I have the database queries working ( Still need to work on the date) and I can post,update and retrieve information with the db. My problem is it will only read information from the very last record pulled from the db. So if I have 5 records and I edit 1 -4 nothing will happen. if I edit 5 then I will get that information posted. if I edit 1-4 record 5 is still posted. Now if I have the radio button check on 1-4 then it wll update with the same info as the 5th record has. I am guessing I am not calling the record id or something as id is the primary key. thanks for your help. <!--table to display and edit schedule information--> <table id="schedtable" align="center"> <tr> <td width="50">Edit</td <td width="250">Date</td> <td width="250">Track</td> <td width="250">Information</td> <td width="250">Race Results</td> </tr> <!--start form--> <form method="post" action="schedule_update.php"> <?php // loop to display info from db while ( $row = mysql_fetch_array($cur_sched)) { echo "<tr>"; echo "<td width='50'>" . "<input name='id'type='radio' value=" . $row['id'] . " >" . "</td>"; echo "<td width='250'>" . "<input name='date' type='text' value=" . $row['date'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='track' type='text' value=" . $row['track'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='information' type='text' value=" . $row['other'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='results' type='text' value=" . $row['results'] . ">" . "</td>"; echo "</tr>"; //end loop } ?> <!--buttons for form--> <tr> <td colspan="5" align="center"> <INPUT type="submit" value="Update" name="submit" /> </td> </tr> <!--end form--> </form> </table> This is the php file for the query <?php //connect to the db require_once('includes/connection.php'); //Gets the Schedule from the schedule page $id = $_POST['id']; $date = $_POST['date']; $track = $_POST['track']; $information = $_POST['information']; $results = $_POST['results']; //Query to insert data into database $result = mysql_query("UPDATE raceinfo SET date='$date', track='$track', other='$information', results='$results' WHERE id='$id' ") or die(mysql_error()); //here for troubleshooting echo $id; echo $date; echo $track; echo $information; echo $results; //redirect after query header("Location:schedule.php"); ?> Quote Link to comment Share on other sites More sharing options...
timmah1 Posted April 16, 2009 Share Posted April 16, 2009 Try this Your form <table id="schedtable" align="center"> <tr> <td width="50">Edit</td <td width="250">Date</td> <td width="250">Track</td> <td width="250">Information</td> <td width="250">Race Results</td> </tr> <!--start form--> <form method="post" action="schedule_update.php"> <?php // loop to display info from db while ( $row = mysql_fetch_array($cur_sched)) { echo "<tr>"; echo "<td width='50'>" . "<input name='id[]' type='radio' value=" . $row['id'] . " >" . "</td>"; echo "<td width='250'>" . "<input name='date[]' type='text' value=" . $row['date'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='track[]' type='text' value=" . $row['track'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='information[]' type='text' value=" . $row['other'] . ">" . "</td>"; echo "<td width='250'>" . "<input name='results[]' type='text' value=" . $row['results'] . ">" . "</td>"; echo "</tr>"; //end loop } ?> <!--buttons for form--> <tr> <td colspan="5" align="center"> <INPUT type="submit" value="Update" name="submit" /> </td> </tr> <!--end form--> </form> </table> schedule_update.php <?php //connect to the db require_once('includes/connection.php'); //Gets the Schedule from the schedule page $id = (is_numeric($_POST['id'][$i]))? $_POST['id'][$i] : 0; $date = mysql_real_escape_string($_POST['date'][$i]); $track = mysql_real_escape_string($_POST['track'][$i]); $information = mysql_real_escape_string($_POST['information'][$i]); $results = mysql_real_escape_string($_POST['results'][$i]); //Query to insert data into database $result = mysql_query("UPDATE raceinfo SET date='$date', track='$track', other='$information', results='$results' WHERE id='$id' ") or die(mysql_error()); //here for troubleshooting echo $id; echo $date; echo $track; echo $information; echo $results; //redirect after query header("Location:schedule.php"); ?> Quote Link to comment Share on other sites More sharing options...
cory011202 Posted April 16, 2009 Author Share Posted April 16, 2009 Thanks for the quick response! however it still only takes the last input and now it will only display the first letter of whatever I type in. I dont know know why its only taking the last row and using that to update the other records. I am guessing since it will update the other records then the id is working correctly Quote Link to comment Share on other sites More sharing options...
timmah1 Posted April 16, 2009 Share Posted April 16, 2009 <?php $id = (is_numeric($_POST['id'][$i]))? $_POST['id'][$i] : 0; $date = mysql_real_escape_string($_POST['date']); $track = mysql_real_escape_string($_POST['track']); $information = mysql_real_escape_string($_POST['information']); $results = mysql_real_escape_string($_POST['results']); ?> Quote Link to comment Share on other sites More sharing options...
cory011202 Posted April 16, 2009 Author Share Posted April 16, 2009 Well that fixed the issued of only showing the first letter. Still only pulls the last info record. I need to somehow pull out the information from the radio button after it is updated and send it to the query Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.