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

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
Tepear
Forum Newbie
Posts: 3
Joined: Sun Apr 01, 2007 10:33 am

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

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...)
Tepear
Forum Newbie
Posts: 3
Joined: Sun Apr 01, 2007 10:33 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_query() isn't called in the snippet posted.
Tepear
Forum Newbie
Posts: 3
Joined: Sun Apr 01, 2007 10:33 am

Post by Tepear »

uhh were would that go? Like I said, I'm new to this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Somewhere after $query is set, probably.
Post Reply