I am doing a online test I fetch question and option from database....
I need to select which option they choosed and question id....to the next page for the answered question or not.....I got only they selected option I need get all value....
my php code as follows
<tr>
<td height="30"><?= $id?></td>
<td height="30" colspan="2"><?= $question ?></td>
</tr>
<?php
if($option1!='') { ?>
<tr>
<td height="30"><input type="radio" name="answer[<? echo $id?>]" value="<?php echo $id?>-<?php echo $option1?>" /></td>
<td height="30" colspan="2"><?= $option1?></td>
</tr>
<?php }?>
<?php if($option2!='') {?>
<tr>
<td height="30"><input type="radio" name="answer[<? echo $id?>]" value="<?php echo $id?>-<?php echo $option2?>" /></td>
<td height="30" colspan="2"><?= $option2?></td>
</tr><?php }?>
<?php if($option3!='') {?>
<tr>
<td height="30"><input type="radio" name="answer[<? echo $id?>]" value="<?php echo $id?>-<?php echo $option3?>" /></td>
<td height="30" colspan="2"><?= $option3?></td>
</tr><?php }?>
<?php if($option4!='') {?>
<tr>
<td height="30"><input type="radio" name="answer[<? echo $id?>]" value="<?php echo $id?>-<?php echo $option4?>" /></td>
<td height="30" colspan="2" ><?= $option4?></td>
</tr>
<? }
$id will have the same value for all your options.
So you might want to put name="answer" instead:
<input type="radio" name="answer" value="<?php echo $id?>-<?php echo $option2?>" />
On your result page $_GET['answer'] should then have the correct value.
You could send all the answers as hidden elements:
<input type="hidden" name="allanswers[]" value="Answer 1" />
<input type="hidden" name="allanswers[]" value="Answer 2" />
<input type="hidden" name="allanswers[]" value="Answer 3" />
<input type="hidden" name="allanswers[]" value="Answer 4" />
Related
I want to update multiple records of type radio (field "status"). Below is the codes. But as you can see the result here:
http://lamoncheri.com/admin/dapur.php?id=21
It only recognize the status of one record.
<?php
$i = 1;
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"> <input name="nama_menu[]" type="text" id="nama_menu" value="<?php echo $rows['nama_menu']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td align="center"> <input name="qty[]" type="int" id="qty" value="<?php echo $rows['qty']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td> <input type="radio" name="status[]" id='status' value="order" <?php if ($rows['status'] == "order"){echo "checked";} ?> class ="auto-style5" required>Order<br>
<input type="radio" name="status[]" id='status' value="process" <?php if ($rows['status'] == "process"){echo "checked";} ?> class ="auto-style5" required>Process<br>
<input type="radio" name="status[]" id='status' value="finish" <?php if ($rows['status'] == "finish"){echo "checked";} ?> class ="auto-style5" required> Finish<br>
</td>
<td style="align:center; color:white"><input name="id[]" type="text" id="id" value="<?php echo $rows['id']; ?>" readonly style="border:0; color:white; width: 10px"> </td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<?php
$i++;
}
?>
name put some thing like this
<?php
$i = 1;
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"> <input name="nama_menu<?php echo $i; ?>[]" type="text" id="nama_menu" value="<?php echo $rows['nama_menu']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td align="center"> <input name="qty<?php echo $i; ?>[]" type="int" id="qty" value="<?php echo $rows['qty']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td> <input type="radio" name="status<?php echo $i; ?>[]" id='status' value="order" <?php if ($rows['status'] == "order"){echo "checked";} ?> class ="auto-style5" required>Order<br>
<input type="radio" name="status<?php echo $i; ?>[]" id='status' value="process" <?php if ($rows['status'] == "process"){echo "checked";} ?> class ="auto-style5" required>Process<br>
<input type="radio" name="status<?php echo $i; ?>[]" id='status' value="finish" <?php if ($rows['status'] == "finish"){echo "checked";} ?> class ="auto-style5" required> Finish<br>
</td>
<td style="align:center; color:white"><input name="id<?php echo $i; ?>[]" type="text" id="id" value="<?php echo $rows['id']; ?>" readonly style="border:0; color:white; width: 10px"> </td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<?php
$i++;
}
?>
I am loading a php page into a spefific div, using this code
function peopleEdit(id, currid) {
$("#people_edit").load( "people_edit.php?id="+currid );
return false;
}
There are 2 issues though.
the form displayed, has the option values out of the select box, and the option is not working.
the tinymce box is displayed but the data are out of the box.
the form is tested and is working properly before the ajax .load
here's the html of the form.
<form action="people.php" enctype="multipart/form-data" name="pelatesForm" id="pelatesForm" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Τύπος</td>
<td width="80%"><label>
<select name="pelates_type_det" id="pelates_type_det" />
<option value="<?php echo $pelates_det_type ?>"><?php echo $pelates_det_type ?></option>
<option value="Πελάτης">Πελάτης</option>
<option value="Προμηθευτής">Προμηθευτής</option>
</select>
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα</td>
<td width="80%"><label>
<input name="pelates_first_name_det" type="text" id="pelates_first_name_det" size="64" value="<?php echo $pelates_det_first_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Επίθετο</td>
<td width="80%"><label>
<input name="pelates_last_name" type="text" id="pelates_last_name" size="64" value="<?php echo $pelates_det_last_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Σταθερό</td>
<td width="80%"><label>
<input name="pelates_phone" type="text" id="pelates_phone" size="64" value="<?php echo $pelates_det_phone ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Κινητό</td>
<td width="80%"><label>
<input name="pelates_cell" type="text" id="pelates_cell" size="64" value="<?php echo $pelates_det_cell ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Email</td>
<td width="80%"><label>
<input name="pelates_email" type="text" id="pelates_email" size="64" value="<?php echo $pelates_det_email ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα εταιρείας - Ιδιώτης</td>
<td width="80%"><label>
<input name="pelates_company" id="pelates_company" size="64" value="<?php echo $pelates_det_company ?>" />
</label>
</td>
</tr>
<tr>
<td width="20%" align="right">ΑΦΜ</td>
<td width="80%"><label>
<input name="pelates_afm" type="text" id="pelates_afm" size="64" value="<?php echo $pelates_det_afm ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">ΔΟΥ</td>
<td width="80%"><label>
<input name="pelates_doy" type="text" id="pelates_doy" size="64" value="<?php echo $pelates_det_doy ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Διεύθυνση</td>
<td width="80%"><label>
<input name="pelates_address" type="text" id="pelates_address" size="64" value="<?php echo $pelates_det_address ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Ταχυδρομικός κώδικας</td>
<td width="80%"><label>
<input name="pelates_tk" type="text" id="pelates_tk" size="64" value="<?php echo $pelates_det_tk ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Περιοχή</td>
<td width="80%"><label>
<input name="pelates_area" type="text" id="pelates_area" size="64" value="<?php echo $pelates_det_area ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Σχόλια</td>
<td width="80%">
<textarea name="pelates_comments_det" type="text" class="tinymce" id="pelates_comments_det" size="64" /><?php echo $pelates_det_comments ?></textarea>
</td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="submitpel" id="submitpel" value="Υποβολή" />
<input type="button" value="Άκυρο" onclick="return epistrofi('people_detailed','<?php echo $targetID ?>');" />
</label>
</td>
</tr>
</table>
</form>
any ideas of why is this happening?
You close your select :
<select name="pelates_type_det" id="pelates_type_det" />
Change to:
<select name="pelates_type_det" id="pelates_type_det">
I have use code as shown below:
<?
$sql = mysql_query("select * from tbl_item where item_category = '$item_cat'");
$i=1;
while($crows = mysql_fetch_array($sql))
{
;
?>
<tr>
<td width="57" align="center" ><? echo $i;?></td>
<td width="540" align="center" onClick=><div align="center"><? echo $crows["item_name"];?> </div></td>
<td width="385" align="center">
1<input name="<? echo $crows["item_name"];?>" type="radio" id="radioqty<? echo $i;?>" value="1" checked="checked" />
2<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="2" />
3<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="3" />
4<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="4" />
</td>
<td width="249" align="center" >
Full<input name="radioplate<? echo $i?>" type="radio" id="radioplate<? echo $i?>" value="full" checked="checked" />
Half<input type="radio" name="radioplate<? echo $i?>" id="radioplate<? echo $i?>" value="half" /></td>
<td width="281" align="center">
<input name="serve" type="button" value="Serve" onclick="get_code('a','get_item_save.php?item_id='+<? echo $crows["item_id"];?>+'&cat_id='+document.exB.item_category.value+'&plate_type='+document.exB.radioplate<? echo $i?>.value+'&qty='+exB.radioqty<? echo $i;?>.value+'&bill_no='+document.exB.bill_summary_bill_no.value+'&bill_date='+document.exB.bill_summary_date.value),get_code('b','get_item_sale_list.php?bill_no='+document.exB.bill_summary_bill_no.value)"/> </td>
</tr>
<? $i++; }?>
Here I'm doing something wrong when I call get_code function and I'm unable to figure out were I'm wrong. Could someone figure out what I'm doing wrong on this line of code:
<td width="281" align="center">
<input name="serve" type="button" value="Serve" onclick="get_code('a','get_item_save.php?item_id='+<? echo $crows["item_id"];?>+'&cat_id='+document.exB.item_category.value+'&plate_type='+document.exB.radioplate<? echo $i?>.value+'&qty='+exB.radioqty<? echo $i;?>.value+'&bill_no='+document.exB.bill_summary_bill_no.value+'&bill_date='+document.exB.bill_summary_date.value),get_code('b','get_item_sale_list.php?bill_no='+document.exB.bill_summary_bill_no.value)"/> </td>
I get an error at: document.exB.radioplate<? echo $i?>.value show undefined.
Maybe with mysql_fetch_array($sql, MYSQL_ASSOC) in the while statement.
With the MYSQL_ASSOC you can retrieve the fields by its name, like crows['item_name'].
I don't know why but my table cuts off right after the second <td> tag... can anyone help, I have constantly looked over it over and over. Can someone help me find where the problem is?
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("newpass")); ?>
</td>
</tr>
Btw, that code is only the first two rows.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<form action="adminprocess.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?php
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?php
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("newpass")); ?>
</td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input name="conf_newpass" type="password" value='
<?php echo $form->value("newpass"); ?>' size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
</tr>
<td>Edit motto:</td>
<td><input type="text" size="56" name="motto" value='<?php
if($form->value("motto") == ""){
echo $req_user_info['motto'];
}else{
echo $form->value("motto");
}
?>'></td>
<tr>
<tr>
<td>Edit profile bio:</td>
<td><textarea cols="40" rows="10" name="profile" value=""><?php
if($form->value("profile") == ""){
echo $req_user_info['profile'];
}else{
echo $form->value("profile");
}
?></textarea></td>
<tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" value='
<?php
if($form->value("email") == ""){
echo $req_user_info["email"];
}else{
echo $form->value("email");
}
?>' size="56" maxlength="50">
</td>
<td><?php echo $form->error("email"); ?></td>
</tr>
<tr>
<td>User level:</td>
<td><input name="userlevel" type="text" value='
<?php
if($form->value("userlevel") == ""){
echo $req_user_info["userlevel"];
}else{
echo $form->value("userlevel");
}
?>' size="4" maxlength="10"></td>
<td><?php echo $form->error("userlevel"); ?></td>
</tr>
<tr><td align="right">
<input type="hidden" name="subedit" value="1">
<input type="hidden" name="usertoedit" value="<?php echo $usertoedit; ?>">
<input type="submit" name="button" value="Edit Account">
</td>
<td colspan="2" style="text-align:right;">
<input type="submit" name="button" value="Delete" onclick="return confirm ('Are you sure you want to delete this user, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')">
</td>
</tr>
</table>
</form>
I've changed your syntax a little..
<tr>
<td>Username:</td>
<td><input name="username" type="text" value="<?php echo htmlspecialchars(($form->value("username")=="" ? $req_user_info["username"] : $form->value("username"))); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("username"); ?></td>
</tr>
<tr>
<td>New Password:</td>
<td><input name="newpass" type="password" value="<?php echo htmlspecialchars($form->value("newpass")); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
For additional php error logging, put this at the top of the page:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
I want to change data in a sql table by using checkbox. I have successfully echo all the data of my table. but, I can not delete. after I enter the new data et click on checkbox and submit. the data go back to the orignial data. can anyone help me please? thank you so much.
<?php
include_once("mesparametres.inc.php");
$sql="SELECT * FROM poisson";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="modifier.php">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Nom</strong></td>
<td align="center"><strong>Classe</strong></td>
<td align="center"><strong>eau</strong></td>
<td align="center"><strong>nourriture</strong></td>
<td align="center"><strong>couleur</strong></td>
<td align="center"><strong>taille</strong></td>
<td align="center"><strong>vie</strong></td>
<td align="center"><strong>dateacqui</strong></td>
<td align="center"><strong>modifier</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><input type="hidden" name="id<? echo $rows['id']; ?>" value="<? echo $rows['id']; ?>" /><? echo $rows['id']; ?></td>
<td align="center"><input name="nom<? echo $rows['id']; ?>" type="text" id="nom" value="<? echo $rows['nom']; ?>"></td>
<td align="center"><input name="classe<? echo $rows['id']; ?>" type="text" id="classe" value="<? echo $rows['classe']; ?>"></td>
<td align="center"><input name="eau<? echo $rows['id']; ?>" type="text" id="eau" value="<? echo $rows['eau']; ?>"></td>
<td align="center"><input name="nourriture<? echo $rows['id']; ?>" type="text" id="nourriture" value="<? echo $rows['nourriture']; ?>"></td>
<td align="center"><input name="couleur<? echo $rows['id']; ?>" type="text" id="couleur" value="<? echo $rows['couleur']; ?>"></td>
<td align="center"><input name="taille<? echo $rows['id']; ?>" type="text" id="taille" value="<? echo $rows['taille']; ?>"></td>
<td align="center"><input name="vie<? echo $rows['id']; ?>" type="text" id="vie" value="<? echo $rows['vie']; ?>"></td>
<td align="center"><input name="dateacqui<? echo $rows['id']; ?>" type="text" id="dateacqui" value="<? echo $rows['dateacqui']; ?>"></td>
<td align="center"><input name="modifier[]>" type="checkbox" id="modifier[]" value="<? echo $rows['id']; ?>" ></td>
</tr>
<?php if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];}?>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit)
{
foreach($_POST['id'] as $id)
{
$sql1="UPDATE poisson SET nom='".$_POST["nom".$id]."', classe='".$_POST["classe".$id]."', eau='".$_POST["eau".$id]."',nourriture='".$_POST["nourriture".$id]."',couleur='".$_POST["couleur".$id]."',taille='".$_POST["taille".$id]."',vie='".$_POST["vie".$id]."',dateacqui='".$_POST["dateacqui".$id]."' WHERE id='".$id."'";
$result1=mysql_query($sql1);
}
}
mysql_close();
?>
</body>
</html>
Checkboxes are checked or not based on the checked HTML attribute, not the value attribute:
This:
<input type="checkbox" checked="checked" />
Not this:
<input type="checkbox" value="1" />
The value is what gets submitted along with the form when, for example, you group a bunch of checkboxes by using the same name attribute.
First I'd suggest to store that POST-data in variables for clarity :)
Then try run the query without storing it, i.e:
mysql_query("UPDATE table SET nom='variable1', classe='variable2' WHERE id='condition';
and so on, just like you did. You need also the attribute 'checked' i.e. checked="yes"