Jump to content

Recommended Posts

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 button 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
https://forums.phpfreaks.com/topic/286448-a-line-app/
Share on other sites

uhhh -  need a bit more direction here.  When you say 'timeline' I envision a line on the page.  Or a list of times. What is the granularity of this timeline?  And how many radio buttons do you have to associate with this timeline?  Removing a button s/b no problem.  Simply create a session array var and make entries for each button value you output.  When one is picked, tag that array element as used and then regenerate your button elements, disabling any that has already been picked, as indicated by the session array.

Edited by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1470264
Share on other sites

hey man, 

 

look i have a list of radio buttons as you said, im kind of new to this, what do you mean by session array ? if you can show me a little example ..

 

 

this is my html form

 

<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="choice3" value="3" onclick="toggle('show')"/>10:30-10:45</li>
  
   <li><input type="radio" name="placeInLine" id="choice4" value="4" onclick="toggle('show')"/>10:45-11:00</li>
    
 <li><input type="radio" name="placeInLine" id="choice5" value="5" onclick="toggle('show')"/>11:00-11:15</li>
 
 <li><input type="radio" name="placeInLine" id="choice6" value="6" onclick="toggle('show')"/>11:15-11:30</li>
 
 <li><input type="radio" name="placeInLine" id="choice7" value="7" onclick="toggle('show')"/>11:30-11:45</li>
 
 <li><input type="radio" name="placeInLine" id="choice8" value="8" onclick="toggle('show')"/>11:45-12:00</li>
 
<br />
<input type="submit" value="Save my choice" class="button" />
 
</ul>
 
</form>
Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1470288
Share on other sites

In your php code that outputs the radios, use a loop to output each one using a var to set the value clause of the button and to set an array value like this:

$no_btns = 10;   // how many buttons to output
for ($I=1;$I<=$no_btns; $I++)
{
   $val = 'radio'.$i;
    $disab = '';
    if ( isset($_SESSION[$val]) && $_SESSION[$val) == "X")
            $disab = 'disabled';
//
    echo "<li><input type='radio' name='placeInLine' id='choice$i  $disab value='$i' onclick="toggle('show')"/>11:15-11:30</li>";
}

      

 
When your script retrieves the input from the client and determines the radio button that was selected, you set that session value as in
if ($_POST['placeInLine'] <> ''){
   $val = 'radio' . $_POST['placeInLine'];   $_SESSION[$val] = "X";}

 
Of course you need to validate the incoming post values before doing this.
Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1470315
Share on other sites

hey man,  i was trying to make it a bit more simple but i have a syntax problem i cant solve , do you mind take a look ?

 

 

 

<title>hairdresser</title>
<?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
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1470681
Share on other sites

Ps - looking at this code I get the impression that you don't know any php.  Your coding skills and syntax errors are incredibly elementary.

 

1 - you are running the query twice - why?

2 - you are comparing a result row against the value of the radio button.  Do you have any idea how impossibly wrong that is?

3 - you make reference to something called "$table(choice)" in your query statement.  What is that supposed to be?

4 - you run the first insert query with nothing to capture the results.

5 - you create a query statement after #4 but you never run it

 

Lastly you begin by running a query and capturing the results but you never use it.  Plus I don't know what its relevance to the rest of the code is.

Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1470685
Share on other sites

  • 2 weeks later...

hey guys,

 

i managed to do i needed thank you all !!  now i need to put the form i created in my html page and i have a problem with that ..

i want to put the form in a div section . 

 

i added the php code ( test)

<?php

//  include("connect.php");
   
   $db_host = "localhost";
$db_username = "root";
$db_pass = "test123";
$db_name = "test_database";
$table="placeinline";


$dbcon =  mysqli_connect("$db_host","$db_username","$db_pass", "$db_name" ) or die("could not connect to mysql");
@mysql_select_db("$db_name") or die ("no database");

//echo "successful Connection";
   
   
 
   
   for($k=1; $k<=12;$k++){
   $query= "SELECT * FROM placeinline WHERE choice = $k ";
   $result= mysql_query($query);
   
   if(mysql_fetch_array($result)){
  
     switch($k)
	 {
	 	   
	 	case 1:   $disab1= "disabled";
	              
		           break;
	              
  
		case 2:   $disab2= "disabled";
	              
                   break;
				   
		case 3:   $disab3= "disabled";
	             	
		           break;
	                
		case 4:   $disab4= "disabled";
                
		          break;
				  
	    case 5:   $disab5= "disabled";
                  
		          break;
	    case 6:   $disab= "disabled";
	             
		           break;
	              
  
        case 7:   $disab7= "disabled";
	               
                   break;
				   
		case 8:   $disab8= "disabled";
	             	
		           break;
	                
		case 9:   $disab9= "disabled";
                  
		          break;
				  
	    case 10:   $disab10= "disabled";
                  
		          break;
		case 11:   $disab11= "disabled";
                  
		          break;
				  
	    case 12:   $disab12= "disabled";
                  
		          break;
					
	 }
     }
   }


   
    echo '<form action="test.php" method="POST">';
    
    echo '<input type="date" id= "linedate"><br/>';
    echo "<li> <input type='radio' name='placeInLine' id='choice1'  $disab1 value= '1' /> 10:00-10:15 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice2'  $disab2 value= '2' /> 10:15-10:30 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice3'  $disab3 value= '3' /> 10:30-10:45 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice4'  $disab4 value= '4' /> 10:45-11:00 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice5'  $disab5 value= '5' /> 11:00-11:15 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice6'  $disab6 value= '6' /> 11:15-11:30 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice7'  $disab7 value= '7' /> 11:30-11:45 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice8'  $disab8 value= '8' /> 11:45-12:00 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice9'  $disab9 value= '9' /> 12:00-12:15 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice10' $disab10 value= '10'/> 12:15-12:30 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice11' $disab11 value= '11'/> 12:30-12:45 </li>";
    echo "<li> <input type='radio' name='placeInLine' id='choice12' $disab12 value= '12'/> 12:45-13:00 </li>";

    echo '<input type="submit" value="Submit">';
    echo "</form>";
	
$choice = $_POST['placeInLine'];
echo $choice;


$sqlinsert = "INSERT INTO placeinline (choice) VALUES ('$choice') ";

if(!mysqli_query($dbcon,$sqlinsert)){
			die('error insertin');
		}
	
	$newrecord = " 1 choice added to the line";
    echo $newrecord;
	
	

?>



Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1472444
Share on other sites

You haven't learned much since your last post.  So much wrong with your code. and your coding.

 

1 - you should not be doing a query inside of a loop.  Look up the syntax for "where field in (....)" used in queries.

2 - you have to store the fetch'ed row into something, otherwise why do the fetch at all?  It's like going to the well without a bucket.

3 - nice try to capture data from multiple rows by using the same name= value, but how do you recognize which row the input comes from?  You probably want to use the format "name='placeinline[]' which will create an array of values in the POST array.

 

You have a lot of catching up to do.

 

Suggestion?  Stop using upper- & lowercase in your var names.  It's going to catch up to you one day. One mis-typed char and you're going to be searching for an error for a long time.

Link to comment
https://forums.phpfreaks.com/topic/286448-a-line-app/#findComment-1472445
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.