Jump to content

[SOLVED] Updating a PHP form???


Clinton

Recommended Posts

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']; ?> &nbsp &nbsp &nbsp 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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>


<?
}
?>

Link to comment
Share on other sites

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());
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.