
xxreenaxx1
Members-
Posts
167 -
Joined
-
Last visited
Never
Everything posted by xxreenaxx1
-
mysql_num_rows() expects parameter 1 to be resource
xxreenaxx1 replied to xxreenaxx1's topic in PHP Coding Help
I appreciate your help and I did mention about me not knowing function. But thanks for the tips. I am reading the link you have provided me, Hopefully that should cover everything I want to know about function. Thank you -
mysql_num_rows() expects parameter 1 to be resource
xxreenaxx1 replied to xxreenaxx1's topic in PHP Coding Help
$query=fncsubject(); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=myselect>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } echo "</select>"; This is my code for a form and would like to call this function <?PHP function fncsubject(){ $con = fncOpenConnection(); mysql_select_db("Examination", $con); $result = mysql_query("SELECT DISTINCT s.Sub_ID, s.Sub_Name FROM user u, user_x_subject us, subject s, test t WHERE u.Use_ID = '{$_SESSION['username1']}' AND u.Use_ID = us.Use_ID AND s.Sub_ID = us.Sub_ID AND us.Sub_ID = t.Sub_ID") or die('Cannot Execute:'. mysql_error()); fncCloseConnection($con); return $result; } ?> -
mysql_num_rows() expects parameter 1 to be resource
xxreenaxx1 replied to xxreenaxx1's topic in PHP Coding Help
Oops.. I am new to function. Have No idea how to use it or even what that is. Any website you would like to recommend me to. I was focused to use this function thing -
mysql_num_rows() expects parameter 1 to be resource
xxreenaxx1 replied to xxreenaxx1's topic in PHP Coding Help
This is my query. And the query actually works. <?php function fnclogin(){ $con = fncOpenConnection(); mysql_select_db("Examination", $con); $result = mysql_query("SELECT * FROM user WHERE (Use_ID = '" . mysql_real_escape_string($_POST['ID']) . "') and (Use_Password = '" . mysql_real_escape_string($_POST['password']) . "')and (Rol_ID = '1')") or die('Cannot Execute:'. mysql_error()); fncCloseConnection($con); return $result; } ?> This is my code and including this in to my php as -
I have tired to search this up but get nothing back.. :@ This error is on line 18 on line 18 is if (mysql_num_rows($result) == 1) { This is the error message. if (mysql_num_rows($result) == 1) { // Set username session variable $_SESSION['ID'] = $_POST['ID']; header("location:Staff_Menu.php"); } else { echo"Wrong Username or Password"; }
-
May be I didn’t explain it clearly. I have a question for this I have four choices. So I would need them row to insert different answer for these rows. And it’s a multiple choice.
-
why not? I am not repeating anything, so yehh. May be I am being stupid, but is there any error in my table. If yes, what is it
-
I am trying to insert what I have Printed on my page. I have two tables Question table layoyt: Que_ID Que_Choice1 Que_Choice2 Que_Chocie3 Que_Choice4 Answer table layout: Que_ID Ans_Choice1 Ans_Choice2 Ans_Choice3 Ans_Choice4 Use_ID With these two tables, the first table is used to output the choice that has been made by the user and I can echo these. with these result I want to insert Question ID, choice that is selected as 1 to my answer table. But my PHP is for loop. This is how I am printing the result session_start(); $name= $_SESSION['username1']; echo "User ID: $name <br/>"; $gender = $_POST["choice"]; $que_ID = $_POST["Que_ID"]; foreach ($gender as $key => $array) { if($array) { $val=1; } ///echo "Question ID and the choice ID:$key. Value is:.$val <br />\n"; $well = array(floor($key), substr(strstr($key, '.'), 1)); //$well = array(floor($key), $key - floor($key)); echo "Question ID: $well[0], "; echo "Choice: $well[1]. value: $val<br/>"; } //}break; ?> How would I insert what I have echoed into my answer table.
-
I dont see the solved button. But this has been solved
-
Thank you . It works
-
You are awesome......... One more question. When I print my second value. its does 0.3 or 0.1 or whatever
-
can you have something like.. echo $whatever; this putput 1.2 can you split this number so the first integer will be in $val"(1)" or whatever and the second integer after the "." will be in $val2"(2)"
-
Thanks for the help, I didnt really get your code. I thought I would explain the description as I find that hard to do.
-
I am kind of confused. So far I can print the choices but not the Question ID according to that. while($submit = $_POST['submit']){ $questionid= $_POST['Que_ID']; echo "Question ID: $questionid"; foreach ($_POST["choice"] as $question => $answer) { if($answer == NULL) { $val=0; }else{ $val = 1; } echo "choice id: $question. value: $val"; } } For this code Question ID just get repeated by the last question. And its not meant to do that. My form has been changed to $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"Radio\" name=\"choice{$info['Que_ID']}.{$i} []\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++; } } ?> <input type="submit" value="submit" name="submit"> </form>
-
I have tried your way. <HTML> <BODY> <?php if($_POST){ echo "<pre>"; print_r($_POST); echo "</pre>";} else{ $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db('test', $conn); $query = "SELECT * FROM test"; $result = mysql_query($query); $counter = 1;?> <form action="<? echo $PHP_SELF; ?>" method="POST"> <?php while( $info = mysql_fetch_assoc($result)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID_{$info['Que_ID']}\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"Que_ID_{$info['Que_ID']}[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"Que_ID_{$info['Que_ID']}[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"Que_ID_{$info['Que_ID']}[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"Que_ID_{$info['Que_ID']}[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; } ?> <input type="submit" value="submit"/> </form><?php mysql_close($conn); } ?> </BODY> </HTML> this is the message I am getting
-
Why wont my radio array show the value that was selected. If a user select a radio then the value should be printed. But it should print the question id then the choice that was chosen for that question id. <?php $gender = $_POST["choice"]; $que_ID = $_POST["Que_ID"]; foreach ($gender as $key => $value) { echo $key." - ".$value."";} ?> $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"Radio\" name=\"choice[{$info['Que_ID']}][]\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++;
-
I have worked on a while loop as a radio and this dispalys well and Now I am trying to post this to the next page. But kind of stuck. This is my while loop for the form $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"Radio\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++; } } ?> <input type="submit" name="submit" value="submit"/> </form> </body> </html> Now in order for me to post this to the next page, can I do something like if (isset($_POST['Submit1'])) { $qu=$_POST[Que_ID]; $choi=$_POST[choice]; for($i=1; $1=5; i++) echo $qu. $choi; this is just my guess. I want the que_ID to display four choice for each question ID. so it would be Question ID=2(choice1=selected, choice2=notselected, choice3=not selected, chocie4=not selected) and this would be repeated to the next question ID. So far I can notice that my chociename are added by one(choice1, choice2,choice3,choice4,choice5,choice6,choice7,choice8,choice8......) so my post for loop will not work work as my choices goes up to more then 5.
-
@mhodge_txs, I tried your code but this is what I get. I dont even get my form but straight goes into POSTING
-
Invalid argument supplied foreach() foreach ($_POST["Que_ID"] as $question)
-
Thanks for the reply. Your code will return <input type="hidden" value="1" name="Que_ID[]"> <input type="checkbox" value="1" name="choice[1][]"> <input type="checkbox" value="2" name="choice[1][]"> <input type="checkbox" value="3" name="choice[1][]"> <input type="checkbox" value="4" name="choice[1][]"> <input type="hidden" value="2" name="Que_ID[]"> <input type="checkbox" value="1" name="choice[2][]"> <input type="checkbox" value="2" name="choice[2][]"> <input type="checkbox" value="3" name="choice[2][]"> <input type="checkbox" value="4" name="choice[2][]"> But I wanted my form to return <input type="hidden" value="1" name="Que_ID[]"> <input type="checkbox" value="1" name="choice[1][]"> <input type="checkbox" value="2" name="choice[2][]"> <input type="checkbox" value="3" name="choice[3][]"> <input type="checkbox" value="4" name="choice[4][]"> <input type="hidden" value="2" name="Que_ID[]"> <input type="checkbox" value="1" name="choice[5][]"> <input type="checkbox" value="2" name="choice[6][]"> <input type="checkbox" value="3" name="choice[7][]"> <input type="checkbox" value="4" name="choice[8][]"> action page gives me an error "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\Testphp on line 6" on line 6 is echo "Question id: ".$question. implode(',',$choice")<br />"; the action code that I used for the choice is foreach ($_POST["choice"] as $choice => $answer) { if(!empty($answer)){ $val = 1; echo "Choice ID: .$choice. $val. is ticked <br/>\n"; } else{ $val = 0; echo "Choice ID: $choice.$val"; }} outcome of this is Now, I just want the question id to go with these. So que_ID(choice1, choice2,choice3, choice4) eg. 2(ticked,ticked,ticked,ticked). I can only display the result of ticked one and I cant display the empty one. If its not ticked then its a 0 and if its ticked it 1. so the outcome would be something like 2(1,1,0,1)
-
How do I post a for loop array in the next page. I am printing Question ID and choices for these and would like the for loop to print Question ID and choice that are checked for these. If the choice is ticked then it shoul return a 1 if the choice is empty then it should print 0. and I would like to insert this to a new table. How would I do this. $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; ?> <br> <?PHP for ($i =1; $i < 5; $i++) { echo "<input type=\"checkbox\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}"; $intnumber++; } this is my form that print the question and it works fine. <?PHP foreach ($_POST["Que_ID"] as $question) { $_POST["choice"] = $choice; echo "Question id: ".$question. $choice"<br />"; This is the post code but I know I need to do so much more but not sure how? Ayone help me or direct me to a source or tutorial or something.
-
Thank you so much for your response @ mhodge_txs 1, yes it is the result <?php $sql = ("SELECT * FROM user u,question q, test t WHERE u.Use_ID = '{$_SESSION['username1']}' AND t.Sub_ID = '{$_SESSION['ssubject']}' AND q.Tes_ID = t.Tes_ID AND q.Tes_ID = {$_SESSION['smodule']}") or die(mysql_error()); echo $sql; $sqll = mysql_query($sql); ?> 2, I do want the $info to return array as choice1 to 4 is repeating. and this is why I created a counter so each time the while loop is process the name of the choice wouldnt be the same. Que_ID=1(choice1,choice2,choice3,choice4) second loop. Que_ID=2(choice5,choice6,choice7,choice8) 3, Yes I am accepting more then one answer. Because I want the name to be different or atleast add one number each time it loops the choices so when I call these choices each will have different value and names. 4, I am not sure what I should change. @Muddy_Funster I have shown my sql query on the top. <html> <body> <form action="Test_Completed.php" method="POST"> <?PHP include '../Database/take_an_exam.php'; //$intNumber = 1;] $counter = 1; while( $info = mysql_fetch_assoc( $sqll )) //)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; } ?> <input type="submit" value="submit"/> </form> </body> </html> </body> </html>
-
I am trying to post while loop array. But I dont know how to do this and I used foreach and it works for each array but doesnt loop this. My table has Que_ID, Question, choice1, choice2, choice3 and choice 4. I would like to do something like.. For each Que_id (choice1, choice2, choice3 , choice4), this should be looped for each que_id so far I have $counter = 1; while( $info = mysql_fetch_array( $sqll )) //)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; How would go on to posting these while loop and display Que_ID and all the choices that are ticked for this que_ID and if its not ticked then its 0.
-
I am seriously LOST. Let me explain fully. I have a question table. In this I have Question ID, question, Choice1, Choice2, Choice 3 and choice 4. These choice are set as checkbox so if a student is taking an exam they will tick the choice which is correct and I want to post the ticked checkbox to another page and INSERT this to new table called Answer. But in this table I need the question ID. This question ID should be retrieved from the question table. My answer table needs Answer to choice 1, Answer to choice2, Anser to choice3, Answer to choice 4, Question ID and User ID. I am retrieving user id from a session and answer to choice 1 to 4 should be either 0 or 1. Depend on the checkbox. If a checkbox is ticked then its 1 if not it should be written as 0. so in order for me to set the exam I am using while loop to output the question and the choices. Now i need to post these and gather information as stated above. $intNumber = 1; while($info = mysql_fetch_array( $sql )) { "<input name=\"Que_ID[]\" value=\"{$info['Que_ID']}\" /> "; echo "$intNumber, {$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $intNumber++; } ?> <input type="submit" value="submit"/>
-
Sorry, So I am using checkbox to retrieve questions and choices for these. include '../Database/take_an_exam.php'; $intNumber = 1; while($info = mysql_fetch_array( $sql )) { echo "$intNumber, {$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; These checkbox will be posted on to another page where I will be able to add them to a new table. But the trick is I have to get the Question Id for the question name and how would I go on to posting these values. So for example if choice 1 was ticked then its a 1 or else its a 0. For each choices I can check wherther they are ticked and if they are then its value 1 if not its 0. But not sure how to get question id. foreach ($_POST['choice1'] as $key => $val) { if(empty($val)) { $val2 = "0"; //mysql_query("INSERT INTO answer (`Ans_Answer1`)VALUES ('{$val2}'"); } else { echo "wrong"; //mysql_query("INSERT INTO answer (`Ans_Answer1`)VALUES ('{$val}'"); } }