-2

When I submit a form I get form submit success, but I cant see the data in database

Am using Hostinger phpmyAdmin

Name:

Email address:

Phone:

Twitter:

Comment:

if(isset($_POST['submit'])){

define('DB_NAME','u111425464_arub');
define('DB_USER','u111425464_arub');
define('DB_PASSWORD','');
define('DB_HOST','localhost');

$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);

if(!$conn){
    die('Sorry, we could not connect at this time:'.mysql_error());
}

$db_selected=mysql_select_db(DB_NAME, $conn);

if(!$db_selected){
    die('Cannot use'.DB_NAME.':'.mysql_error());
}

mysql_select_db("users", $conn);

$sql = "INSERT INTO usercontacts (ID, name, email, phone, twitter, comment) VALUES ('$_POST[name]',               '$_POST[email]', '$_POST[phone]', '$_POST[twitter]', '$_POST[comment]')";
mysql_query($sql,$conn);

mysql_close($conn);

}

No data in database

  • 1
    Your code is *wide open* to **SQL injection**, which is not only a security hole but also a very common source of bugs. You're also not checking for errors if `mysql_query()` fails, take a look at the output of `mysql_error()`. (Basically, the database could be telling you the problem but you're just ignoring it.) Also, the `mysql_*` functions have been deprecated for a *long* time and shouldn't be used anyway, take a look at the `mysqli_*` functions as a replacement. – David Jan 28 '19 at 12:14
  • https://stackoverflow.com/questions/21797118/deprecated-mysql-connect may be an issue. – Nigel Ren Jan 28 '19 at 12:16
  • What is the name of the database where you want to make changes? Is it "u111425464_arub" or is it "users"? What is the name of the table you want to add rows to? – Fabian Jan 28 '19 at 13:04

1 Answers1

-1

First thing you have used two times select db. Verify both. Next try with quotes like. If id is auto increment then no need to pass id.

$sql = "INSERT INTO users (ID, ==name, email, phone, twitter, comment)
        VALUES ('".$_POST["name"]."','".$_POST["email"]."','".$_POST["phone"]."','".$_POST["twitter"]."','".$_POST["comment"]."')";
krishnaisdinesh
  • 379
  • 4
  • 17