Jump to content

Connecting to MYSQL database


Nexus10

Recommended Posts

<?php
$host = "localhost";
$user = "ericsmi_admin";
$password = "password";
$database = "ericsmi_Users"; 

mysql_connect($host, $user, $password) or die(mysql_error("DIED"));
mysql_select_db($database) or die("Error: Could not connect to database"); 

$query = INSERT INTO Users(user, date_registered, password, email) VALUES ("eric", "12/12/12, test, eric@eric.com");
mysql_query($query) or die("Error: data not inserted");
echo("Data inserted");?>

 

Nothing happens, nothing is printed, not no error message.

Link to comment
https://forums.phpfreaks.com/topic/205408-connecting-to-mysql-database/
Share on other sites

Try this and tell me whts the output...

error_reporting(E_ALL);
$host = "localhost";
$user = "ericsmi_admin";
$password = "password";
$database = "ericsmi_Users"; 

mysql_connect($host, $user, $password) or die(mysql_error("DIED"));
mysql_select_db($database) or die("Error: Could not connect to database"); 

$query = "INSERT INTO Users(user, date_registered, password, email) VALUES ('eric', '12/12/12', 'test', 'eric@eric.com')";
mysql_query($query) or die("Error: data not inserted");
echo("Data inserted");

  Quote

$query = INSERT INTO Users(user, date_registered, password, email) VALUES ("eric", "12/12/12, test, eric@eric.com");

 

There are no quotes around the query string. You need:

$query = 'INSERT INTO Users(user, date_registered, password, email) VALUES ("eric", "12/12/12, test, eric@eric.com")';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.