Dusaro Posted October 20, 2011 Share Posted October 20, 2011 I have made a thread earlier but i did not get any help. changeapp.php <form method="post" name="memberadd" action="change_app_complete.php"> <label>Name:</label> <select name="member"> <?php $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sqlquery="SELECT * FROM `application` Order By Name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option value='".$row['ID']."'>".$row['Name']." (".$row['Status'].")</option>"; } ?> </select> <br> <label>Status:</label> <select name="Status"> <option value="PENDING">PENDING</option> <option value="ACCEPTED">ACCEPTED</option> <option value="DENIED">DENIED</option> <br> <input type="submit" value="submit" /> </form> change_app_complete.php <?php $status=$_POST['Status']; $member=$_POST['Name']; $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sql="UPDATE application SET Status = '$status' WHERE Name= '$member'"; if(mysql_query($sql,$con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } mysql_close($con); ?> This does not return any errors and does not change the Status... Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/ Share on other sites More sharing options...
sunfighter Posted October 20, 2011 Share Posted October 20, 2011 Having played with this for awhile, I find that it works for me. The column called Status is set to PENDING or ACCEPTED or DENIED. maybe the problem is in this part WHERE Name= '$member'"; This is a number. it comes from <option value='".$row['ID'] If you want a name remove the value from <option> echo "<option>".$row['Name']." (".$row['Status'].")</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1280898 Share on other sites More sharing options...
Dusaro Posted October 20, 2011 Author Share Posted October 20, 2011 did not seem to work... changeapp.php: <html> <head> <title>Honorable Brothers - Change Application Status</title> </head> <body> <h1>Change Application Status</h1> <hr> <form method="post" name="appchange" action="change_app_complete.php"> <label>Name:</label> <select name="member"> <?php $con = mysql_connect("mysql17.000webhost.com","a2186214_gbclan","replay123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a2186214_hbclan",$con); $sqlquery="SELECT * FROM `application` Order By Name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option>".$row['Name']." (".$row['Status'].")</option>"; } ?> </select> <br> <label>Status:</label> <select name="Status"> <option value="PENDING">PENDING</option> <option value="ACCEPTED">ACCEPTED</option> <option value="DENIED">DENIED</option> <br> <input type="submit" value="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1280982 Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2011 Share Posted October 21, 2011 Your select menu's name attribute is 'member' <select name="member">. You would need to reference $_POST['member'] to get the value that was selected. Your original <option tags had a value='...' attribute. That is what you should use and since the values were the ID, you should use the ID column in the WHERE clause in your UPDATE query, not the name column. Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281008 Share on other sites More sharing options...
Dusaro Posted October 21, 2011 Author Share Posted October 21, 2011 so i should use ID not Name? I don't understand what you mean... could you please post the fixed code? Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281024 Share on other sites More sharing options...
iRush Posted October 21, 2011 Share Posted October 21, 2011 $member=$_POST['Name']; That should be member inside instead of name im guessing Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281032 Share on other sites More sharing options...
Dusaro Posted October 21, 2011 Author Share Posted October 21, 2011 $member=$_POST['Name']; That should be member inside instead of name im guessing No, because Name is the column in the database Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281051 Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2011 Share Posted October 21, 2011 ... remove the value from <option> ^^^ That won't work for two reasons - 1) It results in invalid HTML and only certain browsers submit the display text when the value attribute is not present. 2) The display text is not just the name, so in the browsers where this would submit a value, it would take extra processing in the php code to get just the name out of the value. @Dusaro, what ever table column you use, you must be consistent throughout all your code. You started by using the ID as the value in the form's select menu options. You must have had a plan to use the ID or you wouldn't have written the code to do that. Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281102 Share on other sites More sharing options...
Dusaro Posted October 22, 2011 Author Share Posted October 22, 2011 I had made a points table that wrote to a different table using the ID from the first table and i forgot how i had set it up. I am still wondering how i would fix it to update the same table instead of adding to another... Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281290 Share on other sites More sharing options...
Drummin Posted October 22, 2011 Share Posted October 22, 2011 The main thing to make "change_app_complete.php" work is wrapping the section in an IF statement. IF (isset(submit)){ Your processing code } Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281299 Share on other sites More sharing options...
Dusaro Posted October 22, 2011 Author Share Posted October 22, 2011 Never mind, i figured out that i had the variables set wrong. Topic Solved Quote Link to comment https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281301 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.