Jump to content

Dynamic update form


KMC1499

Recommended Posts

First off thank you for opening my issue and taking the time out to try and help.

 

I have created a php page that will display a list of people from a mysql database. What i would like to do is have a button that will update a field in the database when pressed. My question is if i make the fields into a form will it only update that one person?

Link to comment
Share on other sites

PHP is versatile and can pretty much whatever you want it to do, form-wise. If you could post some code and give more detailed explanation, we can probably help you do whatever it is you want to do. Make sure your code is surrounded by code tags.

Link to comment
Share on other sites

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_judges, $judges);
$query_Recordset1 = "SELECT idjudge, firstname, lastname, email, mailaddress, city, state, zipcode, party, phone, transportation, travel, distance, class, pickup, dropoff, bilingual, dateentered, mysqldate, contacted FROM judge WHERE contacted='No' ORDER BY mysqldate ASC";
$Recordset1 = mysql_query($query_Recordset1, $judges) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Judges</title>
</head>

<body>

<?php




// Free memory
//mysql_free_result($check);	
?>

<table border="1" style="border:1px solid black;">
  <tr>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Signup Date</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>First Name</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Last Name</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Email Address</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Mailing Address</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>City</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>State</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Zipcode</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Party</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Phone Number</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Transportation</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Travel</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Distance</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Class</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Pickup</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Dropoff</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Bilingual</FONT></td>
    <TD BGCOLOR=#C7C5BC ALIGN=CENTER ><FONT style=FONT-SIZE:9pt FACE="Arial" COLOR=#f9f9f7>Contacted?</FONT></td>
   
    
  </tr>
  <?php do { ?>
    <tr>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['dateentered']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['firstname']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['lastname']; ?></td>
      <TD ALIGN=CENTER ><a href="mailto:<?php echo $row_Recordset1['email'];?>"><?php echo $row_Recordset1['email']; ?></a></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['mailaddress']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['city']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['state']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['zipcode']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['party']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['phone']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['transportation']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['travel']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['distance']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['class']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['pickup']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['dropoff']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['bilingual']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['contacted']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

 

What we want to do is to be able to update each person as we contact them here is a picture showing the form online.

form.jpg

Link to comment
Share on other sites

I believe so i was just unsure how to go about it since im fairly new to php and i wasnt sure how to go about it.

 

My idea was to create a form around each record that would have a "update" button on the end that would run a function that would update the database and reload the webpage. Sound good???

Link to comment
Share on other sites

I'd go with cyber on that, it's needless bloating to the script if you are coding a form for each record.  If you want it to look like a button you can use an image as the link, but a simple hyperlink rendered from the select query is, I think, the best way.  you can even contitionalise the hyperlink/image to not link if the Contacted field is already set to Yes.

Link to comment
Share on other sites

I plan on adding a where clause to my select so only my people who have "no" in the contacted field are shown.

 

 

So i added the form tags to the code.

 

 

  <form action="update_script.php" method="get">
<tr>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['dateentered']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['firstname']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['lastname']; ?></td>
      <TD ALIGN=CENTER ><a href="mailto:<?php echo $row_Recordset1['email'];?>"><?php echo $row_Recordset1['email']; ?></a></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['mailaddress']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['city']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['state']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['zipcode']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['party']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['phone']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['transportation']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['travel']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['distance']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['class']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['pickup']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['dropoff']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['bilingual']; ?></td>
      <TD ALIGN=CENTER ><?php echo $row_Recordset1['contacted']; ?></td>
      <TD ALIGN=CENTER ><a href="update_script.php?<?php print $row_Recordset1['idjudge']; ?>">Update</a></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

 

And in my update script page i add the php info to update the record?

Link to comment
Share on other sites

Sorry, I mistyped the code. You need a name/value pair for each variable.

 

<a href="update_script.php?id=<?php print $current_record_id; ?>">Update Current Record</a>

 

 

 

So your code would be changed to:

 

<TD ALIGN=CENTER ><a href="update_script.php?id=<?php print $row_Recordset1['idjudge']; ?>">Update</a></td>

 

 

Of course, "id" would be whatever you want to name the variable.

Link to comment
Share on other sites

Ok no form tags and i added that code to me page buuuuuut im missing where the page actually updates the database.  What i want to do is when the people click the update button have the page update the contacted field to Yes and  reload the page this time without the contacts with yes in the contacted column (page will filter these out in the select query automatically)

Link to comment
Share on other sites

For displaying the list after an update has been made, you could look into using the same page that displays the list to also process the update. For example, you page could be modified to do the following:

 

[*]If user clicked one of the edit links

  • get the ID to edit
  • make sure the ID is valid
  • update the database, if the ID was valid
  • If the update was successful / unsuccessful, display corresponding message to user

 

[*]Get the list of contacts

[*]Display the list of contacts

 

 

Note that steps 2 and 3 happen whether or not an edit link was clicked.

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.