Jump to content

Recommended Posts

This php code inserts the values into the database

 

 

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="server2go"; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$quesid= $_POST['quesid'];
$question= $_POST['question'];
$answer= $_POST['answer'];
$ranswer = $_POST['ranswer'];
$ranswer1= $_POST['ranswer1'];
$ranswer2= $_POST['ranswer2'];
$qzid= $_POST['qzid'];
$next_id=$_REQUEST['next_id'];


if(($quesid=="")||($quesid==0))
{
$quesid=1;
}
else
{
$quesid=$quesid+1;
}



mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$query = "INSERT INTO questiona (quesid,question,answer,ranswer,ranswer1,ranswer2,qzid)
VALUES
('$quesid','$question','$answer','$ranswer','$ranswer1','$ranswer2','$qzid')";


mysql_query($query) or die('Error1, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error2, insert query failed');
$result = @mysql_query($query);

if ($result)
{
header("location: addquizquestion.php?quesid='$quesid'");
exit();
}


?>

 

 

 

This page has the fields ..... that allow the user to enter in the data

 

<table width="400" border="0" cellspacing="1" cellpadding="2">

<form method=post name=form action="createquizcheck1.php?quesid='.$quesid.'" onSubmit="return validate_form ( );">

<input type=hidden name=todo value=post>

<tr>
      <td width="100">Question</td>
      <td><input name="question" type="text" id="question"></td>
</tr>
<tr>
      <td width="100">Right answer</td>
      <td><input name="answer" type="text" id="answer"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer" type="text" id="ranswer"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer1" type="text" id="ranswer1"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer2" type="text" id="ranswer2"></td>
</tr>


</select>
</td>
</tr>



<tr>
<td width="100"> </td>



<td><input name="add" type="submit" id="add" value="add quiz"></td>

 

What i wanted to know is how do u make it so that the value quesid automatically passes through the php code and increments each time.Please could you help me.

 

Should i use (if(isset($_GET['quesid'])) $quesid = $_GET['quesid'];) and if so how do i use it in the script.Thank you.

i already have a table with a quest id that auto increments but i need the quesid to increment to ten and then go to another php page, The reason for this is i have a qzid as well so that when u click on the quiz question 1 then 2 then 3 will come up to ten, so i cant auto increment in the mysql database i need to have it in the php form.

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="server2go"; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");



if(isset($_POST['add']))
{

if(isset($_GET['quesid'])) 
{
$quesid = $_GET['quesid'];


header("location: createquizcheck1.php?quesid=$quesid");
exit();


}
}

?>


<table width="400" border="0" cellspacing="1" cellpadding="2">

<form method=post name=form action="" onSubmit="return validate_form ( );">

<input type=hidden name=todo value=post>

<tr>
      <td width="100">Question</td>
      <td><input name="question" type="text" id="question"></td>
</tr>
<tr>
      <td width="100">Right answer</td>
      <td><input name="answer" type="text" id="answer"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer" type="text" id="ranswer"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer1" type="text" id="ranswer1"></td>
</tr>
<tr>
      <td width="100">Wrong Answer</td>
      <td><input name="ranswer2" type="text" id="ranswer2"></td>
</tr>


</select>
</td>
</tr>


<tr>
<td width="100"> </td>



<td><input name="add" type="submit" id="add" value="addquiz"></td>

 

 

and this is my other script

 

<?php


$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="server2go"; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$question= $_POST['question'];
$answer= $_POST['answer'];
$ranswer = $_POST['ranswer'];
$ranswer1= $_POST['ranswer1'];
$ranswer2= $_POST['ranswer2'];
$qzid= $_POST['qzid'];

if(isset($_GET['quesid'])) 
{
$quesid = $_GET['quesid'];



if((quesid==0)||(quesid==""))
{
$quesid=1;
}
else
{
$quesid=$quesid+1;
}



mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$query = "INSERT INTO questiona (quesid,question,answer,ranswer,ranswer1,ranswer2,qzid)
VALUES
('$quesid','$question','$answer','$ranswer','$ranswer1','$ranswer2','$qzid')";


mysql_query($query) or die('Error1, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error2, insert query failed');
$result = @mysql_query($query);

if ($result)
{
header("location: addquizquestion.php?quesid=$quesid");
exit();


}
}


?>

 

 

Please dont be too harsh im a newbie ,:-) thanks for your time.

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.