html - php input into mysql database -
i'm trying set input form in database won't work. here code:
<?php $host="localhost"; // host name $username="removed"; // mysql username $password="removed"; // mysql password $db_name="removed"; // database name $tbl_name="input"; // table name // connect server , select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); // values form $email=$_post['email']; // insert info mysql $sql="insert $tbl_name(email) values('$email')"; $result=mysql_query($sql); // if insert info database, displays message "successful". if($result){ echo "successful"; echo "<br>"; echo "<a href='insert.php'>back main page</a>"; } else { echo "error"; } ?> <?php // close connection mysql_close(); ?>
hi
<form class="form-signin" method="post" action="./php/email2db.php"> <input type="text" name="email" class="input-block-level" placeholder="email address"> <button class="btn btn-primary" type="submit">pass popcorn</button> </form>
can help me when out in goes on database? want , it's not please help.
think query should this:
<?php $host="localhost"; // host name $username="removed"; // mysql username $password="removed"; // mysql password $db_name="removed"; // database name $tbl_name="input"; // table name // connect server , select database. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select db"); //removed " $db_name, $host, $username, $password // values form $email=$_post['email']; // insert info mysql $sql="insert ".$tbl_name." (email) values(".$email.")"; //here have concatenate query multiple parts, of import //and cant utilize "$tbl_name(email)" $result=mysql_query($sql); // if insert info database, displays message "successful". if($result){ echo "successful"; echo "<br>"; echo "<a href='insert.php'>back main page</a>"; } else { echo "error"; } ?> <?php // close connection mysql_close(); ?>
php html mysql table row
No comments:
Post a Comment