Hello,
below is my code. i am trying to insert the data into database but not getting suceeded. In my query there, if i remove the condition WHERE username=‘$u’ it works fine but with it,it responds only in failure.
<?php
$sql = "SELECT * FROM mymake LIMIT 1";
$query = mysqli_query($db_conx,$sql);
$numrows = mysqli_num_rows($query);
?>
<?php
if(isset($_POST["submit"]))
{
$ques=preg_replace('#[^a-z0-9]#i', '', $_POST['q']);
$ans=preg_replace('#[^a-z0-9]#i', '', $_POST['response']);
$sql="INSERT INTO mymakeuser (question1,answer1) VALUES('$ques','$ans') WHERE username='$u' ";
$user_query = mysqli_query($db_conx, $sql);
if($user_query===TRUE)
{echo "success";}
else echo "failed";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
form > select { width:280px;}
</style>
</head>
<body>
<form method="post" action="hello.php?u=<?php echo $u; ?>">
<?php
if ($numrows > 0){
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
?>
<input type="text" name="q" placeholder="<?php echo $row["question"];?>" size="82" >
<select name="response" required="required">
<option value=""></option>
<option value="<?php echo $row["option1"]; ?>"><?php echo $row["option1"]; ?></option>
<option value="<?php echo $row["option2"]; ?>"><?php echo $row["option2"]; ?></option>
<option value="<?php echo $row["option3"]; ?>"><?php echo $row["option3"]; ?></option>
</select>
<br>
<?php
}
}
?>
<br /><input type="submit" value="Ready to Go" name="submit" />
<input type="reset" value="Reset" name="reset" />
</form>
</body>
</html>