Page 1 of 1

Code dosnt INSERT VALUE and Dosnt Display data but no error!

Posted: Fri Apr 16, 2004 3:29 am
by yosuke_
Hi!!
Well, this is my code, but it dosnt insert any value in database table. I added some values into Database: Mydata.users.firstname and when I type in mySQL monitor: Select firstname From users; then i get my values, but the problem is this. The code dosnt add any value in firstname and dosnt display any error!!

Code: Select all

<?
error_reporting(E_ALL);
$username="Kristian";
$password="mypassword";
$database="mydata";

mysql_connect("localhost",$username,$password);
mysql_select_db($database);
$query = "INSERT INTO users(firstname) VALUES ('MySQL')";
mysql_query($query);

mysql_close();
?>
[/i]

Posted: Fri Apr 16, 2004 4:25 am
by markl999
Try this version, it should tell you what's going on.

Code: Select all

<?
error_reporting(E_ALL);
$username="Kristian";
$password="mypassword";
$database="mydata";

$db = mysql_connect('localhost',$username,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$query = "INSERT INTO users (firstname) VALUES ('MySQL')";
mysql_query($query) or die(mysql_error());

mysql_close();
?>