Syntax Error
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.";
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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";
}
?>