Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

More PHP help (20 characters)?

Hey, every time I try this code it gives me problems. I'm using a Site Point book, so it's done by an expert. At first I copied it myself and after that I copied it and pasted it right out of the e-book (PDF).

Here's the code:

<?php

mysql_query(query[, connection_id])

$sql = 'CREATE TABLE joke (

id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

joketext TEXT,

jokedate DATE NOT NULL

)';

if (@mysql_query($sql)) {

echo '<p>joke table successfully created!</p>';

}

else {

exit ('<p>Error creating joke table: '.

mysql_error() .'</p>');

}

?>

It gives me the following message when I refresh the page:

Parse error: syntax error, unexpected '[' in /home/content/s/h/a/shadeaux/html/phpsite/mysqlcon.php on line 33.

I'm at a loss here, could someone please help?

Update:

Thank you Joe, only problem is it created a whole new error..

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/s/h/a/shadeaux/html/phpsite/mysqlcon.php on line 21

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/content/s/h/a/shadeaux/html/phpsite/mysqlcon.php on line 21

Error creating joke table: Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)

Update 2:

Tiger238 you did it!!!! Thank you man!!!! Thank you all for the help.

4 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Ok this is the proper way to write this code:

    <?php

    //First you have to connect to your server. For example:

    $connection = mysql_connect("host","username", "password");

    //check and see if connection went through

    if(!$connection)

    {

    echo '<p>Error connecting to server:'.mysql_error().'</p>';

    }

    //then create the table:

    $sql = 'CREATE TABLE joke {id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

    joketext TEXT,

    jokedate DATE NOT NULL

    )';

    //then execute the code by doing this:

    $table_cr = mysql_query($sql);

    //check to see if table was created

    if(!$table_cr)

    {

    echo '<p>Error creating joke table: '.mysql_error().'</p>';

    }

    else

    {

    echo '<p>Table was created successfully.</p>';

    }

    ?>

    - - - - - - - - v - - - - - - - - - - - - -- v -- - - - - - - - - - -

    Now for your code. What is "query[" and "connection_id"? If you need anymore help, just join my forum.

    Since you are working on your own computer, your hostname should be "localhost", username might be "root", and password might be "password" or blank.

    Source(s): http://www.bluecomet.comxa.com/ I'm a web developer
  • 1 decade ago

    Use this code:

    <?php

    $sql = 'CREATE TABLE joke (

    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

    joketext TEXT,

    jokedate DATE NOT NULL

    )';

    if (mysql_query($sql)) {

    echo '<p>joke table successfully created!</p>';

    }

    else {

    exit ('<p>Error creating joke table: '.

    mysql_error() .'</p>');

    }

    ?>

  • 1 decade ago

    it says LINE 33 ... r u including any files in this page .. if yes .. it counts all the lines of all the files included in the page starting from line 1 in the page .. so it might be tht the file you have included may have an error in it .. plz chk tht .. else i do not see any error in the code by itself

  • lamons
    Lv 4
    4 years ago

    To study/get the consultation identity's you will ought to run the Hypertext Preprocessor code on the comparable server. subsequently each and each time its run on a various server its a various #, and this # is tied to the cookie it creates make it unique. additionally Hypertext Preprocessor code is compiled until now its confirmed to you, so which you cant see the source itself. unlike asp :)

Still have questions? Get your answers by asking now.