0

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

3
Contributors
9
Replies
69
Views
2 Years
Discussion Span
Last Post by broj1
0

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.

0

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?

0

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.

1
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 ;?

0

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?

0

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";

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.