Syntax Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your insert code was fine the way it was (with the possible exception of the '/' in the 'osx/osx.css'). Maybe try passing the insert data through mysql_real_escape_string() and see what comes of it.
nhwood
Forum Newbie
Posts: 13
Joined: Tue May 23, 2006 2:51 pm

Post by nhwood »

How does this help me? All I need is to post that data, if there is a way to get the "/" in the code in some other form...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sometimes, passing data to MySQL without checking to make sure it is acceptable leads to errors in the SQL command. I have had experiences with trying to pass '@' into mysql, as well as '\'. The DB doesn't handle those special characters well and chokes when you throw those into the script without escaping them. It was just a thought.
nhwood
Forum Newbie
Posts: 13
Joined: Tue May 23, 2006 2:51 pm

Post by nhwood »

I worked on a replacement and I was able to just have it be "osx" rather than "osx/osx.css" Still no luck though, I will keep trying...
nhwood
Forum Newbie
Posts: 13
Joined: Tue May 23, 2006 2:51 pm

Post by nhwood »

Does this new script look okay?

Code: Select all

<?php

$server = "localhost";	// server to connect to.
$database = "nhwood_spirfboard";	// the name of the database.
$db_user = "nhwood_testing";	// mysql username to access the database with.
$db_pass = "******";	// mysql password to access the database with.
$table = $_POST['username'];		// the table that this script will set up and use.

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// create table on database
$insert = "INSERT INTO $table (style, texttest, title) VALUES ('osx', 'Welcome to SPIRFBoard', 'Title');";

mysql_query($insert)
or die ("Could not create tables because ".mysql_error());
echo "Complete.";

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$server = "localhost";	// server to connect to.
$database = "dbname";	// the name of the database.
$db_user = "dbname";	// mysql username to access the database with.
$db_pass = "******";	// mysql password to access the database with.
$table = $_POST['username'];		// the table that this script will set up and use.

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database) or die ("Could not select database because ".mysql_error());

// create table on database
$insert = "INSERT INTO $table (style, texttest, title) VALUES ('osx', 'Welcome to SPIRFBoard', 'Title');";

if (!$result = mysql_query($insert))
{
    die ("Could not create tables because ".mysql_error());
}

if (mysql_affected_rows($result))
{
    echo "Complete.";
}
else
{
    echo "Not COmplete";
}
?>
Try this one and see. I just added another level of checking things.
nhwood
Forum Newbie
Posts: 13
Joined: Tue May 23, 2006 2:51 pm

Post by nhwood »

Guess what? Everything works! Thanks a lot for all of your help! I have one last step, but I can do that myself. This forums is awesome. I've still got some work, but as soon as my public beta for my Web 2.0 project is ready I'll be sure to announce it to you!
Post Reply