Jump to content

INSERT INTO trouble


xxreenaxx1

Recommended Posts

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.

User ID: 1

Question ID: 1, Choice: 1. value: 1

Question ID: 2, Choice: 2. value: 1

Question ID: 3, Choice: 3. value: 1

Question ID: 4, Choice: 4. value: 1

 

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.

Link to comment
Share on other sites

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.

 

So for each question, it will have 4 possible answers...if I'm understanding. And will these 4 choices be the same for every question?

ex:

1. Ques 1

    a. 1

    b. 2

    c. 3

    d. 4

2. Ques 2

    a. 1

    b. 2

    c. 3

    d. 4

 

I have a db schema and code for you to base yours on, but would require you to change your db structure, to  be normalized, like fenway said.

Link to comment
Share on other sites

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.

 

Does your table have multiple columns for each question/answer?

Link to comment
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.