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?

2009-07-31T17:54:26Z

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)

2009-07-31T18:00:30Z

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

tiger23802009-07-31T18:00:56Z

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.

?2009-07-31T17:53:01Z

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>');
}
?>

?2009-07-31T17:50:26Z

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

?2016-12-24T20:57:39Z

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 :)