I have a quiz which shows 1 question per page. If the user clicks next question without selecting a multiple choice answer, I'm trying to get validation to appear so that they can't advance unless they select an answer. When the user currently presses next question the error: 'Notice: Undefined index: answer' appears
any help?
quiz.php:
if(isset($_POST['checkQuiz'])) {
$a=$_POST['a'];
$quiz_id=$_SESSION['quiz_id'];
$index=$_SESSION['index'];
$resultQuery = mysqli_query($con,"SELECT `correctValue` FROM quiz_questions WHERE quiz_id = '$quiz_id' LIMIT 1 OFFSET $index");
$cor=0;
$incorrect=0;
while ($correct = mysqli_fetch_array($resultQuery)){
if ($_POST['answer'] == $correct[0]) {
$_SESSION['rightAnswers']+=1;
}
if ($_POST['answer'] != $correct[0]) {
$_SESSION['wrongAnswers']+=1;
}
}
}
<form method="post" action="" class="form complete">
<table>
<td>
<td width = "50" id="question"><?php echo $result['question'] . "<br>"; ?></td>
</td>
<tr height = "10"></tr>
<td id= "number" width = "20" class="number"><?php echo $questionNumber ?>)</td>
<td id = "possible_answers" height = "100"width = "700">
<input type="radio" name="answer" onClick="changeColour('a')" value="<?php echo $result['answerA'] ?>"> <?php echo $result['answerA']; ?> <br>
<input type="radio" name="answer" onClick="changeColour('b')" value="<?php echo $result['answerB'] ?>"> <?php echo $result['answerB']; ?> <br>
<input type="radio" name="answer" onClick="changeColour('c')" value="<?php echo $result['answerC'] ?>"> <?php echo $result['answerC']; ?> <br>
<input type="radio" name="answer" onClick="changeColour('d')" value="<?php echo $result['answerD'] ?>"> <?php echo $result['answerD']; ?> <br><br>
</table>
<?php
$_SESSION['questionNumber']=$questionNumber;
}
$a=$a+1;
?>
<input type="submit" name="exitQuiz" value="Exit Quiz" id="button1">
<?php
if ($questionNumber<$_SESSION['numberOfQuestions']) {
?>
<input type="submit" name="checkQuiz" value="Next Question" id="button1">
<input type="hidden" value="<?php echo $a ?>" name="a">
<?php
}
?>
<?php
if ($questionNumber==$_SESSION['numberOfQuestions']) {
?>
<input type="submit" name="checkResult" value="Quiz Result" id="button1">
<input type="hidden" value="<?php echo $a ?>" name="a">
<?php
} ?>
You need to check that $_POST['answer'] is set, like this:
while ($correct = mysqli_fetch_array($resultQuery)){
if (!isset($_POST['answer']) || $_POST['answer'] != $correct[0]) {
$_SESSION['wrongAnswers']+=1;
} elseif ($_POST['answer'] == $correct[0]) {
$_SESSION['rightAnswers']+=1;
}
}
Related
I have a table to display Addon items from database.
The user must check the checkbox for the first two items namely: gps and babyseat.
So the deposit and priceperday are captured inside add_item[] of the checkbox.
But the third item which is Driver, there's no deposit or priceperday but price per hour.
So I gave out two radio buttons namely: one for per8thhour rate and the other one for per16thhour rate.
The problem is it captures both rate but I only want either one value of the radio button to be recorded.
Here's the table:
<table border="1" style="border-collapse: collapse;margin-top: 20px;">
<tr>
<th>AddOns</th>
<th>Deposit</th>
<th>PricePerDay</th>
<th>Price per 8th Hour</th>
<th>Price per 16th Hour</th>
<th></th>
</tr>
<?php
while($row_addon=mysql_fetch_array($result_addon))
{
$add_on_id=$row_addon['addOns_id'];
$add_on=$row_addon['addOns'];
$deposit=$row_addon['Deposit'];
$ppd=$row_addon['PricePerDay'];
$pp8=$row_addon['PricePer8thHour'];
$pp16=$row_addon['PricePer16thHour'];
$status=$row_addon['status'];
?>
<tr>
<td><input type="hidden" name="add_name" value=""><?php echo $add_on;?></td>
<td><input type="hidden" name="add_on"><?php echo $deposit;?></td>
<?php
if(isset($add_on)&&($add_on!=='Driver'))
{
?>
<td><input type="hidden" name="add_on"><?php echo $ppd;?></td>
<td><input type="hidden" name="add_on"><?php echo $pp8;?></td>
<td><input type="hidden" name="add_on"><?php echo $pp16;?></td>
<?php
}
else
{
?>
<td><input type="hidden" name="add_on"><?php echo $ppd;?></td>
<td><input type="radio" name="add_on"><?php echo $pp8;?></td>
<td><input type="radio" name="add_on"><?php echo $pp16;?></td>
<?php
}
?>
<td><input type="checkbox" name="add_item[]" value="<?php echo $add_on_id;?>"/></td>
</tr>
<?php
}
?>
<input type="hidden" name="submit_add">
<tr><td colspan="6"></td></tr>
</table>
I'm recording the value like this:
if(isset($_POST['submit_add']))
{
$add_item=$_POST['add_item'];
echo $add_item_1=implode(',',$add_item);
}
How do I make it possible to catch only the value selected by user for the item driver.
At the same time group them all under one name which is addon so that I can store them as one group in session later?
FULL FORM:
<form action="" method="POST">
<?php
//display pickup location
mysql_select_db($database_bumi_conn, $bumi_conn);
$q="SELECT * FROM tbl_pickup_location WHERE pickup_id='$location'";
$r=mysql_query($q);
$row_show= mysql_fetch_array($r);
?>
<input type="hidden" name="lo" value="<?php echo $location_name=$row_show['pickup_location'];?>">
<?php
echo 'Pickup Location :'.$location_name=$row_show['pickup_location'].'<br/>';
//display dropoff location
mysql_select_db($database_bumi_conn, $bumi_conn);
$q_1="SELECT * FROM tbl_dropoff WHERE dropoff_id='$d_location'";
$r_1=mysql_query($q_1);
$row_show_1= mysql_fetch_array($r_1);
?>
<input type="hidden" name="d_lo" value="<?php echo $location_name_1=$row_show_1['dropoff_location'];?>">
<?php
echo 'Return Location : '.$location_name_1=$row_show_1['dropoff_location'].'<br/>';
?>
<input type="hidden" name="val_1" value="<?php echo $date_value; ?>"/>
<?php
echo 'Pickup date : '.$date_value.'<br/>';
?>
<input type="hidden" name="val_2" value="<?php echo $date_value_2; ?>"/>
<?php
echo 'Return date : '.$date_value_2.'<br/>';
//$days=0;
$days=$diff->format("%a Days");
echo 'Total Rental for : '.$days.'<br/>';
//echo"hdssssssssssssfviodrhfvuhgudfhghdfhijswdjiahsdhsndjfhzsnhio";
$total_days=(int)$days;
?>
<input type="hidden" name="t_days" value="<?php echo $total_days; ?>"/>
<?php
include'calculation.php';
?>
<input type="hidden" name="sum" value="<?php echo $sum;?>">
<?php
mysql_select_db($database_bumi_conn, $bumi_conn);
$q_addon="SELECT * FROM tbl_addons";
$result_addon= mysql_query($q_addon)or die(mysql_error());
echo "<hr width=540>";
?>
<table border="1" style="border-collapse: collapse;margin-top: 20px;">
<tr><th>AddOns</th><th>Deposit</th><th>PricePerDay</th><th>Price per 8th Hour</th><th>Price per 16th Hour</th><th></th></tr>
<?php
while($row_addon=mysql_fetch_array($result_addon))
{
$add_on_id=$row_addon['addOns_id'];
$add_on=$row_addon['addOns'];
$deposit=$row_addon['Deposit'];
$ppd=$row_addon['PricePerDay'];
$pp8=$row_addon['PricePer8thHour'];
$pp16=$row_addon['PricePer16thHour'];
$status=$row_addon['status'];
?>
<tr>
<td><input type="hidden" name="add_name" value=""><?php echo $add_on;?></td>
<td><input type="hidden" name="add_item[]"><?php echo $deposit;?></td>
<td><input type="hidden" name="add_item[]"><?php echo $ppd;?></td>
<td><input type="radio" name="add_item[]" value="eight"><?php echo $pp8;?></td>
<td><input type="radio" name="add_item[]" value="six"><?php echo $pp16;?></td>
<td><input type="checkbox" name="add_item[]" value="<?php echo $add_on_id;?>"/></td>
</tr>
<?php
}
?>
<input type="hidden" name="submit_add">
<tr><td colspan="6"></td></tr>
</table>
<input type="image" src="submit.png" name="submit" value="submit" onclick="return confirm('Do you really want to proceed to checkout?');"href="checkout.php" style="padding-left:20px;" title="Add to cart"/>
</form>
To select one radio button at once, you have to give the all radio button's name same.
Otherwise you have to use javascript/jquery to deselect others when one is selected.
if you give all radio button name same, then when you post it will just post the value of the radio which is selected. You can get it by $_POST['radio_name'] .
Here it is $_POST['add_item'] .
If you are interested to use jquery, you can do that in this way
<script>
$(document).ready(function() {
$('input:radio').click(function(event) {
$('input:radio').not(this).attr('checked', false);
$(this).attr('checked', true);
});
});
</script>
I want to make it so the select boxes user selects stays selected encase validation fails later in my form the rest of the form works perfect but I cant seem to figure how to do this for select boxes without changing all the names can someone please help I have created this which contains just my form checkboxes and the action I will be doing later on so you can see what I require
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="desert_l">
<label for="hnumber"><div class="bookerror"></div>Desert Choice </label>
</div>
<div id="desert_f">
<table width="275">
<tr>
<td width="113">
<label>
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Vanila Cheesecake"))
{
echo ' checked="checked""';
}
?> />
Vanilla Cheesecake</label></td>
<td width="94"><input type="checkbox" name="desgroup[]" value="Carrot Cake"<?php if (isset($dessgroup) && ($dessgroup == "Carrot Cake"))
{
echo ' checked="checked""';
}
?> />
Carrot Cake</td>
<td width="52"><input type="checkbox" name="desgroup[]" value="Jelly"<?php if (isset($dessgroup) && ($dessgroup == "Jelly"))
{
echo ' checked="checked""';
}
?> />
Jelly</td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="desgroup[]" value="Fruit Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Cheesecake"))
{
echo ' checked="checked""';
}
?> >
Fruit Cheesecake</label></td>
<td><input type="checkbox" name="desgroup[]" value="Fruit Flan"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Flan"))
{
echo ' checked="checked""';
}
?> />
Fruit Flan</td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="desgroup[]" value="Fruit Platter"<?php if (isset($dessgroup) && ($dessgroup == "Fruit Platter"))
{
echo ' checked="checked""';
}
?> />
Fruit Platter</label></td>
<td><input type="checkbox" name="desgroup[]" value="Chocolate Cake"<?php if (isset($dessgroup) && ($dessgroup == "Chocolate Cake"))
{
echo ' checked="checked""';
}
?>/>
Chocolate Cake</td>
<td> </td>
</tr>
</table>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
<p><span class="bookerror">
<?php
$dessgroup = $_POST['desgroup'] ;
if (isset ($_POST['submit']))
{
if (isset ($dessgroup))
{
echo "<h2>Desert Choice</h2>";
// Show Deserts Selected
for($i=0; $i < count($dessgroup); $i++)
{
echo $dessgroup[$i]."</br>";
}}
else
{
echo "You Must Select At Least 1 Desert" ;
}
}
?>
</span></p>
<p>Please Choose The Number Specified In Your Menu Choice<br />
</p>
</div>
</form>
Instead of
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($dessgroup) && ($dessgroup == "Vanila Cheesecake"))
{
echo ' checked="checked""';
}
?> />
try
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake"<?php if (isset($_POST['desgroup']) && is_array($_POST['desgroup']) && in_array("Vanila Cheesecake", $_POST['desgroup']))
{
echo ' checked="checked""';
}
?> />
It would save you a lot of typing though if you would use arrays consequently.
$arr = array('possible value 1', 'possible value 2');
foreach ($arr as $val) {
?>
<input type="checkbox" name="desgroup[]" value="<?php echo $val; ?>"<?php if (isset($_POST['desgroup']) && is_array($_POST['desgroup']) && in_array($val, $_POST['desgroup']))
{
echo ' checked="checked""';
}
?> />
<?php
}
Try this
<input type="checkbox" name="desgroup[]" value="Vanila Cheesecake" <?php echo ((isset($dessgroup) && ($dessgroup == "Vanila Cheesecake")))?'checked="checked"':''; ?> />
## Keep Radio Button Value after Next/Prev page .. ##
This is for Student Online Exam
if(!isset($_GET['start'])){
$_GET['start'] = "undefined";
}
$start=$_GET['start']; /*To take care global variable if OFF*/
if(!($start > 0)) { /*This variable is set to zero for the first page*/
$start = 0;
}
$startpos = ($start -0);
$limit = 1;
// No of records to be shown per page.
$currentpos = $startpos + $limit;
$back = $startpos - $limit;
$next = $startpos + $limit;
$countquery=" SELECT * FROM quiz ";
$countresult=mysql_query($countquery);
echo mysql_error();
$totalrecords=mysql_num_rows($countresult);
//$quiz_table = mysql_query("select * from quiz Limit 1");
?>
<form method="POST" action="" onclick="">
<table>
<?php
$quiz_table=" SELECT * FROM quiz ORDER BY qid limit $startpos, $limit ";
$result=mysql_query($quiz_table);
echo mysql_error();
while ($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo "$row[qid]"; ?></td>
<td><?php echo "$row[Question]"; ?></td>
</tr>
<tr>
<td><input type="radio" name="a" id="a" value="a"/> <?php echo "$row[opt1]"; ?></td>
<td><input type="radio" name="a" id="a" value="b"/> <?php echo "$row[opt2]"; ?></td>
<td><input type="radio" name="a" id="a" value="c"/> <?php echo "$row[opt3]"; ?></td>
<td><input type="radio" name="a" id="a" value="d"/> <?php echo "$row[opt4]"; ?></td>
</tr>
<tr>
<td><!--<input type="submit" name="smt" value="check"/>-->
<?php
if($back >=0) {
print "<a href='onlineexam.php?start=$back'><font face='Verdana' size='2'><input type='button' name='prev' value='PREV'></font></a>";
}
if($currentpos < $totalrecords) {
## Keep Radio Button Value after Next/Prev page .. ##
print "<a href='onlineexam.php?start=$next'><font face='Verdana' size='2'><input type='button' name='nxt' value='NEXT'></font></a>";
}
?></td>
<td><input type="submit" name="smt" value="Finish"/></td>
</tr>
<?php
}
$quiz_table="SELECT * from quiz";
$result=mysql_query($quiz_table);
while ($row = mysql_fetch_array($result))
{
$id=$row['qid'];
$ques=$row['Question'];
$op1=$row['opt1'];
$op2=$row['opt2'];
$op3=$row['opt3'];
$op4=$row['opt4'];
$crt=$row['woptcode'];
if(isset($_POST['smt'])){
$ans= $_POST['a'];
if(isset($_POST['a'])){
if($crt == $ans ){
$mark=0;
$mark=$mark+1;
mysql_query("INSERT INTO stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");
} else{
$mark=0;
mysql_query("INSERT INTO stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");
}
}
}
}
..THANKS..
You can use the checked attribute.
<input type="radio" checked>
So if you had some variables (booleans), $opt1, $opt2, $opt3, $opt4, then you could do something similar to this:
<input type="radio" name="opt1" <?php if ($opt1) echo "checked"; ?> />
<input type="radio" name="opt2" <?php if ($opt2) echo "checked"; ?> />
<input type="radio" name="opt3" <?php if ($opt3) echo "checked"; ?> />
<input type="radio" name="opt4" <?php if ($opt4) echo "checked"; ?> />
I have a MYSQL table with edit link and delete button on each row. The edit link goes to edit_movie.php which has a form. My problem is that the form is not showing any data to be updated/edited. How do I fetch the id from the row clicked on or what function to write to pick it up. The form is just blank, no fields are filled out.
Could someone help out I´d be very happy! Been sitting with this problem for 3 days now and just can´t get it to work. I'm a PHP beginner...
I know I'm using mysql functions which are outdated and I need to lookover SQL injection which I will once I get this working.
Table info:
Table 1 name: Movies
Fields: id (primary key, AI), title, release_year, genre_id, director
Table 2 name: Categories
Fields: genre_id (primary key, AI), genre
They have a foreign relation between genre_id.
Here is the code in index.php file
<?php
require('movie.inc.php');
if ( isset($_GET['delete']) && isset($_GET['id']) ){
if ( delete_movie_by_id($_GET['id']) ){ //it's 100% safe
die('Movie has been removed. Refresh the page now'); // or the like
} else {
echo 'Sorry movie could not be deleted'; // could not - handle here
}
}
include 'add_movie.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>My movie library</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="mall.css" />
</head>
<body>
<table>
<tr>
<th>Title</th>
<th>Release year</th>
<th>Genre</th><th>Director</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php foreach (get_all_movies() as $index => $row) : ?>
<tr>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['release_year']; ?></td>
<td><?php echo $row['genre'];?></td>
<td><?php echo $row['director'];?></td>
<td><a href='<?php printf('edit_movie.php?edit=%s', $row['id']);?>'>Edit</a></td>
<td>
<form action="index.php" method="GET">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="<?php echo $row['id'];?>" />
<input type="submit" value="Delete" />
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
Here is the edit_movie.php code:
<?php
require 'connect.inc.php';
require_once('movie.inc.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>My movie library</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="mall.css" />
</head>
<body>
<h1>Edit movie</h1>
<div id="form_column">
<form action="edit_movie.php" method="post">
<input type="hidden" name="id" value="<?php if (isset($row["id"])) ?>" /> <br>
Title:<br> <input type="text" name="title" value="<?php if (isset($row["title"])) { echo $row["title"];} ?>" /> <br>
Release Year:<br> <input type="text" name="release_year" value="<?php if (isset($row["release_year"])) { echo $row["release_year"];} ?>" /> <br>
Director:<br> <input type="text" name="director" value="<?php if (isset($row["director"])) { echo $row["director"];} ?>" /> <br><br>
Select genre:
<br>
<br> <input type="radio" name="genre_id" value="1" checked />Action<br>
<br> <input type="radio" name="genre_id" value="2" />Comedy<br>
<br> <input type="radio" name="genre_id" value="3" />Drama<br>
<br> <input type="radio" name="genre_id" value="4" />Horror<br>
<br> <input type="radio" name="genre_id" value="5" />Romance<br>
<br> <input type="radio" name="genre_id" value="6" />Thriller<br><br>
<input type="submit" value="Update movie" />
</form>
</div>
</body>
</html>
And here is the movie.inc.php file
<?php
require_once('connect.inc.php');
function get_all_movies(){
$query = "SELECT * FROM movies m INNER JOIN categories c ON m.genre_id = c.genre_id";
$result = mysql_query($query);
if ( ! $result ){
return false;
} else {
$return = array();
while ($row = mysql_fetch_assoc($result)){
$return[] = array('director' => $row['director'], 'genre' => $row['genre'], 'release_year' => $row['release_year'], 'title' => $row['title'], 'id' => $row['id']);
}
return $return;
}
}
function delete_movie_by_id($id){
return mysql_unbuffered_query(sprintf("DELETE FROM `movies` WHERE id='%s' LIMIT 1", mysql_real_escape_string($id)));
}
if ( isset($_POST['delete'], $_POST['id']) ){
delete_movie_by_id($_POST['id']);
}
?>
In edit_movie.php it doesn't look like you're actually getting the movie passed view the form. You need something like this in your movie.inc.php:
function get_movie_to_edit($id) {
$query = "SELECT * FROM movies m INNER JOIN categories c ON m.genre_id = c.genre_id WHERE id = $id";
$result = mysql_query($query);
if ( ! $result ){
return false;
} else {
while ($row = mysql_fetch_assoc($result)){
$return = array('director' => $row['director'], 'genre' => $row['genre'], 'release_year' => $row['release_year'], 'title' => $row['title'], 'id' => $row['id']);
}
return $return;
}
}
And then in edit_movie.php you need to call this function. Something like...
if(isset($_GET['edit'])) {
$movie = get_movie_to_edit($_GET['edit']);
}
Of course, as you mentioned, you need to clean up a lot of the code to prevent against injection and check for a scenario where, say, you get to edit_movie.php and the ID ro edit doesn't exist, but this is the basic gist.
You would also then edit the values in the form in edit_movie.php to reflect the new array like:
<form action="edit_movie.php" method="post">
<input type="hidden" name="id" value="<?php echo $movie['id']; ?>" /> <br>
Title:<br> <input type="text" name="title" value="<?php echo $movie['title']; ?>" /> <br>
.... the rest of your form inputs
</form>
Updated
For the genre radio buttons...
<input type="radio" name="genre_id" value="1"<?php if($movie['genre'] == 1) { echo ' checked'; } ?> />Action<br>
<input type="radio" name="genre_id" value="2"<?php if($movie['genre'] == 2) { echo ' checked'; } ?> />Comedy<br>
.... and so on
Im getting crazy with this problem.
I try to use ajax to send data from a form in a way that I have not to reload all webpage (my webpage contain some queries for generate index menu that produce traffic); I create sendForm method, which handle form datas and pass it to php page to process.
This is the js code:
function sendForm(){
var http = false;
http = new XMLHttpRequest();
var ser = $(":input").serialize();
http.open("POST", "http://localhost/redir.php" ,true);
http.onreadystatechange= handleResponse();
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", ser.length);
http.setRequestHeader("Connection", "close");
http.send(ser);
return true;
}
My form data contain a variable numbers of inputs because there's some php code inside a for cycle.
<form name="form" id="form" class="table table-hover" method="post">
<?php while(.....)) { ?>
<tr style="line-height:40px">
<td><?php echo $home;?></td>
<td><?php echo $vis;?></td>
<td><input type="text" name="goal_h[]" class="input-mini"
<?php if ($sq[16] == "2"){ ?>
readonly value="<?php echo $goal_h;?>"
<?php }else if ($sq[16] == "3"){
?> readonly value="-"
<?php } else echo "value=\"-\"";
?> id="goal_h<?php echo $i?>[]" maxlength="2" size="2" />
<input type="hidden" name="id_sub" value="<?php echo $id_sub;?>" />
<input type="hidden" name="id" id="id" value="<?php echo $id_d;?>" />
<input type="hidden" name="data_gg" value="<?php echo $data_gg;?>" />
<input type="hidden" name="n_gg" value="<?php echo $n_gg;?>" />
<input type="hidden" name="id_p_home[]" id="idphome<?php echo $i?>" value="<?php echo $tmp_id_p;?>" />
<input type="hidden" name="id_p_vis[]" id="idpvis<?php echo $i?>" value="<?php echo $sq[10];?>" />
</td>
<td>
<input type="text" name="goal_v[]" class="input-mini" <?php if ($sq[16] == "2"){ ?> readonly value="<?php echo $goal_v;?>" <?php }else if ($sq[16] == "3"){ ?> readonly value="-" <?php } else echo "value=\"-\""; ?> id="goal_v<?php echo $i?>[]" maxlength="2" </td>
<td><input type="checkbox" <?php if ($sq[16] == "2"){ ?> checked <?php } ?> id="sosp<?PHP echo $i?>" name="sosp[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/></td>
<td><input type="checkbox" <?php if ($sq[16] == "3"){ ?> checked <?php } ?> id="nd<?PHP echo $i?>" name="nd[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/>
</td>
</tr>
<tr style="line-height:40px">
<td><input type="submit" id="submit" name="submit" value="AGGIORNA IL PUNTEGGIO" onclick="sendForm()" /></td>
<td colspan="5"></td>
</tr>
<?php } ?>
</form>
this code works if I don't use with ajax and simply use an action=name_of_file.php, but when I try to use sendForm() method, in redir.php file I lose $_POST variables.
$home_id_p=$_POST['id_p_home'];
$vis_id_p=$_POST['id_p_vis'];
$goal_home=$_POST['goal_h'];
$goal_vis= $_POST['goal_v'];
$sosp= (isset($_POST['sosp'])) ? $_POST['sosp'] : "99";
$nd= (isset($_POST['nd'])) ? $_POST['nd'] : "99";
and then I need to loop on $home_id_p.
I tried also wihout serialize(), and also with serializeArray() :
var ser = $(":input").serializeArray();
but with this I'm not able to send it, because I get an error "invalid argument" in
http.send(ser)
Any idea?
Thanks