Help - Search - Members - Calendar
Full Version: [resolved] Blog tutorial
Codegrrl.com Forums > Script Help > Tutorial Help
benjaminj
Just to let you all know, I am
extremely new to php, and mysql.

Well I have done everything the blog tutorial said to do on "Creating your database"
When I go to browse my php script this is the result. A white page which says

"Parse error: syntax error, unexpected T_STRING in /home/www/benjaminj.awardspace.com/test.php on line 4"

This is everything that I have put in this page
NOTE: I placed stars where my password was, just as a saftey precausion.


<?php

mysql_connect ('localhost', 'db_benjaminj_blog', 'db_******')
mysql_select_db ('db_benjaminj_blog');

$sql = "CREATE TABLE php_blog (
id int(20) NOT NULL auto_increment,
timestamp int(20) NOT NULL,
title varchar(255) NOT NULL,
entry longtext NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
)";

$result = mysql_query($sql) or print ("Can't create the table 'php_blog' in the database.<br />" . $sql . "<br /> .mysql_error());

if ($result != false) {
echo "table 'php_blog' was successfully created.";
}

mysql_close();

?>



Will someone help me please?
Contact me either on here or at
Benjaminj88@msn.com

thank you for your time.
Amelie
You forgot a ; on the third line - mysql_connect ('localhost', 'db_benjaminj_blog', 'db_******'). Add it to the end of the line, after the ).
lifejacket
And just fix up your double quotes in this one:

$result = mysql_query($sql) or print ("Can't create the table 'php_blog' in the database.<br />" . $sql . "<br />" .mysql_error());

It needed and extra " after the final <br />. biggrin.gif
Sairah
Hi, I'm new here, and since Cutenews wasn't working with my sites dynamic includes [thanks to the tut on here =D], I decided to get rid of it. Well...one thing lead to another and I decided to get rid of Blogger, too. XD

Anyhow, I'm quite familiar with basic PHP [includes, external stylesheets, stuff like that], but EXTREMELY N00B at MySQL [as in, I just created a database on about an hour ago for the purposes of following this tut]. Needless to say, I've run into errors.

Here's what my script looks like:

CODE
<?php
mysql_connect ('localhost', 'sairah_sscribble', '****************');
mysql_select_db ('sairah_ss');
$sql = "CREATE TABLE php_blog (
    id int(20) NOT NULL auto_increment,
    timestamp int(20) NOT NULL,
    title varchar(255) NOT NULL,
    entry longtext NOT NULL,
    PRIMARY KEY (id)
)";

$result = mysql_query($sql) or print ("Can't create the table 'php_blog' in the database.<br />" . $sql . "<br />" . mysql_error());

if ($result != false) {
    echo "Table 'php_blog' was successfully created.";
}

mysql_close();
?>


...and this is what it's returning me:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 2

Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 3

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 3

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 12

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 12
Can't create the table 'php_blog' in the database.
CREATE TABLE php_blog ( id int(20) NOT NULL auto_increment, timestamp int(20) NOT NULL, title varchar(255) NOT NULL, entry longtext NOT NULL, PRIMARY KEY (id) )
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Warning: mysql_close(): no MySQL-Link resource supplied in /var/hsphere/local/home/sairah/sairah.endless-time.net/ssdb.php on line 18


Any help please? sad.gif
Amelie
Your database host isn't localhost - you'll need to ask your host what it is, and replace all instances of localhost in the script (usually at the top of every page) with whatever your database host actually is.
Sairah
Excellent! Thanks! I kinda figured everyone had 'localhost' as their host, since in the tut, it didn't mention you might need to change that. =D But I got a perfect table created message when I changed it. ^^ A relief- I thought I was SQL-retarded and that would be sad. T_T
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.