Results 1 to 11 of 11

Thread: localhost

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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

  2. #2
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    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

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    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

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    try chaging the table name to `contacts`, with those kind of quotes.
    Have I helped you? Please Rate my posts.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    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?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    anyone?>

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Do this on your query. It will then tell you the extact error:
    PHP Code:
    ($result mysql_query($query)) or 
        die(
    mysql_error()); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    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

  9. #9
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    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

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    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
  •  



Click Here to Expand Forum to Full Width