Adam77 Posted February 23, 2014 Share Posted February 23, 2014 hey guys please help me out here ! i did a time line which people fill their place in line with radio button , now i want to make the radio that already been picked to be disable for everyone else so it cant be picked twice . i have an sql database where i put(by php) the submitted picking. will appreciate any help !!! Adam Link to comment Share on other sites More sharing options...
davej Posted February 23, 2014 Share Posted February 23, 2014 <form action="demo_form.asp"> Choice 1: <input type="radio" name="choice" value="ch1"><br> Choice 2: <input type="radio" name="choice" value="ch2"><br> Choice 3: <input type="radio" name="choice" value="ch3" disabled><br> Choice 4: <input type="radio" name="choice" value="ch4"><br> <input type="submit" value="Submit"></form> Link to comment Share on other sites More sharing options...
Adam77 Posted February 23, 2014 Author Share Posted February 23, 2014 you disable the third choice in your code but how do i let the user do it ? Link to comment Share on other sites More sharing options...
davej Posted February 23, 2014 Share Posted February 23, 2014 (edited) The user would submit the form. The next time you generate the form you would generate it with that radio button disabled. Perhaps also adding the name of the person who has that position. <?php$ch[1] = '';$ch[2] = '';$ch[3] = 'disabled';$ch[4] = '';$assignname[1] = '';$assignname[2] = '';$assignname[3] = 'bobsmith';$assignname[4] = '';echo '<form action="process_form.php">';echo 'Choice 1: <input type="radio" name="choice" value="ch1"'.$ch[1].' >'.$assignname[1].'<br>';echo 'Choice 2: <input type="radio" name="choice" value="ch2"'.$ch[2].' >'.$assignname[2].'<br>';echo 'Choice 3: <input type="radio" name="choice" value="ch3"'.$ch[3].' >'.$assignname[3].'<br>';echo 'Choice 4: <input type="radio" name="choice" value="ch4"'.$ch[4].' >'.$assignname[4].'<br>';echo '<input type="submit" value="Submit">';echo '</form>';?> Edited February 23, 2014 by davej Link to comment Share on other sites More sharing options...
MarkT Posted February 23, 2014 Share Posted February 23, 2014 You could look at using Ajax PHP, possibly. Take a look; http://www.w3schools.com/php/php_ajax_php.asp Link to comment Share on other sites More sharing options...
Adam77 Posted February 23, 2014 Author Share Posted February 23, 2014 hey man, thanks for the help but i still dont understand how to write the loop on it ? right now it chooses the first button to be disabled Link to comment Share on other sites More sharing options...
davej Posted February 23, 2014 Share Posted February 23, 2014 So you have a sql database but you've never used it? Link to comment Share on other sites More sharing options...
Adam77 Posted February 23, 2014 Author Share Posted February 23, 2014 never . if its complicate can you just give me some key terms of what i need nd ill try to find it ? Link to comment Share on other sites More sharing options...
davej Posted February 23, 2014 Share Posted February 23, 2014 Well, if you've never used a database I'm not sure it is the best solution for you here. You might be better off writing this array to a file. In any case you need to go through one or several tutorials... http://www.w3schools.com/php/default.asp Link to comment Share on other sites More sharing options...
Adam77 Posted February 24, 2014 Author Share Posted February 24, 2014 it doesnt really help read all different function and i do have some clue in php .. i know i need to regenerate my radio buttons each time someone is picking a radio button but i dont know how this is all my php file <?php ini_set('display_errors', 'Off'); if(isset($_POST['submitted'])){ include("connect.php"); $choice = $_POST['placeInLine']; mysql_query("INSERT INTO $table(choice) VALUES ($choice)") or die(mysql_error()); $sqlinsert = "INSERT INTO placeinline (choice) VALUES ($choice)"; $newrecord = "1 choice added to the line"; echo $newrecord; $disabled = ($choice != '') ? 'disabled' : ''; } //end of the main if statment ?> <!DOCTYPE html> <html > <head> <title> shop </title> <meta http-equiv="content-type" content="text/html; charset-utf-8" /> </head> <body> <form id= "line" name="line " action="index.php" method="post"> <input type="hidden" name="submitted" value="true"/> <ul> <li><input type="radio" name="placeInLine" id="choice1" value="1"'.$ch[1].' onclick="toggle('show')" />10:00-11:15</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice2" value="2"'.$ch[2].'onclick="toggle('show')" />10:15-10:30</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice3" value="3"'.$ch[3].' onclick="toggle('show')"/>10:30-11:45</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice4" value="4"'.$ch[4].' onclick="toggle('show')"/>10:45-11:15</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice5" value="5" onclick="toggle('show')"/>11:15-11:30</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice6" value="6" onclick="toggle('show')"/>11:30-11:45</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice7" value="7" onclick="toggle('show')"/>11:45-12:00</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <li><input type="radio" name="placeInLine" id="choice8" value="8" onclick="toggle('show')"/>12:00-12:15</li> <div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man <form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman <form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div> <br /> <input type="submit" value="Save my choice" class="button" /> </ul> </form> <script type="text/javascript" src="jquery-1.11.0.js"></script> <script type="text/javascript" src="javaScript.js"></script> </body> </html> Link to comment Share on other sites More sharing options...
Adam77 Posted February 25, 2014 Author Share Posted February 25, 2014 hey guys i simplify my code but i still have a little syntax problem i cant solve, please help <?php include("connect.php"); ini_set('display_errors', 'Off'); if(isset($_POST['submitted'])){ $choice = $_POST['placeInLine']; $query = "SELECT `choice` FROM `placeinline`"; $result = mysql_query($query ); if($query_run = mysql_query($query) ){ echo 'good'; }else{ echo mysql_error(); } $disab = '' ; $row = mysql_fetch_row($result); if($choice==$row){ $disab = 'disabled'; } <form id= "line" name="line " action="test1.php" method="post"> echo "<li> <input type='radio' name='placeInLine' id='choice1' $disab value='1' /> 10:00-10:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice2' $disab value='2' /> 10:15-10:30 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice3' $disab value='3' /> 10:30-10:45 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice4' $disab value='4' /> 10:45-11:00 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice5' $disab value='5' /> 11:00-11:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice6' $disab value='6' /> 11:15-11:30 </li>"; </form> mysql_query("INSERT INTO $table(choice) VALUES ($choice)") or die(mysql_error()); $sqlinsert = "INSERT INTO placeinline (choice) VALUES ($choice)"; $newrecord = "1 choice added to the line"; echo $newrecord; } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now