Jump to content

MIR1999

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

MIR1999's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok here's an update. After reading another topic on here about passing variables after a submit button had been pressed i decided i would try and use a session to help with my problem. At the very top of my page i put in <?php session_start(); ?> Then when my while loop had finished and my array had been finalised i put in $_SESSION['questids']=$_POST['qid'] Now by my reckoning i have created a new array questids and filled it with the values of qid. Is this correct? Then in my INSERT command held in the 'else' invoked when the button is pressed i have tried various pieces of code e.g. }else{//Add question ids to database require_once ('../mysql_connect.php'); $qu = "INSERT INTO test_score(subject_id, q1,q2,q3,q4,q5,q6,q7,q8,q9,q10) VALUES('1','$questids[0]','$questids[1]','$questids[2]','$questids[3]','$questids[4]','$questids[5]','$questids[6]','$questids[7]','$questids[8]','$questids[9]')"; $res = @mysql_query ($qu) or die(mysql_error());//Run the query } mysql_close(); I also tried this: }else{//Add question ids to database require_once ('../mysql_connect.php'); $qu = "INSERT INTO test_score(subject_id, q1,q2,q3,q4,q5,q6,q7,q8,q9,q10) VALUES('1','".$_SESSION['questids'][0]."','".$_SESSION['questids'][1]."','".$_SESSION['questids'][2]."','".$_SESSION['questids'][3]."','".$_SESSION['questids'][4]."','".$_SESSION['questids'][5]."','".$_SESSION['questids'][6]."','".$_SESSION['questids'][7]."','".$_SESSION['questids'][8]."','".$_SESSION['questids'][9]."')"; $res = @mysql_query ($qu) or die(mysql_error());//Run the query } mysql_close(); Both continue to give the error Incorrect integer value:"for column 'q1' at row 1 error message. I can't see where i'm going wrong. Can anyone help?
  2. [!--quoteo(post=355114:date=Mar 14 2006, 11:04 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 11:04 PM) [snapback]355114[/snapback][/div][div class=\'quotemain\'][!--quotec--] My guess would be that you are trying to insert an incorrect integer value into the q1 field for your table. Check the data type of that field...if it's supposed to be an INT, then make sure you are trying to insert an INT, if it's not supposed to be an INT, then change it. echo out your query if needed to check that it is correct as well. [/quote] What i've done to test it is to make the initial form display happen only when the button is pressed. I changed if(!isset($_POST['submitted'])){ //display the form to if(isset($_POST['submitted'])){ //display the form so that everything happens only when the button is pressed. I also had to remove the last 'else' so that the database query ran when the button was pressed. When i run it like this it works fine so the correct information is being passed to the array and then onto my table. The problems only start to happen when the array info is passed with if(!isset($_POST['submitted'])) and the last 'else' in place. My array information is not being sent when the submit button is pressed. To get round this i even tried making the insert values like the following: '".$_POST['qid'][0]."' with the 1 changing to a 1 and so on but again i get the Incorrect integer value:"for column 'q1' at row 1 error message.
  3. [!--quoteo(post=355103:date=Mar 14 2006, 10:43 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 10:43 PM) [snapback]355103[/snapback][/div][div class=\'quotemain\'][!--quotec--] Why are you supressing errors on your query when it's giving you problems? change it to: [code]$res = mysql_query($qu) or die(mysql_error());[/code] [/quote] Believe me it wasn't intentional. I'm not very good at this lol. Thanks for your quick replies. The error message i get now is: Incorrect integer value:"for column 'q1' at row 1 Any ideas?
  4. [!--quoteo(post=355090:date=Mar 14 2006, 10:12 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 10:12 PM) [snapback]355090[/snapback][/div][div class=\'quotemain\'][!--quotec--] Your missing the variable delimiter ($) before your array variable: '[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[0]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[1]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[2]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[3]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[4]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[5]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[6]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[7]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[8]','[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]qid[9]' [/quote] You are correct. However, i've now added them and it makes no difference. There are still no values being added to the table.
  5. Hello again, Having trouble inserting array values into my database table. The array in question - $qid - is created from values of one table. The form is displayed and when the submit button is pressed i would like the array values to be entered into another table. Here is some of what i have, i have cut irrelevant bits out. I think the problem lies with the fact that when the form is submitted my array values are no longer available so they cannot be inserted. Any ideas? <form name ="systemstest" action="<?php echo $_SERVER['PHP_SELF'];?>"method="post"> <div align="center"><input type="submit" value="check score" name="submitted"></div> <?php //Connect to db. require_once ('../mysql_connect.php'); //Select 10 random questions $query = "SELECT question_id, question, answer, choice1, choice2, choice3 FROM questions ORDER BY RAND() LIMIT 10"; $result = @mysql_query ($query); //Run query if(!isset($_POST['submitted'])){ //display the form $randomiseAnswer=rand(1,5);//used for randomising answer order if($result) { echo '<table align="left" cellspacing="10" cellpadding="10">'; $qid=array(); $counter = 0; while ($row=mysql_fetch_array($result,MYSQL_NUM)){ $id = $row[0]; $qid[$counter] = $id; $questions = $row[1]; $answer = $row[2]; if($randomiseAnswer==1){ $opt1 = $row[3]; $opt2 = $row[4]; $opt3 = $row[5]; } elseif{......}(more choices) //Show questions and random choices (some html/php code) $counter++; }//end while echo '</form>';//close form }else{ //else no result echo'<p>Test failed</p>'; } }else{//Add question ids to database if submitted is pressed require_once ('../mysql_connect.php'); $qu = "INSERT INTO test_score(subject_id, q1,q2,q3,q4,q5,q6,q7,q8,q9,q10) VALUES ('1','qid[0]','qid[1]','qid[2]','qid[3]','qid[4]','qid[5]','qid[6]','qid[7]','qid[8]','qid[9]')"; $res = @mysql_query ($qu);//Run the query } mysql_close(); ?>
  6. Here are the error messages i get when i try to implement my session: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2 wanted to redirect you but i could not do it! Here is the code i have: <?php session_start(); //Start the session, register the values and redirect. $_SESSION['first_name'] = $row[1]; $_SESSION['user_id'] = $row[0]; if(!headers_sent()){ header("Location:http://localhost/logged_in.php"); exit(); }else{ echo'wanted to redirect you but i could not do it!'; } if(isset($_POST['login'])){ $u = $_POST['Login_email']; $p = $_POST['Password']; //Connect to db. require_once ('../mysql_connect.php'); $query = "SELECT user_id, first_name FROM users WHERE email='$u' AND password='$p'"; $result=@mysql_query($query); $row=mysql_fetch_array($result,MYSQL_NUM); if($row){//A match was made }else{//No match was made echo '<p>The email and password entered do not match those on file.</p>'; } mysql_close(); }else{ ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type"content="text/html;charset=encoding"/> <title>Login</title> <script type="text/javascript" language="Javascript"> <!--//Validate the textfields function CheckLogData() { var problem2 = 'No'; if (document.login.Login_Name.value.length<=0) { alert ("Enter your UserName."); document.login.Login_Name.value = "*** UserName"; document.login.Login_Name.focus(); problem2 = 'Yes'; } if (document.login.Password.value.length<=0) { alert ("Enter your Password."); document.login.Password.value = "*** Password"; document.login.Password.focus(); problem2 = 'Yes'; } if (problem2 == 'No') { return true; } else { return false; } } //--> </script> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="return CheckLogData()"> <fieldset><legend> Enter your email address and password in the boxes below:</legend> <p align="left"><b>Email :</b> <input type="text" name="Login_email" size="30"></p> <p align="left"><b>Password :</b><input type="text" name="Password" size="20"></p> <p align="left"><input type="submit" name="login" value="LOGIN"></p> </form> </body> <?php } ?> </html> Any ideas why its gone pear shaped? I accept that the code is probably completely wrong. Let me have it, don't hold back!!
  7. [!--quoteo(post=354000:date=Mar 11 2006, 08:36 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 11 2006, 08:36 PM) [snapback]354000[/snapback][/div][div class=\'quotemain\'][!--quotec--] this is not the full answer, you you should get the picture pretty easily... You could even randomize the orders directly instead... [code] $rand=rand(1,4) if($successful)    { echo '<table align="left">'; while ($row=mysql_fetch_array($result,MYSQL_NUM)){ $id = $row[0]; $q = $row[1]; if($rand==1){ $answer1 = $row[2]; $answer3 = $row[3]; $answer2 = $row[4]; $answer4 = $row[5];} elseif($rand==2){ $answer2 = $row[2]; $answer4 = $row[3]; $answer3 = $row[4]; $answer1 = $row[5];} elseif($rand==3){ $answer4 = $row[2]; $answer1 = $row[3]; $answer3 = $row[4]; $answer2 = $row[5];} else($rand==4){ $answer3 = $row[2]; $answer4 = $row[3]; $answer1 = $row[4]; $answer2 = $row[5];} echo'<tr><td align=\"left\">'.$q.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer1.'"/>'.$answer1.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer2.'"/>'.$answer2.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer3.'"/>'.$answer3.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer4.'"/>'.$answer4.'</td></tr>'."\n"; } echo '</table>'; echo '</form>'; }else{ echo'<p><b>Error. Please contact admin</b></p>'; } [/code] [/quote] I tried this and it worked really well. Many thanks. Thanks also to the other reply, i didn't try it but thnks for the effort.
  8. I'm looking for a bit of advice regards the code shown below. I am implementing a questionairre in html/php and got some great help on the code in another thread. One thing i would like to be able to do with my answers is to have them randomly display on the screen instead of them being in the same order all the time. For example, one question may be: What make of mobile phone do you own? A)Nokia B)Motorolla C)Siemens D)Sony. The choices will always be the same except i would like Nokia to be in a different positions from choice A the next time someone runs the questionairre. Is this possible? if($successful) { echo '<table align="left">'; while ($row=mysql_fetch_array($result,MYSQL_NUM)){ $id = $row[0]; $q = $row[1]; $answer1 = $row[2]; $answer2 = $row[3]; $answer3 = $row[4]; $answer3 = $row[4]; echo'<tr><td align=\"left\">'.$q.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer1.'"/>'.$answer1.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer2.'"/>'.$answer2.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer3.'"/>'.$answer3.'</td></tr> <tr><td align=\"left\"><input type="radio" name="option['.$id.']"value="'.$answer4.'"/>'.$answer4.'</td></tr>'."\n"; } echo '</table>'; echo '</form>'; }else{ echo'<p><b>Error. Please contact admin</b></p>'; }
×
×
  • 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.