php - linking and sending form values to mysql database? -
my html code:
<form action="send_post.php" method="post"> <input type="submit" value="login" /> </form>
php code:
<?php $con = mysqli_connect("","",""); if (!$con) { die('could not connect: ' . mysql_error()); } else { // echo('connected mysql'); } @mysql_select_db("a", $con);// connect database db_name if (isset($_post['submit'])) { $email=$_post['email']; $pass=$_post['pass']; $sql_query="insert formdata (email, pass) values('$email', '$pass')";} ?>
database name: mysql
table name: formdata
why not working? in second line used 'local host' first receiving error removed it.
- you use
mysqli_
api connect database , test errors , try select databasemysql_
api. pick 1 , stick it. (don't pickmysql_
deprecated). - you run form handling code if there
submit
data item in submitted data. have no form controlname="submit"
never happen. - your form handling code expects there
email
,pass
data in submitted data form not have fields names. - constructing sql query string , storing in variable insufficient database. have sent database server. use
mysqli_query
current approach, should switch prepared statements
Comments
Post a Comment