tags:

views:

95

answers:

2

Hi, Once I have successfully connected to the database, i have a line that must insert values.

mysqli_query($edb, "INSERT INTO elvis_table (name,email) VALUES ('$name','$email')" ) or die('Error querying database.');

It works fine on my computer ( xampp ), but once I upload it onto a server, it starts giving an error.

Yes, I have a database with a corresponding table and fields on a server, it connects to the database fine, but gives an error on this line...

Thanks!

if (isset($_POST['submit_to_db'])) { 
  $name = trim($_POST['namefield']); 
  $email = trim($_POST['emailfield']); 
  $edb = mysqli_connect('mysql3.XXX.com', 'DB_NAME', 'DB_PASSWORD') or die('Error connecting to MySQL server.'); 
  #upto here connects OK. 
  mysqli_query($edb, "INSERT INTO elvis_table (name,email) VALUES ('$name','$email')" ) or die('Error: ' . mysql_error()); 
  # and dies here.
+2  A: 

Without error message it's just impossible to tell what's the problem.

or die(mysqli_error($edb)); instead of or die('Error querying database.'); would tell you whats wrong
or even better

$sql="INSERT INTO elvis_table (name,email) VALUES ('$name','$email')";
mysqli_query($edb, $sql) or trigger_error(mysqli_error($edb) . $sql);

but you have to be able to see standard error messages in this case.

Also, I hope that $name and $email are properly escaped using mysqli_real_escape_string()

Col. Shrapnel
tried, it does not give any error, but still nothing is added to the database.
+1  A: 

check out if u have given permissions to the user in server

nik