kevincro Posted October 22, 2007 Share Posted October 22, 2007 I've been experimenting with if statements, and have run into something I can't figure out. What I want to do is construct an if statement that will display one of two submit buttons. The idea is for members to be able to click the apply button and are automatically added to a select box. When the page reloads the button should now read unapply. I've made the page and can make it work using both buttons on the same page but I can't seem to figure out the right if statement. What I have looks something like this: <? $sql=("SELECT * From Applicants WHERE Project='$data_key'"); $Applicant=$row['Applicant_Name']; $query=mysql_query($sql); $row=mysql_fetch_array($query); IF ($userdata['user_name']!=$Applicant){ echo "<tr><td><INPUT TYPE=\"SUBMIT\" name=\"apply\" VALUE=\"Apply\"></td></tr>\n"; }elseif($userdata['user_name']==$Applicant){echo "<tr><td><INPUT TYPE=\"SUBMIT\" name=\"unapply\" VALUE=\"Unapply\"></td></tr>\n"; } ?> This code will display the apply button and the link works well at adding the member's name to the database, yet when the page reloads the same submit button shows up and the action is the same. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 23, 2007 Share Posted October 23, 2007 <?php if ($userdata['user_name']!=$Applicant){ echo "<tr><td><INPUT TYPE=\"SUBMIT\" name=\"apply\" VALUE=\"Apply\"></td></tr>\n";} elseif($userdata['user_name']=$Applicant) {echo "<tr><td><INPUT TYPE=\"SUBMIT\" name=\"unapply\" VALUE=\"Unapply\"></td></tr>\n"; }?> Quote Link to comment Share on other sites More sharing options...
trq Posted October 23, 2007 Share Posted October 23, 2007 Look at the logic in your code. This line.... $Applicant=$row['Applicant_Name']; You use an array ($row) that is not actually defined for another two lines. Try... <?php $sql = "SELECT * From Applicants WHERE Project='$data_key'"; // where does $dat_key come from? if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); if ($userdata['user_name'] != $row['Applicant_Name']) { // where does $userdata come from? echo "<tr><td><input type=\"submit\" name=\"apply\" value=\"Apply\"></td></tr>\n"; } else { echo "<tr><td><input type=\"submit\" name=\"unapply\" value=\"Unapply\"></td></tr>\n"; } } } ?> ?> Quote Link to comment Share on other sites More sharing options...
kevincro Posted October 23, 2007 Author Share Posted October 23, 2007 $data_key is a variable passed from a previous page using "get". $userdata is a superglobal in PHP fusion that will provide info about the user. Quote Link to comment Share on other sites More sharing options...
trq Posted October 23, 2007 Share Posted October 23, 2007 $data_key is a variable passed from a previous page using "get". Then you'll need to use.... <?php if (isset($_GET['data_key'])) { $data_key = mysql_real_escape_string($_GET['data_key']); $sql = "SELECT * From Applicants WHERE Project='$data_key'"; // where does $dat_key come from? if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); if ($userdata['user_name'] != $row['Applicant_Name']) { // where does $userdata come from? echo "<tr><td><input type=\"submit\" name=\"apply\" value=\"Apply\"></td></tr>\n"; } else { echo "<tr><td><input type=\"submit\" name=\"unapply\" value=\"Unapply\"></td></tr>\n"; } } } } ?> Quote Link to comment Share on other sites More sharing options...
kevincro Posted October 23, 2007 Author Share Posted October 23, 2007 I tried that code and no buttons are showing up. Do you think there is something wrong with my condition statement? The table I'm working with has 3 columns, when the member applies, it should add the project number, the name of the member, and their user id. The user id is not needed on this page. Quote Link to comment 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.