I'm making a quiz. I'm getting all the questions on one page, but I don't want that. I only want the first question. After the button is clicked, then i want the second question. How can I accomplish this? Here's my code:
$qry=mysql_query("select `id`,`question` from `paper_details` where `paper_id`='$id'") or die(mysql_error());
$num_rw= mysql_num_rows($qry);
while($f=mysql_fetch_assoc($qry))
{
$q2=mysql_query("select `id`,`que`,`unique_id`,`image` from `que_master` where `id`='".$f['question']."'") or die(mysql_error());
$f2=mysql_fetch_row($q2);
$i=$pid;?>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="4" class="form_border" id="form_table">
<tr>
<th width="3%" rowspan="2" align="left" valign="top" class="form_label"></th>
<th width="5%" height="27" align="left" valign="top" class="form_label">Que<?php echo $i;?> : </th>
<th width="92%" align="left" valign="top" class="form_label"> <?php echo $f2[1]; if($f2[3]!=""){?>
<img src="admin/que_image/<?php echo $f2[3];?>" border="noborder" width="20px" height="20px"/><?php }?>
<input type="hidden" id="que_id" name="que_id" value="<?php echo $f2[0];?>"/>
</th>
</tr>
<tr>
<th height="78" align="left" valign="top" class="form_label">Ans : </th>
<td align="left" valign="top" style="line-height:2.0em;">
<input type="hidden" id="id" name="id" value="<?php echo $id;?>"/>
<input type="hidden" id="pid" name="pid" value="<?php echo $pid+1;?>"/>
<input type="hidden" id="num_raw" name="num_raw" value="<?php echo $num_rw;?>"/>
<input type="hidden" id="time" name="time" value="<?php echo $time;?>" />
<input type="hidden" id="que_id" name="que_id" value="<?php echo $f2[0];?>" />
<?php
$q3=mysql_query("select `id`,`ans`,`ans_img` from `ans_master` where `unique_id`='$f2[2]'") or die(mysql_error());
while($f3=mysql_fetch_row($q3)){
?>
<input type="radio" value="<?php echo $f3[0]; ?>" name="ans" id="ans"><?php echo $f3[1]; ?><?php if($f3[2]!=""){?>
<img src="admin/ans_image/"<?php echo $f3[2];?>" border="noborder" width="20px" height="20px"/>
<?php }
}}
?>
</td>
</tr>
<tr>
<th height="33" align="left" valign="middle" class="form_label"> </th>
<th colspan="2" align="left" valign="middle" class="form_label">
<input type="submit" name="Submit" value="Next >" />
Please help me.
If I understand correctly, you want to have a single-page application to run your quiz.
For this purpose, you could use ajax requests with jquery.
Or else, you can make a separate page for each question.
Related
I have this code in php
<div style="width:75%;height: 600px;float: left;overflow-x: auto;">
<form method="POST" action="addtocart.php">
<table class="table" style="overflow-x: auto; width: 900px;">
<tr>
<th class="danger" id="th">Items</th>
<th class="danger" id="th">Price(PhP)</th>
<th class="danger" id="th">Quantity</th>
<th class="danger" id="th">Action</th>
</tr>
<?php
$item=mysqli_query($conn,"select * from store");
while($pqrow=mysqli_fetch_array($item)){
$iid=$pqrow['id_item'];
?>
<tr>
<td class="warning" id="td">
<?php echo $pqrow['item']; ?></td>
<td class="warning" id="td"><input type="hidden" name="price" value="<?php echo $pqrow['price']; ?>"><?php echo $pqrow['price']; ?></td>
<td class="warning" id="td"><input type="number" style="width: 70px;" name="qty" value="1"></td>
<td class="warning" id="td"><input type="hidden" name="item" value="<?php echo $iid; ?>"><input class="btn btn-success btn-md" type="submit" name="addtocart" value="AddToCart<?php echo $iid; ?>"></td>
</tr><?php } ?>
</table></form>
</div>
When I click AddToCart in first row, the value of the last row has been fetch. I want to get the id and the input quantity when I click the AddToCart in 1st row.
As you have only one form tag and multiple inputs with same name on this form, value of next input overwrites previous one. As a result you always have value of the last row.
You can fix it for example with creating a separate form for every row, e.g:
<div style="width:75%;height: 600px;float: left;overflow-x: auto;">
<table class="table" style="overflow-x: auto; width: 900px;">
<tr>
<th class="danger" id="th">Items</th>
<th class="danger" id="th">Price(PhP)</th>
<th class="danger" id="th">Quantity</th>
<th class="danger" id="th">Action</th>
</tr>
<?php
$item = mysqli_query($conn,"select * from store");
while ($pqrow=mysqli_fetch_array($item)) {
$iid=$pqrow['id_item'];?>
<tr>
<td class="warning" id="td">
<?php echo $pqrow['item']; ?></td>
<td class="warning" id="td"><?php echo $pqrow['price']; ?></td>
<td class="warning" id="td"><input type="number" style="width: 70px;" name="qty" value="1"></td>
<td class="warning" id="td">
<!-- Separate form for each record -->
<form method="POST" action="addtocart.php">
<input type="hidden" name="price" value="<?php echo $pqrow['price']; ?>">
<input type="hidden" name="item" value="<?php echo $iid; ?>">
<input class="btn btn-success btn-md" type="submit" name="addtocart" value="AddToCart<?php echo $iid; ?>">
</form>
</td>
</tr>
<?php } ?>
</table>
</div>
In this case you should track with javascript the value of quantity field. Of course, you can move <input type="number"> in a form too, but this will break your markup.
Also, if you're familiar with javascript, you can add some client preprocessing (getting values from inputs of a certain row) and use ajax-request to send these values to server.
I am using php-webdriver (facebook) and wait 90 seconds for a webpage where name="mdn" is found by following code. This works well but after this I would like to get the text of name="mdn". The hidden form field has a value but on $number there is no value. Does somebody know whats wrong?
Test.php:
$driver->wait(90, 10000)->until(
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
WebDriverBy::name('mdn')
)
);
$number= $driver->findElement(WebDriverBy::name('mdn'))->getText();
Page:
<div id="main content" align="center" class="mainCon">
<div class="mainBG1">
<table width="900" cellspacing="0" cellpadding="0">
<tr>
<td width="650" valign="top">
<div class="paddingT20 paddingB20" style="font-family:'Oswald', sans-serif; font-weight:normal; font-size:35px">xxxxxxx Completed</div>
<form method="post" action="xxxxxxxxxxxxxxxxxxxxxx" target="_blank">
<input type="hidden" name="trans_id" value="1234567" />
<input type="hidden" name="mdn" value="1234567890" />
<input type="hidden" name="bal" value="" />
<input type="hidden" name="exp" value="" />
<input type="hidden" name="note" value="" />
<table width="40%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" class="dv-R"> </td>
</tr>
<tr>
<td width="40%" class="dv-L">MDN</td>
<td width="60%" class="dv-R">6142086840</td>
</tr>
<tr>
<td width="32%" class="dv-L"> </td>
<td width="68%" class="dv-R"><input type="image" value="Print" src="images/xxxxx.png" /></td>
</tr>
</table>
<div class="InfoGr paddingT20 paddingB20"></div><br/>
</p>
</form>
<div class="paddingB40"></div>
</td>
<td valign="top" bgcolor="#e2e2e2"> </td>
</tr>
</table>
</div>
</div>
You can use getAttribute(), because your page have atrribute value and not text.
e.g.
$number= $driver->findElement(WebDriverBy::name('mdn'))->getAttribute('value');
i am facing problem i am developing school system in php.
i want use checkbox dynamic for attendance but checkbox value i cant use in another file please help me
first file attendacne.php
<form name="abc" method="post" action="attendance-con.php">
<p>Date:
<input name="dat" type="text" class="tcal"/>
<input name="Save" type="submit" style="float:right 20ox;" value="Save Attendace" />
<input name="class_id" type="hidden" value="<?php echo $_REQUEST['class_id']; ?> " />
<?php
$a=0;
$qry=("SELECT DISTINCT
s.rollnum as rollnum,
s.std_name as name
FROM student s WHERE s.std_class=".$_REQUEST['class_id']."");
$result=mysql_query($qry);
while($row=mysql_fetch_array($result))
{
?>
<table width="100%" border="1" align="center" cellpadding="4" cellspacing="4" style="text-align:left;" id="stname">
<?php
if($a==0)
{ ?>
<tr>
<th width="117" height="39" bgcolor="#FFE1CC">Student RollNo</th>
<th bgcolor="#FFE1CC">Student Name</th>
<th width="100" bgcolor="#ECFAFF">Present</th>
</tr>
<?php
}?>
<?php
if($a==1)
{ ?>
<tr>
<th width="117" height="-5" bgcolor="#FFE1CC"></th>
<th bgcolor="#FFE1CC"></th>
<th width="100" bgcolor="#ECFAFF"></th>
</tr>
<?php
}
?>
<?php $a=1; ?>
<input type="hidden" name="rollnum[]" value="<?php echo $row['rollnum'];?>"/><tr>
<td>
<?php echo $row['rollnum'];?>
</td>
<td>
<?php echo $row['name'];?>
</td>
<td>
<input type="checkbox" name="stid[]" value="1">
</td>
</tr>
<?php }?>
</table>
</form>
second file attendance-con.php
<?php
include_once("include/config.php");
$i=0;
$Dat=$_POST['dat'];
$cid=$_POST['class_id'];
$sid=$_POST['stid'];
foreach($_POST['rollnum'] as $x)
{
if($sid[$i]=='1')
{
$query=mysql_query("INSERT INTO attendance (sid,cid,Date,status)
values('$x','$cid','$Dat','1')");
}
if($sid[$i]!='1')
{
$query=mysql_query("INSERT INTO attendance (sid,cid,Date,status)
values('$x','$cid','$Dat','0')");
}
$i=$i+1;
}
?>
<input type="checkbox" name="stid" value="1">
not
<input type="checkbox" name="stid[]" value="1">
I want to select a row from MySQL database which there are multiple rows.
I've chosen radio button for selection and I've put id of that row in radio button value.
The problem is the posted radio button is set and when I echo it as you can see in the code it shows me the right id.
When I want to select from database with MySQL query it gives me and index undefined error, the strange point is when I select a table that contains just one row this code is working but when number of rows are more than one I am not able to select the chosen row.
Table code:
<?
if($_SESSION["count"]!=0 || $_SESSION["count"]!="")
{
?>
<!-- begining of levels informations -->
<form name="form2" method="POST" dir="rtl" action="" style="font-family:'B_yekan';">
<div align="center" width="900" >
<table class="styled-table" cellspacing="0" width="900" border="1">
<tr>
<th width="10" scope="col" ></th>
<th width="60" scope="col">level</th>
<th width="60" scope="col">date</th>
<th width="60" scope="col">time</th>
<th width="54" scope="col">price</th>
<th width="60" scope="col">mark</th>
</tr>
<?php
$id = array();
while($rows=mysql_fetch_array($result)){
$id[]=$rows['id'];
?>
<tr>
<td><input class="styled-input" type="hidden" name="id[]" id="id" value= "<? echo $rows['id']; ?>" /></td>
<td><input class="styled-input" type="text" name="lev" id="lev" value="<? echo $tbl_name; ?>" /></td>
<td><input class="styled-input" type="text" name="date[]" id="date" value="<? if($rows['date']=="1"){echo "even";}else{echo "odd";}?>" /></td>
<td><input class="styled-input" type="text" name="time[]" id="time"
value="<?if($rows['time']=="pm1"){ echo"16 - 17:30";}
elseif($rows['time']=="pm2"){ echo "17:45 - 19:15";}
elseif($rows['time']=="pm3"){echo "19:30 - 21";}?>" />
</td>
<td><input class="styled-input" type="text" name="price[]" id="price" value= "<? echo $rows['price']; ?>" /></td>
<td><input class="styled-input" style="padding: 5px;width:20px" type="radio" name="mark[]" id="mark" value="<? echo $rows['id']; ?>" /></td>
</tr>
<?php
}//end of loop
?>
</table>
</div>
<input class="styled-button-8" type="Submit" value="firstchoose" name="firstchoose" />
<?}//end of if check for count?>
</form>
Select code:
<!-- first choose level -->
<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['firstchoose']) && $_POST['firstchoose'] == 'firstchoose')
{
$tbl_name=$_POST['lev'];
for($i=0;$i<$_SESSION["count"];$i++)
{
$checked =mysql_real_escape_string($_REQUEST['mark'][$i]);
echo $checked;
$sql2="SELECT * FROM $tbl_name WHERE `id`='".mysql_real_escape_string($checked)."' ";
$result2=mysql_query($sql2);
$data = mysql_fetch_assoc($result2);
$count2=mysql_num_rows($result2);
}
if(isset($result2)){
?>
<script language="javascript">alert('the level is selected successfully.'); </script>
<?php
}
}
?>
<!-- end of first choose level -->
I have the following code which works well.
The code is to display all the data from the database in input text field format. User is able to edit and update the details by clicking the update button at the end of each row to update the specific row.
Instead of clicking the update buttons one by one (if user wants to edit and update more than one row), now I would like to create a hyperlink which will update ALL the data at once.
The problem now is I dunno how to pass the value of $_post to the "update.php" since I already have
<form name="form1" action="submitAction.php" method="post">
I am not sure is it possible to do so. Or are there any other alternative ways?
<html>
<script language="javascript" >
<!-- hide
function submitRequest(id) {
document.forms[id].submit();
}
// end hide -->
</script>
<!-- The Javasript (Onclick) to Remove the Readonly Attribute-->
<script language="JavaScript">
function removeAlignment(id){
document.getElementById("ProjectName_"+id).removeAttribute("readonly",0);
document.getElementById("DeviceType_"+id).removeAttribute("readonly",0);
}
</script>
<body>
<?php
$counter=1;
//Connecting and Accessing the Database
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Project", $con);
$result = mysql_query("SELECT * FROM Project where status='Ongoing'");
?>
<p><h2 align="center">ADC Project Funnel</h2></p>
<table border="1" bordercolor="lavender" cellspacing="0" cellpadding="0">
<tr>
<td width="20" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">No</font></b></td>
<td width="78" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Project
Name</font></b></td>
<td width="72" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Device Type</font></b></td>
<td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Status</font></b></td>
<td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial"></font></b></td>
</tr>
<tr>
<td colspan="15" height="15" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Current Project Assignment</font></td>
</tr>
<!-- Records from the database (Current Project Assignment) -->
<?php
$i = 0;
while ($row=mysql_fetch_array($result)){
?>
<tr>
<form name="form1" action="submitAction.php" method="post">
<td height="5" width="20" align="center" style="font-size: 13" valign="middle"><?php echo $counter; ?></td>
<td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="ProjectName_<?php echo $i; ?>" name="ProjectName<?php echo $row['No'];?>" value="<?php echo $row['ProjectName'];?>" size="20" style="font-size: 10"></font></td>
<td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="DeviceType_<?php echo $i; ?>" name="DeviceType<?php echo $row['No'];?>" value="<?php echo $row['DeviceType'];?>" size="15" style="font-size: 10"></font></td>
<td height="5" width="67" style="font-size: 13">
<select name="action" onchange="submitRequest(<?php echo $i; ?>);">
<option value=>Ongoing </option>
<option value="<?php echo $row['ProjectName'];?>">Complete</option>
<option value="<?php echo $row['Flag2'];?>">Future</option>
<option value="<?php echo $row['Flag1'];?>">Cancel</option>
<option value="<?php echo $row['No'];?>">Update</option>
<option value="<?php echo $row['Flag3'];?>">Delete</option>
</select>
</td>
<td height="5" width="64" ><input type="button" style="width:100%" value="Edit" onclick="removeAlignment(<?php echo $i; ?>);"></td>
</tr>
</form>
<?php
?>
<?php
$i++;
$counter++;
}
?>
<tr>
<td colspan="16" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Add New Project Assignment</font></td>
</tr>
<!-- Add New Records -->
<tr>
<form action="project_insert.php" method="post">
<td width="20" ></td>
<td width="78" ><input type="text" autocomplete=off name="ProjectName" size="40" style="font-size: 10"></font></td>
<td width="72" ><input type="text" autocomplete=off name="DeviceType" size="15" style="font-size: 10"></font>
<td width="80" style="font-size: 13">
<select name="Status" style="width:100%">
<option value=Future>Future</option>
<option value=Ongoing>Ongoing</option>
</select>
</td>
<td>
<input type="Submit" style="width:100%"value="Add">
</td>
</form>
</tr>
</table>
<br/>
<table border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
<td valign="middle">update</td>
</tr>
</table>
<br/>
</body>
</html>
You want to pass value in a link to another page ?
Simply use $_GET[] like in this example :
Update all
Make just one form tag for everything - not an individual form tag for each row.
Next change:
<select name="action" onchange="submitRequest(<?php echo $i; ?>);">
To:
<select name="action[<php echo $i; ?>]" onchange="submitRequest(<?php echo $i; ?>);">
(It's better to use the primary key from your database instead of the $i counter, but you don't say what it is.)
Also it has not been necessary to do:
<!-- hide
// end hide -->
For something like 10 years already, so you should stop including that.