Trouble with inserting data into a table

A

Anonymous

Guest
Hi there.

I'm kinda stuck with this. I'm a begginer so bear that mind. :?

My code is ;
Code:
<?php

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
	
mysql_query($query);
$query = INSERT INTO contacts ( `id` , `first` , `last` , `phone` , `mobile` , `fax` , `email` , `web` ) VALUES(``,`John`,`Smith`,`01234 567890`,`00112 334455`,`01234567891`,`johnsmith@gowansnet.com`,`http://www.gowansnet.com`);
mysql_close();

?>
I have declared $username and $password above this code. The connection to the server and the database seem to be fine.

Any help??

Thanks in advance
:help:
 
Please use code tags next time.

Your INSERT statement must be inside quotes and mysql_query() after that. You can get rid of the '`'.
Also use ' in the VALUES part of the query when inserting data. That will denote a string.
The best option is to always echo/print your query ($query in this case) to see what's happening.

Try this out:
Code:
<?php

// ...

$query = "INSERT INTO contacts (id, first, last, phone, mobile, fax, email, web) VALUES('','John','Smith','01234 567890','00112 334455','01234567891','johnsmith@gowansnet.com','http://www.gowansnet.com')";
mysql_query($query);
mysql_close();

// Testing
print $query;

?>
Also if you are INSERTing values in the right fields order, you can simply make:
Code:
<?php

$query = "INSERT INTO contacts VALUES('','John','Smith','01234 567890','00112334455','01234567891','johnsmith@gowansnet.com','http://www.gowansnet.com')";

?>
 
Back
Top