0

i want send two parameters to function in another PHP file, but operator must twice click on submit and checkbox!!!??????? this is my code to take data

<div class="question">
<?php

$data=array();
$fielddata=array();
$myconnection=mysql_connect("localhost","goftaman_solar","Setalna@2718");
mysql_set_charset('utf8',$myconnection);
$db=mysql_select_db('goftaman_edu');
$resultquestion="SELECT * FROM examination WHERE operator=''";
$showresultquestion=mysql_query($resultquestion,$myconnection);

while($row=mysql_fetch_object($showresultquestion)){
    $data[]=$row;
}
foreach($data as $itmes){ 
?>
<?php
    echo $itmes->question;
?>
    <form name="sendanswer" method="POST">
    <ul>
    <input type="hidden" id="idd" name="idd" value="<?php echo $itmes->question?>"></input>
    <li><input type="checkBox" id="answer" name="answer" value="<?php echo $itmes->answer1?>"><?php echo $itmes->answer1?></input></li>
    <li><input type="checkBox" id="answer" name="answer" value="<?php echo $itmes->answer2?>"/><?php echo $itmes->answer2?></input></li>
    <li><input type="checkBox" id="answer" name="answer" value="<?php echo $itmes->answer3 ?>"/><?php echo $itmes->answer3?></input></li>
    <li><input type="checkBox" id="answer" name="answer" value="<?php echo $itmes->answer4 ?>"/><?php echo $itmes->answer4?></input></li>
    </ul>
    <input type="submit" name="submit" value="ارسال پاسخ"/>
<?php
    $sendques="";
    $sendques=$_POST['idd'];
    $sendanswer="";
    $sendanswer=$_POST['answer'];
    funcsendexam($sendanswer,$sendques);
?>
    </form>

this my code in other PHP file which must take parameter and save in database:

<?php

function funcsendexam($sendexam,$sendques){
    $conn=mysql_connect("localhost","goftaman_solar","Setalna@2718");
    mysql_set_charset('utf8',$conn);
    mysql_select_db('goftaman_edu');
    $saveanswerquery="UPDATE examination 
                        SET operator='".$sendexam."'
                      WHERE question='".$sendques."'";
    mysql_query($saveanswerquery,$conn);
    mysql_close($conn);
}

?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
hosseini
  • 1
  • 2
  • A few things: your form has no action, you don't need closing input tags and an input cannot be a direct child of a ul – Pete Mar 05 '20 at 11:42
  • mysql_* is **DEPRECATED** and you should stop using it immediately , However using mysql_* means that you still use PHP5 which has no support right now , you are in a big risk – hassan Mar 05 '20 at 11:43
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 05 '20 at 11:44
  • 1
    Multiple errors. You have multiple `id` and separately `name` attributes with same values `id="answer"`. Dunno if the `name=` ones were intended... Also you are confusing front-end with backend. Among other problematic things as mentioned by other persons in comments here. – GetSet Mar 05 '20 at 11:45
  • Dunno why this was closed on mysql_* because actually it has more problems that could be indicative a deeper understanding of basic html forms in general, at least in consideration by javascript manipulations with same name `id`s but I digress. – GetSet Mar 05 '20 at 11:49
  • more more thanks from you, but if i use multi id because of i want send data which operator selected(this is related with Multiple errors) – hosseini Mar 05 '20 at 12:40

0 Answers0