bmcgonag Posted June 8, 2011 Share Posted June 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238795-updating-certain-records-from-an-array-output/ Share on other sites More sharing options...
AbraCadaver Posted June 8, 2011 Share Posted June 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238795-updating-certain-records-from-an-array-output/#findComment-1227056 Share on other sites More sharing options...
bmcgonag Posted June 8, 2011 Author Share Posted June 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238795-updating-certain-records-from-an-array-output/#findComment-1227073 Share on other sites More sharing options...
bmcgonag Posted June 12, 2011 Author Share Posted June 12, 2011 Okay, when I use the SQL you provided, I get an error about the syntax near the ')'. Also I gegt an error about the array_map part and tha the second argument should be an array. Not sure what I need to do. Quote Link to comment https://forums.phpfreaks.com/topic/238795-updating-certain-records-from-an-array-output/#findComment-1228756 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.