Hi all
I would like to add to my web form a section where the user can select yes or no. The reason for this is that if they select yes then his / her details will be displayed using the code below. What i need to know is how i create the if statement on the following code?
i understand that it would work in the following way but i'm not sure how to code it in.
if the user selects Yes then show all results
else
do not display the users details
ThanksCode:<?php $con = mysql_connect("localhost","db_username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_name", $con); $result = mysql_query("SELECT * FROM members"); echo "<table border='1'> <tr> <th>Email Address</th> <th>Title</th> <th>First Name</th> <th>Last Name</th> <th>Address</th> <th>Mobile</th> <th>Tennis Number</th> <th>LTA Number</th> <th>ITF ITN Number</th> <th>Age</th> <th>Club</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><a href='mailto:{$row['username']}'>{$row['username']}</a></td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['showdetails'] . "</td>"; echo "<td>" . $row['firstname'] . "</td>"; echo "<td>" . $row['lastname'] . "</td>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['mobile'] . "</td>"; echo "<td>" . $row['tennis_number'] . "</td>"; echo "<td>" . $row['lta_number'] . "</td>"; echo "<td>" . $row['itf_itn_number'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['club'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?>
Hud
Will the yes/no be posted, or saved to a database?
Hi there
The Yes or No is only going to be held in the database. I just need the user to say Yes if they wish their details to be listed
Does that help?
Thanks
Hud
Whats the table name going to be where you save the yes/no ?
Hi
The table name in the database is called members and the dropdown on the page for capturing the value is called showdetails
Thanks
Hud
Well, sounds like a simple SQL querie change to me?
Just change yes to whatever your yes/no value is in your SQL database.Code:$result = mysql_query("SELECT * FROM members WHERE showdetails = 'yes'");
Thanks, i'll give that a try just now![]()
Works perfect... Thanks for your help
Your very welcome. Glad I could help![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks