mysql - How to store input given by user in html form in sql using php -


this php code.

<html><head> <title>login.php</title> <link rel = "stylesheet" href="login-style.css">  </head> <body> <div class = "container"> <div class = "message"> <?php define('db_name','mydb'); define('db_user','root'); define('db_password',''); define('db_host','127.0.0.1');  $link = mysql_connect(db_host,db_user,db_password); if($link){     die('could not connect:'. mysql_error()); } $db_selected = mysql_select_db(db_name,$link); if(!$db_selected){     die('can\'t use'.db_name . ': ' . mysql_error()); } $value1 = $_post['name']; $value2 = $_post['password']; $sql = "insert account (username,password) values ('$value1','$value2')";  if(!mysql_query($sql)) {die('error'.mysql_error()); } mysql_close(); ?>  <h1>thank logging in </h1> <form action = "form.html"> <p class ="submit"> <button type ="submit" > go form </button> </p> </div> </div> </body> </html> 

i want store data in mysql when run html code (which have connected php code using action =" name of file"), no entry done in database created, can tell me done wrong , me correct it?

<doctype! html> <html lang = "en-us"> <head> <meta charset = "utf-8"> <title>sign-in</title> <link rel = "stylesheet" href ="style-sign.css"> <script type = "text/javascript"> function validateform(){ var x = document.forms["forma"]["login"].value; if(x == null || x == "") { alert("fill field ");   return false; } var y = document.forms["forma"]["password"].value; if( y == null || y == "") { alert("fill field"); return false; } } </script> </head> <body > <div class="container"> <div class="login"> <h1>login</h1> <form  name = "forma" method="post" onsubmit="return validateform()" action = "login.php"> <p> <input type="text" name="name" value="" placeholder="username or email"> </p> <p> <input type="password" name="password" value="" placeholder="password"> </p> <p class="submit"> <input type="submit" name="commit" value="login" > </p> </form> </div> </div> </body> </html> 

this html code have connected php file ,i using xampp , using phpmyadmin , not getting error , apache , mysql both running

help me problem

change following:

$sql = "insert account (username,password) values ('$value1','$value2')"; 

to:

$sql = "insert account (username,password) values ($value1,$value2)"; 

edit: not have input fields setup username , password. post not work.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -