Dear friend,
i have 2 tab 1) atab 2) qtab.. when i put question and options answers ..
i use three forms qset.php, Ans.php and result.php here are code

what i want that email of user updated after click button submit
code is below ans.php

<?PHP include "conn.php";
//session_start();
?>
<!DOCTYPE HTML>

<html>

<head>
  <title>Answer Section</title>
</head>

<body style="color: #6ACCCB; background-color: #3C8924">

<h1 style="color: #C4CCC4; background-color: #3F5ECC; width: 30%">Answer Section</h1>

<form action="result.php" method="GET">


<?PHP

 $sql="SELECT * FROM qtab ORDER BY Qid DESC Limit 1";

        $result=$conn->query($sql);

        if(!$result){
                  die($conn->error);
                  }
           While($row=$result->fetch_assoc()){
           echo "<BR>"."Question: ".$row["Question"]." ?"."<BR>"."<BR>";
      //fetch data from atab table
      $sqla="SELECT * FROM atab ORDER BY Qid DESC Limit 1";
      $resulta=$conn->query($sqla);

        if(!$resulta){
                  die($conn->error);
                  }
           While($rowa=$resulta->fetch_assoc()){

  ?>
<P>
&nbsp;<?PHP echo $row['AnsA']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="radio" name="q" value="AnsA" /> <BR></br>
&nbsp;<?PHP echo $row['AnsB']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="radio" name="q" value="AnsB" /><BR></br>
&nbsp;<?PHP echo $row['AnsC']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<input type="radio" name="q" value="AnsC" /> <BR></br>


<input type="text" name="hid" value="<?php echo $rowa['Qid']; ?>" />
Enter your Email address:<input type="text" name="email" value="<?php echo $rowa['email'];}  ?>"  />    <br></br>
&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Submit" />

 </p>
</form>
</body>
       <?php
              }
      $conn->close();
 ?>

</html>

and result.php

<?php
include "conn1.php";

   if(isset($_GET['submit']) && isset($_GET['q'])){

   $answer=$_GET['q'];
   $hid=$_GET['hid'];
   $mail="9jjk";
        echo($mail)."<br>";
       //if($row=($sql->num_rows()>1)){
   $sqlu="UPDATE atab
   SET
   email=$mail,
   $answer=$answer+1
    WHERE Qid=$hid";
   $result=$conn->query($sqlu);
   if ($result){
       echo("user has voted");}
   else {
     echo("Error") ;
   }

            }


?>

Only numarical data updated...in mail=$email
plz guid me

The $mail doesn't even come from the form. Should you code it something like:

if(isset($_GET['submit']) && isset($_GET['q']) && isset($_GET['email']) {
    $mail=$_GET['email']; // sanitize this first
    ...

Then the question is what type the email field is.

And a side note: vlidate and sanitize the data from the form before you save it into the database.

again error... no changed?

<?php
    if(isset($_GET['submit']) && isset($_GET['q']) && isset($_GET['email'])){

       $mail=filter_input(INPUT_GET,'email',FILTER_SANITIZE_SPECIAL_CHARS);
       $answer=$_GET['q'];
       $hid=$_GET['hid'];
       $mail=$_GET['email'] ;
            //echo($mail)."<br>";
           //if($row=($sql->num_rows()>1)){
       $sqlu="UPDATE atab
       SET
       email=$mail,
       $answer=$answer+1
        WHERE Qid=$hid";
       $result=$conn->query($sqlu);
       if ($result){
           echo("user has voted");}
       else {
         echo("Error") ;
       }

                }


    ?>

if i enter any number it works but if i enter email or any charector it shows "Error" what to do?

Stick this code on line 3 just after the if(isset($_GET['submit']) && isset($_GET['q']) && isset($_GET['email'])){ line:

die(print_r($_GET, 1));

That will print out the values sent from the form and stop the script. Post the output here.

Enter your Email address:<input type="text" name="email" value="<?php echo $rowa['email'];} ?>" /> <br></br>

Line 47, are you supposed to have } at the end of ;?

Mr.Tywan,

} of line 47  began from line 37 while loop......

dear broj1,
here is output

Array ( [q] => AnsB [hid] => 17 [email] => zebnoooon@gmail.com [submit] => Submit )

yes this data is from previous form .now what to do?

The $_GET array contents is OK. You are getting the email address through. After filtering/sanitizing it the email should not change. It should be writen OK into the database.

Ups, only now I have spotted it. You are missing quotes arround the $mail in your query, like this:

$sqlu="UPDATE atab
SET
email='$mail',
$answer=$answer+1
WHERE Qid=$hid";

If solved, please mark thread as solved. Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.