Clinton Posted September 11, 2007 Share Posted September 11, 2007 Ok, I have this page that has this code: <? $q1= "SELECT * FROM roster WHERE `Position`<='4' AND `Terminated`='0' ORDER BY Position"; $q1rz=mysql_query($q1) or die(mysql_error()); while($row1 = mysql_fetch_array($q1rz)){ ?> <b><font color="orange" size="3"><? echo $row1['Name']; ?></font></b><br> <i><? echo $row1['Title']; ?></i><br> Cell: <? echo $row1['CellPhone']; ?>       Home: <? echo $row1['HomePhone']; ?><br> E-Mail: <a href=mailto:<? echo $row1['Email']; ?>><? echo $row1['Email']; ?></a><br> <? echo $row1['Notes']; ?><p> <? } ?> Now, it will pull out like 5 entries or so. Now, I want to put the output into a table, which I can do. What I don't know how to do is this: They are going to be looking at 5 entries in 'form' form and will be able to change it. But how do I get it to update whatever they changed? Make sense? I mean, it's not like your standard form where you know what the input is going to be. If it's one entry or 5 entries that are displayed I want the power to update them. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/ Share on other sites More sharing options...
pocobueno1388 Posted September 11, 2007 Share Posted September 11, 2007 Are you talking about updating the fields in the database? You would just use an update query. <?php $query = "UPDATE TableName SET col1='whatever', col2='whatever' WHERE condition"; $result = mysql_query($query)or die(mysql_error()); ?> If you posted the code to the form, it would be easier to help you. Sorry if I'm completely off, I didn't quite understand. Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-345735 Share on other sites More sharing options...
jigen7 Posted September 11, 2007 Share Posted September 11, 2007 i think that you must declare a counter variable so that for every it will increase by 1 then use that counter variable as a value in the form action ex <form action=update.php?counter=$counter> then get it by using $_GET counter = $_GET[counter]; update table where idnum =counter sumthing like that hope you get whta i mean Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-345739 Share on other sites More sharing options...
pocobueno1388 Posted September 11, 2007 Share Posted September 11, 2007 i think that you must declare a counter variable so that for every it will increase by 1 then use that counter variable as a value in the form action ex <form action=update.php?counter=$counter> then get it by using $_GET counter = $_GET[counter]; update table where idnum =counter sumthing like that hope you get whta i mean Ummm, no. They should have some primary key in the database that they will be able to identify which table to update with. They will have to pass this variable through a hidden input field. Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-345740 Share on other sites More sharing options...
Clinton Posted September 11, 2007 Author Share Posted September 11, 2007 Well I figured it would have something to do with my ID but i'm not quite sure what just because it's a loop and not fixed text: <? $q4= "SELECT * FROM roster WHERE `Position`<='4' AND `Terminated`='0' ORDER BY Position"; $q4rz=mysql_query($q4) or die(mysql_error()); while($row4 = mysql_fetch_array($q4rz)){ ?> <form action="updatekeyper.php" method="post"> <table border="0"> <tr><td>Name:</td><td> <input type="text" name="Name" maxlength="60" value="<? echo $row4['Name']; ?>"><input type="hidden" name="ID" maxlength="60" value="<? echo $row4['ID']; ?>"> </td></tr> <tr><td>Title:</td><td> <input type="text" name="Title" maxlength="60" value="<? echo $row4['Title']; ?>"> <tr><td>Cell Phone:</td><td> <input type="text" name="CellPhone" maxlength="60" value="<? echo $row4['CellPhone']; ?>"> <tr><td>Home Phone:</td><td> <input type="text" name="HomePhone" maxlength="60" value="<? echo $row4['HomePhone']; ?>"> <tr><td>E-Mail:</td><td> <input type="text" name="Email" maxlength="60" value="<? echo $row4['Email']; ?>"> <tr><td>Notes:</td><td> <input type="text" name="Notes" maxlength="200" value="<? echo $row4['Notes']; ?>"> </td></tr> <tr><td>Position:</td><td> <select name="Position" size="1"> <option value="0">Explosive Manager</option> <option value="1">Explosive Supervisor</option> <option value="2">Class 1 Explosive Technician</option> <option value="3">Class 2 Explosive Technician</option> <option value="4">Class 3 Explosive Technician</option> <option value="5">Standby Personnel</option> </select> </td></tr> <tr><td>Terminated:</td><td> <select name="Terminated" size="1"> <option value="0">No</option> <option value="1">Yes</option> </select> </td></tr> </table> </form> <p> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-345788 Share on other sites More sharing options...
pocobueno1388 Posted September 11, 2007 Share Posted September 11, 2007 Where is your submit button? Make one of those, then put this on the top of your script. <?php if (isset($_POST['submit'])){ $id = mysql_real_escape_string($_POST['ID']); $name = mysql_real_escape_string($_POST['name']); $title = mysql_real_escape_string($_POST['Title']); //do this to the rest of them too $query = "UPDATE TableName SET name='$name', $title='$title' WHERE ID='$ID'"; $result = mysql_query($query)or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-346025 Share on other sites More sharing options...
Clinton Posted September 11, 2007 Author Share Posted September 11, 2007 Awesome. Thanks a million...!!! Quote Link to comment https://forums.phpfreaks.com/topic/68779-solved-updating-a-php-form/#findComment-346086 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.