Jump to content

need help in my query!


cyrixware

Recommended Posts

I need to check first if all of the items are selected. For example, I have ten items in a row. Every items has a choice ex A,B,C,D representing a radio buton.  The problem is if i want to click save the answer will automatically save in the database but if the answer let say from number 1-10, item number 5 is missing or not selected a choice it will display "pls select your answer in item number 5". How to do that?

 

 

<?php
$j = 0;  


while($r_display_students_enrolled = mysql_fetch_array($q_display_students_enrolled))
{
$j++;
<?
<?php echo"<input name=studAns[$j] type=radio value=A>"?>
<?php echo"<input name=studAns[$j] type=radio value=B>"?>
<?php echo"<input name=studAns[$j] type=radio value=C>"?>
<?php echo"<input name=studAns[$j] type=radio value=D>"?>
<?php
}
?>
Insert codes here....

 

Should i use this one?

 

<?php
        $varX      	= count($_REQUEST['studAns']);
for ($varY 	= 0 ; $varY < $varX   ; $varY++)
{ 
	if ((!$_POST[studAns][$varY]) || ($_POST[studAns][$varY] = " "))
	{
		echo "Please select answer every question.";
	}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/97735-need-help-in-my-query/
Share on other sites

Can you post a link to your form?

 

Why are you using radio buttons and not a check box?

 

tip:

Your code below

<?php
        $varX      	= count($_REQUEST['studAns']);
for ($varY 	= 0 ; $varY < $varX   ; $varY++)
{ 
	if ((!$_POST[studAns][$varY]) || ($_POST[studAns][$varY] = " "))
	{
		echo "Please select answer every question.";
	}
}
?>

 

This may be a better way to create that loop and check values.

 

<?php

     if( isSet($_POST['studAns']) && is_array( $_POST['studAns']) ){
        
for ($varY = 0 ; $varY <= count( $_POST['studAns'])-1  ; $varY++)
{ 
	if ( (!isSet( $_POST[studAns][$varY] ) ) || ( $_POST[studAns][$varY] == " " ))
	{
		$error_msg = "Please select answer every question. <br />";
	}
}//end for loop

        if( isSet( $error_msg ) ) {
           echo $error_msg;
           #echo form to correct here
           
           #set vars/array to null and unset here - mem clean up
           #exit
        }//end if
     }//end if
?>

 

 

If you want low cost paid support you can go to www.phpsupportnow.com and someone there will answer you in the morning.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/97735-need-help-in-my-query/#findComment-500122
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.