Jump to content

Updating certain records from an Array output.


bmcgonag

Recommended Posts

i have a page that is pulled using PHP and MySQL.

 

Info like Name, Address, Phone, Email, etc.  I want the user who sees this page to have a checkbox that they can check for each record.

 

Imagine people applying for membership to a club.  The club president pulls the new applicants and will check the one's who are accepted. 

 

then click 'submit' to update them.

 

My issue is, I don't know how to refer to the Array fields to get them updated in teh MySQL db. 

 

<!DOCTYPE html>

<?php

$con = mysql_connect("localhost", "user-name", "userPW!");

if (!$con){
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("dbIMade", $con);

$result = mysql_query("SELECT * FROM MemberInfo WHERE Viewed = 0");

echo "<table border='1' cellpadding='5'>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr><td>---------------------------</td></tr><tr>";
  	echo "<td><b>Membership Eligibility</b></td>";
  	echo "<td><b>Name</b></td><td><b>Address</b></td><Td><b>E-mail Address</b></td></tr>";
  	echo "<tr><td>". $row['Member_Eligibility'] . "</td><td>" . $row['First_Name'] . " " . $row['Middle_Name'] . " " . $row['Last_Name'] . "</td>";
  	echo "<td>" . $row['Street_Address'] . " <b>Apt:</b> " . $row['Apt_Number'] . ", " . $row['City'] . ", " . $row['State'] . "  " . $row['Zip_Part_1'] . "-" . $row['Zip_Part_2'] . "</td>";
  	echo "<td>" . $row['Email'] . "</td></tr>";
      echo "<tr><td><b>Phone / Cell Phone</b></td><td><b>Date of Birth</b></td><td><b>Social Security No</b></td><td><b>DL Number / State</b></td></tr>";
      echo "<tr><td>" . $row['Phone'] . " / " . $row['Cell_Phone'] . "</td>";
      echo "<td>" . $row['Date_of_Birth'] . "</td>";
      echo "<td>" . $row['Social_Security_No'] . "</td>";
      echo "<td>" . $row['Driver_License_No'] . " / " . $row['Driver_License_St'] . "</td></tr>";
      echo "<tr><td><b>Employer Info</b></td><td><b>Mother's Maiden Name</b></td></tr>";
      echo "<tr><td>" . $row['Employer_Name'] . " / " . $row['Employer_Phone_No'] . "</td>";
      echo "<td>" . $row['Desired_Security_No'] . "</td></tr>";
  }
echo "</table>";

mysql_close($con);
?>

 

Any help is appreciated.  I'm a newby to PHP, I'm sure it will be obvious by my coding.

 

Assume the 'Accepted' field is a 1,0 field in the database with 'Accepted' as the field name.

You want to open <form> and a submit button and close </form> outside of your while loop.  Then assuming you have an id column for each row, you want something like this inside the while loop:

 

echo '<input type="checkbox" name="accepted[]" value="' . $row['id'] . '">';

 

Then on whatever page you submit the form to, you would do something like this:

 

$ids = implode(',', array_map('mysql_real_escape_string', $_POST['accepted']));
//UPDATE MemberInfo SET Accepted = 1 WHERE id IN ($ids)

 

There's a lot more to it.  You want to read up on forms and safely handling user data that you supply to a database query.

This is great info.  I appreciate it.  I'll try to get it working tonight, and post back with any other issues.

 

I appreciate the pointer to safety when submitting data to a db.  On the original member forms I use both javascript on the client side, and php on the server side to do as much validation and stripping of invalid entry data as I can. 

 

Best,

 

Mac

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.