I can submit a form without echoing that form. But how can the form be submitted after 5 minutes with the form being echoed?
Here is my code:
echo "<form name=myfm id=myfm1 method=post action=ats_exam.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ". $n .": $row[2]</style>";
echo "<tr><td class=style6><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style6> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style6><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style6><input type=radio name=ans value=4>$row[6]";
if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit1 value='Next Question'> </form>";
echo "<tr><td><input type=submit name=submit value='Get Result'>
</form>";
echo "</table></table>";`
Do the following:
echo "<form name=myfm id=myfm1 method=post action=ats_exam.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ". $n .": $row[2]</style>";
echo "<tr><td class=style6><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style6> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style6><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style6><input type=radio name=ans value=4>$row[6]";
if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit1 value='Next Question'> </form>";
echo "<tr><td><input type=submit name=submit value='Get Result'>
</form>";
echo "</table></table>";`
echo "<script>setInterval(function(){ myform.submit(); }, 3000);</script>";
Please check a simple example of how I achieved it here: https://jsfiddle.net/redmutex/4kgde4o4/
You can use jquery/ajax .get function for this.
$.get( "insertdata.php", { page: "add", username: "username" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});
Related
The label tag has the right syntax however the form structure is not aligned well the way I want it.I also put id as well
echo "<form action='getregister.php' method='post'>";
echo "<fieldset >";
echo "<legend>Register</legend>";
echo "<input type='hidden' name='submitted' id='submitted' value='1'/>";
echo "<label for='First_name'>First Name: </label>";
echo "<input type='text' name='U_fname' id='First_name' value=''><br>";
echo "<label for='Last_name'>Last Name: </label>";
echo "<input type='text' name='U_sname' id='Last_name' value=''><br>";
echo "<label for='Address' >Address: </label>";
echo "<input type='text' name='U_address' id='Address' value=''><br>";
echo "<label for='Postcode' >Postcode: </label>";
echo "<input type='text' name='U_postcode' id='Postcode' value=''><br>";
echo "<label for='Telno' >Tel No: </label>";
echo "<input type='text' name='U_telNo' id='Telno' value=''><br>";
echo "<label for='Email' >Email Address: </label>";
echo "<input type='email' name='U_email' id='Email' value=''><br>";
echo "<label for='password' >Password:</label>";
echo "<input type='password' name='U_password' id='password' value=''><br>";
echo "<label for='passwords' >Confirm Password:</label>";
echo "<input type='password' name='U_confirmPassword' id='passwords' value=''><br>";
echo "<input type='submit' name='Submit' value='Register' />";
echo "<button type='reset' value='Reset'>Clear form</button>";
echo "</fieldset>";
echo "</form>";
Try like this:
echo "<form action='getregister.php' method='post'>";
echo "<fieldset >";
echo "<legend>Register</legend>";
echo "<input type='hidden' name='submitted' id='submitted' value='1'/>";
echo "<table>";
echo "<tr>";
echo "<td><label for='First_name' >First Name: </label></td>";
echo "<td><input type='text' name='U_fname' value=''></td>";
echo "</tr>";
echo "<tr>";
echo "<td><label for='Last_name'>Last Name: </label></td>";
echo "<td><input type='text' name='U_sname' id='Last_name' value=''>";
echo "</tr>";
echo "<table>";
echo "</fieldset>";
echo "</form>";
guyz, i want to select radio button for each question.please help me to do that.now i can select only one radio button in a page...... check this link: http://i.stack.imgur.com/UI2vp.png
while($row= mysql_fetch_row($rs)){
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques[$n][]' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques[$n][]' value=4>$row[6]";
}
How to fetch the data and store it to mydb...
$query="select * from question";
$rs=mysql_query("select * from question where testid=$tid",$cn) or die(mysql_error());
if($submit=='Get Result')
{
$n=0;
while($row= mysql_fetch_row($rs)){
for($i=0;$i<count($_POST['ques']);$i++)
{
$ans=$_POST['ques'][$n][$i];
echo $ans;
$n=$n+1;
mysql_query("insert into useranswer(sessid, testid, ques, ans1,ans2,ans3,ans4,correctans,yourans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());}
}
}
is this works???....
Just replace ques[] with ques[". $n ."][] like this..
while($row= mysql_fetch_row($rs)){
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques[".$n."][]' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques[". $n ."][]' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques[". $n ."][]' value=4>$row[6]";
}
You have to name your radiobuttons for each set.
while($row=mysql_fetch_row($rs)) {
echo "<form name=myfm method=post action=Quiz.php>";
echo "<table width=100%> <tr> <td width=30> <td> <table border=0>";
$n=$n+1;
echo "<tr><td><span class=style2>Question ". $n .": $row[2]</style>";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=1>$row[3]";
echo "<tr><td class=style8> <input type=radio name='ques".$n."' value=2>$row[4]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=3>$row[5]";
echo "<tr><td class=style8><input type=radio name='ques".$n."' value=4>$row[6]";
echo "</table></table></form>"; //AND you should close your tags
}
Also, you should refrain from using mysql_functions, which are deprecated and removed in PHP7.
The mistake is that you are naming all your radio buttons with the same name. That makes all of them in one group. Name each group with three different names. Your problem is solved
So I've been trying for days to figure out how I can update each row separately and i can't figure it out. this is the first time I've used php so sorry for the ugly code.
I can seem to pull the information from each row but the update wont work, however it sends all the data from all the rows in the address bar
<html>
<head>
<title>EDIT Patient data</title>
</head>
<body>
<br>
Edit Patients<br>
Patient Request<br>
Booked Patients
<?php
include 'connect.php';
$sql = "SELECT * FROM patients;";
$result = mysql_query($sql);
$num_of_row = mysql_num_rows($result);
if (isset($_GET['submit'])) {
$id = $_GET['did'];
$fname = $_GET['dfname'];
$lname = $_GET['dlname'];
$email = $_GET['demail'];
$phone = $_GET['dphone'];
$address = $_GET['daddress'];
$query = mysql_query("update patients set fName='$fname', lName='$lname', email='email', phone='$phone', address='$address' where patientID ='$id'");
}
echo "<table border=1>";
echo " <tr> <td> Patient ID </td> ";
echo "<td> First name </td>";
echo "<td> last name </td>";
echo "<td> email </td>";
echo "<td> phone number</td>";
echo "<td> address </td>";
echo "<td> date of birth </td> ";
echo "<td> update </td></tr>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr> <form class='form' method='get'>";
echo "<td> <input type='text' name='did' value='".$row['patientID']."' readonly /></td>";
echo "<td> <input type='text' name='dfname' value ='".$row['fName']."' /></td>";
echo "<td> <input type='text' name='dlname' value = '".$row['lName']."' /></td>";
echo "<td> <input type='text' name='demail' value = '".$row['email']."' /></td>";
echo "<td> <input type='text' name='dphone' value ='".$row['phone']."' /></td>";
echo "<td> <input type='text' name='daddress' value ='".$row['address']."' /></td>";
echo "<td> <input type='text' name='ddob' value ='".$row['dob']."' readonly /></td>";
echo "<td> <input class='submit' type='submit' name='submit' value='update' /> </td> </tr>";
}
?>
</body>
</html>
Does your user have update permissions?
If not you need to use GRANT UPDATE ON *.* TO 'User'#'Host';
But you should use MySQLi as MySQL is deprecated. You should also look into Parameterized Queries and MySQL injection, It's worth knowing about!
If you want to update an individual row, you'll have to put a <form> around your while-loop, like this:
echo "<form action='' method='GET'>";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr> <form class='form' method='get'>";
echo "<td> <input type='text' name='did' value='".$row['patientID']."' readonly /></td>";
echo "<td> <input type='text' name='dfname' value ='".$row['fName']."' /></td>";
echo "<td> <input type='text' name='dlname' value = '".$row['lName']."' /></td>";
echo "<td> <input type='text' name='demail' value = '".$row['email']."' /></td>";
echo "<td> <input type='text' name='dphone' value = '".$row['phone']."' /></td>";
echo "<td> <input type='text' name='daddress' value ='".$row['address']."' /></td>";
echo "<td> <input type='text' name='ddob' value ='".$row['dob']."' readonly /></td>";
echo "<td> <input class='submit' type='submit' name='submit' value='update' /> </td> </tr>";
}
echo "</form>";
The form will allow input fields to be submit according to the form's method (GET and POST).
Hi I have this and works fine except the following issue.
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1' value=".$_SESSION['txt1'].">";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
<A submit button here to send the form data>
The issue is if I have a value in the text box like John when I submit the form I retain the original user typed word Jonn in the text box. However if the user type John Carter, when the form is submitted it retains only John. In other words texts only up to first space between the texts. How do I retain entire text?
EDIT
<?php
if(isset($_POST['sendone']))
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
}
if(isset($_POST['sendtwo']))
{
if($_POST['txt1']=='')
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Empty";
}
else
{
$_SESSION['txt1'] = $_POST['txt1'];
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1' value=".$_SESSION['txt1'].">";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Hit success!";
}
}
?>
You need to include the single quotes around the value for the value= attribue when echoing the _SESSION["txt1"], otherwise the resulting HTML isn't valid .. like this:
<?php
if(isset($_POST['sendone']))
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
}
if(isset($_POST['sendtwo']))
{
if($_POST['txt1']=='')
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Empty";
}
else
{
$_SESSION['txt1'] = $_POST['txt1'];
echo "Hello";
echo "<form method='post' action=''>";
// check out this line here:
echo " <input type='text' name='txt1' id='txt1' value='" . htmlspecialchars($_SESSION['txt1']) . "'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Hit success!";
}
}
?>
Though, it's worth nothing that it is much more performant (and readable!) to use plain HTML where possible, and just use echo for the variables you wish to include.
Check this code.
<form name="" method="post">
<input type="text" name="txt1">
<input type="submit" name="sendtwo">
<input type="submit" name="sendone">
</form>
<?php
if(isset($_POST['sendone']))
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
}
if(isset($_POST['sendtwo']))
{
if($_POST['txt1']=='')
{
echo "Hello";
echo "<form method='post' action=''>";
echo " <input type='text' name='txt1' id='txt1'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Empty";
}
else
{
$_SESSION['txt1'] = $_POST['txt1'];
echo "Hello";
echo "<form method='post' action=''>";
// check out this line here:
echo " <input type='text' name='txt1' id='txt1' value='" . $_SESSION['txt1'] . "'>";
echo " <input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'>";
echo "</form>";
echo "Hit success!";
}
}
?>
This is my code to display list of questions and 4 options( using option box). user has to select the correct option . Is it possible to store the user selected options in array variable. There may be 10 to 20 questions array variable should contain only option values.
<?php
require('connect.php');
$display=mysql_query("SELECT * FROM Java_Test_1 ORDER BY id ASC");
echo "<form method=post action=$PHP_SELF>";
echo "<table border=0>";
while ($row = mysql_fetch_array($display))
{
$id=$row['0'];
$question=$row['1'];
$opta=$row['2'];
$optb=$row['3'];
$optc=$row['4'];
$optd=$row['5'];
$answer = $row["woptcode"];
echo "<tr><td colspan=3><br><b>$question</b></td></tr>";
echo "<tr><td>$opta<input type=radio name=$id value='a'></input></td><td>$optb <input type=radio name=$id value='b'></input></td><td>$optc <input type=radio name=$id value='c'> </input></td><td>$optd <input type=radio name=$id value='d'></input></td></tr>";
}
echo "</table>";
echo "<input type='submit' value='start' name='doo'>";
echo "</form>";
}
$name = 'opt';
$counter = 0;
while ($row = mysql_fetch_array($display))
{
$name = 'opt'.$counter;
$counter++;
$id=$row['0'];
$question=$row['1'];
$opta=$row['2'];
$optb=$row['3'];
$optc=$row['4'];
$optd=$row['5'];
$answer = $row["woptcode"];
echo "<tr><td colspan=3><br><b>$question</b></td></tr>";
echo "<tr><td>$opta<input type=radio name=$name value='a'></td>
<td>$optb <input type=radio name=$name value='b'></td>
<td>$optc <input type=radio name=$name value='c'></td>
<td>$optd <input type=radio name=$name value='d'></td>
</tr>";
}
Here is the official documentation that expains this in detail
http://php.net/manual/en/faq.html.php
Section: How do I create arrays in a HTML ?