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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

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

Post 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]
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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();
?>
Post Reply