Page 1 of 1

Hmmm new to this... Having trouble inserting stuff to db

Posted: Sun Apr 01, 2007 10:38 am
by Tepear
Ok, well like the title says, I'm new to this. I've been following this tutorial..
http://www.freewebmasterhelp.com/tutorials/phpmysql/3
and I need help, when I go to the thing (http://localhost/insertjohn.php)
nothing shows witch is OK but then when I check the database, nothing has been inserted.
I'm using this

Code: Select all

<?
$hostname="localhost"; 
$username="name"; 
$password="password"; 
$database="contacts"; 
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','John','Smith','01234 567890','00112 334455','01234 567891','johnsmith@gowansnet.com','http://www.gowansnet.com')";
?>
(I took out the username and password)

Is something wrong with the code, or is something wrong with the database?

Posted: Sun Apr 01, 2007 10:59 am
by timvw
Could you tell us (in your own words) what the code does? (If you want to perform a query you would have to call mysql_query, your code only seems to create a variable $query which contains some sql...)

Posted: Sun Apr 01, 2007 11:08 am
by Tepear
ok the table is set up like this

ID First Last Phone Mobile Fax Email Web

it is supposed to put in the following info...

John','Smith','01234 567890','00112 334455','01234 567891','johnsmith@gowansnet.com','http://www.gowansnet.com

Posted: Sun Apr 01, 2007 11:11 am
by feyd
mysql_query() isn't called in the snippet posted.

Posted: Sun Apr 01, 2007 11:15 am
by Tepear
uhh were would that go? Like I said, I'm new to this.

Posted: Sun Apr 01, 2007 11:45 am
by feyd
Somewhere after $query is set, probably.