0

I am tried to insert the values into my wampserver, I succeed to insert name column and email column but it is not possible to insert pass word field into the database please check what I done mistake here.
enter image description here

above image gives you a clear idea, how that pass word field looks, note that that password field i tried to save the data in VARCHAR() but not save the data please check my below php and html codes
init.php
for database connection am using this

<?php
$user_name="root";
$pass="";
$host="localhost";
$db_name="userdb";
$con=mysqli_connect($host,$user_name,$pass,$db_name);
if(!$con)
{
 echo "Connection Failed....".mysqli_connect_error();
 
}
else
echo "<h3>Connection Success.....</h3>";

?>

register.php

<?php
$name=$_POST["name"];
$email=$_POST["email"];
$pass=$_POST["password"];
require "init.php";
$query="select * from userinfo where email like '".$email."';";
$result=mysqli_query($con,$query);
//ok
if(mysqli_num_rows($result)>0)
{
 $response=array();
 $code="reg_false";
 $message="User already exist....";
 array_push($response,array("code"=>$code,"message"=>$message));
 echo json_encode(array("server_response"=>$response));
}
else
{
    $querys ="insert into userinfo values ('".$name."','".$email."','".$pass."');";
    $result=mysqli_query($con,$querys);
    if(!$result)
    {
        $response=array();
        $code="reg_false";
        $message="Some server error occurred, Train again....";
        array_push($response,array("code"=>$code,"message"=>$message));
        echo json_encode(array("server_response"=>$response));
    }else{
        $response=array();
        $code="reg_true";
        $message="Registration Success....Thank you....";
        array_push($response,array("code"=>$code,"message"=>$message));
        echo json_encode(array("server_response"=>$response));
    }
}
mysqli_close($con);
?>

register_test.html
this one is used for to send the details to the database, am using this one like as input to send data

<html>
<head> <title>Register Test....</title> </head>
<body>
<form method="post" action="register.php">
<table>
<tr>
<td>Name :</td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Email :</td><td><input type="text" name="email"/></td>
</tr>
<tr>
<td>Password :</td><td><input type="password" name="password"/></td>
</tr>
<tr>
<td><input type="submit" value="Register"/></td>
</tr>
</table>
</form>
</body>
</html>

please check this code, and please tell where i done the mistake to got the pass word values into my database

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
yuggi
  • 32
  • 6
  • Well for one you don't need .$variable. you can just insert them as values '$variable'. When you echo out $pass before the insert does it come as empty or does it have a value. Also why aren't you using prepared statements if you're inserting variables ? – clearshot66 Feb 23 '17 at 18:58
  • Possibly the most significant mistake is that this code is wide open to SQL injection. What this means is not only that it's open to malicious code from users, but also that you don't actually know what SQL query you're executing. Echo the actual runtime SQL query so you can check it. Additionally, look at `mysqli_error()` when the query fails. – David Feb 23 '17 at 18:58
  • @clearshot66, i will try wait a minute – yuggi Feb 23 '17 at 19:02
  • @clearshot66, it's not working bro. will you please tell me elaborately. – yuggi Feb 23 '17 at 19:07
  • http://php.net/manual/en/mysqli.prepare.php and if you echo $pass upon form submit, does it print out the password you entered at the top of your screen? – clearshot66 Feb 23 '17 at 19:08
  • @clearshot66, one thing is sure i dont know about php, and html actually am android developer. i want a sever to check the login and signup response that's why i am here. from last 6 hrs i trying solve this but i am not successes please tell me some code please – yuggi Feb 23 '17 at 19:13
  • @yuggi literally type print_r($_POST); under all your post variables, then fill in your form and submit, then see if a password variable comes there in that array. – clearshot66 Feb 23 '17 at 19:14
  • @sorry for this where in registe.php or register_test.html – yuggi Feb 23 '17 at 19:17
  • @clearshot66 i got a message like Array ( [name] => jaggu [password] => jaggu [email] => jaggu24 ), but in data base it not showing the password coloumn – yuggi Feb 23 '17 at 19:19
  • Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you cannot miss or ignore. – RiggsFolly Feb 24 '17 at 10:00
  • Also in your error processing get into the habit of outputting the actual database error (while testing) using `mysqli_error($con)` rather than just a user message which does not help you debug your query – RiggsFolly Feb 24 '17 at 10:02
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Feb 24 '17 at 10:06

1 Answers1

-1

If your other two are getting inserted, try this:

$querys ="INSERT INTO userinfo (name,email,password) VALUES ('$name','$email','$pass');
$result = $mysqli_query($con,$querys);
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
clearshot66
  • 2,292
  • 1
  • 8
  • 17