|
-
Oct 27th, 2004, 01:44 PM
#1
Thread Starter
PowerPoster
localhost
Code:
<?php
$user = "username";
$password = "password";
$database = "dbname";
mysql_connect(localhost,$user,$password);
@mysql_selectdb($database)or die("Error!");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();
?>
although it did work the table was created i got this error
Notice: Use of undefined constant localhost - assumed 'localhost' in *path here* on line 6
-
Oct 27th, 2004, 02:01 PM
#2
Fanatic Member
Yeah, MySQL doesn't know what localhost is, you should have written 'localhost' (with the 's)
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Oct 27th, 2004, 02:05 PM
#3
Thread Starter
PowerPoster
arr ok i'm following a tutorial and it didnt have quotes in it but thanks while i'm here
PHP Code:
$query="INSERT INTO contacts VALUES('','John','Smith','01234 567890','00112 334455','01234 567891','[email protected]','http://www.gowansnet.com')";
can you see any problems with that? i get a parse error, again its exact from this guide i'm following
-
Oct 27th, 2004, 02:10 PM
#4
Frenzied Member
try chaging the table name to `contacts`, with those kind of quotes.
Have I helped you? Please Rate my posts. 
-
Oct 27th, 2004, 02:14 PM
#5
Thread Starter
PowerPoster
still get the error....
hmm.. this guide is a bit poor really wonder if it was for older php version,
so how do you go about fixing it?
-
Oct 27th, 2004, 02:47 PM
#6
Thread Starter
PowerPoster
-
Oct 27th, 2004, 03:54 PM
#7
Do this on your query. It will then tell you the extact error:
PHP Code:
($result = mysql_query($query)) or
die(mysql_error());
-
Oct 28th, 2004, 11:35 AM
#8
Fanatic Member
Try switching the quotes, i.e. put " where you have ', and ' where you have ". It shouldn't matter, but it's better to have it that way. If you begin a string with " PHP has to parse it for variables and stuff but if you begin with a ' PHP doesn't parse it, so it's faster.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Oct 30th, 2004, 10:58 AM
#9
Fanatic Member
Its because you're trying to put a blank string into your auto incrementing int field. Take out the first two 's and the comma and it should work.
If wishes were fishes we'd all cast nets.
-
Oct 31st, 2004, 06:09 AM
#10
Thread Starter
PowerPoster
PHP Code:
<?php
$user="";
$password="";
$database="";
mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die ("error selecting DB");
$query="INSERT INTO contacts VALUES('John','Smith','01234 567890','00112 334455','01234 567891','[email protected]','http://www.gowansnet.com')";
mysql_query($query) or die (mysql_error());
mysql_close();
?>
Ok now it outputs the following error
Column count doesn't match value count at row 1
hm... this tuturiol is starting to p me off big time
-
Oct 31st, 2004, 06:13 AM
#11
Thread Starter
PowerPoster
PHP Code:
<?php
$user="";
$password="";
$database="";
mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die ("error selecting DB");
$query="INSERT INTO contacts (first, last, phone, mobile, fax, email, web) VALUES('John','Smith','01234 567890','00112 334455','01234 567891','[email protected]','http://www.gowansnet.com')";
mysql_query($query) or die (mysql_error());
mysql_close();
?>
never mind did it myself :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|