/* $query = "ALTER TABLE swat_dev_pending ADD {$gamename} TEXT NOT NULL; INSERT INTO swat_dev_pending ({$gamename}) VALUES ('{$embedcode}')";
$doquery = mysql_query($query) or die(mysql_error()); */ // Error at my end. Anyway:
$query1 = "ALTER TABLE swat_dev_pending ADD {$gamename} TEXT NOT NULL";
$query2 = "INSERT INTO swat_dev_pending ({$gamename}) VALUES ('{$embedcode}')";
$doquery1 = mysql_query($query1) or die(mysql_error());
$doquery2 = mysql_query($query2) or die(mysql_error());
/* $query = "ALTER TABLE swat_dev_pending ADD {$gamename} TEXT NOT NULL; INSERT INTO swat_dev_pending ({$gamename}) VALUES ('{$embedcode}')";
$doquery = mysql_query($query) or die(mysql_error()); */ // Error at my end. Anyway:
$query1 = "ALTER TABLE swat_dev_pending ADD {$gamename} TEXT NOT NULL";
$query2 = "INSERT INTO swat_dev_pending ({$gamename}) VALUES ('{$embedcode}')";
$doquery1 = mysql_query($query1) or die(mysql_error());
$doquery2 = mysql_query($query2) or die(mysql_error());
THANK YOU! Anyway, I am having one of those freak mysql "Check Your Manual" errors . Here is my code:
WOW! Heh. The embedcode went a little overboard don't you think?... Anyway, here is my little error message:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Pants Adventure 2' at line 1"
Hmmm. Does anybody know what this might mean? Thanks for your help so far.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Pants Adventure 2' at line 1
The gamename is Fancy Pants Adventure 2.
Hope I've given enough information to solve this...
Assuming you altered it so that you're actually creating a text field by that name correctly (check you're database), the problem is that it can't identify the fieldname. Backticks like this: ;
$query2 = "INSERT INTO swat_dev_pending (`{$gamename}`) VALUES ('{$embedcode}')"; . Fields with spaces have to be told in SQL that the entirety of the tokens represent the fieldname.
If its not creating the field (which I would expect), you need to surround the name with single quotations in the alter command.
Also, anything coming from a user needs to be escaped. Filter all data through mysql_real_escape_string first, and use my tutorial in the php snippets to remove any slashes added by magic_quotes_gpc. As it stands right now, if magic_quotes_gpc is disabled on you're server I can drop the entire database with one line of input code.
Altering you're table is a bad idea though. Normalize you're table to accept a `gamename` and a `value` field, and use a simple insertion for multiple rows. Altering tables without a model damages you're database design which will ultimately lead to anomalies.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Assuming you altered it so that you're actually creating a text field by that name correctly (check you're database), the problem is that it can't identify the fieldname. Backticks like this: ;
$query2 = "INSERT INTO swat_dev_pending (`{$gamename}`) VALUES ('{$embedcode}')"; . Fields with spaces have to be told in SQL that the entirety of the tokens represent the fieldname.
If its not creating the field (which I would expect), you need to surround the name with single quotations in the alter command.
Also, anything coming from a user needs to be escaped. Filter all data through mysql_real_escape_string first, and use my tutorial in the php snippets to remove any slashes added by magic_quotes_gpc. As it stands right now, if magic_quotes_gpc is disabled on you're server I can drop the entire database with one line of input code.
Altering you're table is a bad idea though. Normalize you're table to accept a `gamename` and a `value` field, and use a simple insertion for multiple rows. Altering tables without a model damages you're database design which will ultimately lead to anomalies.
About adding rows, is it possible to name individual ones and get a specific one using a code? Here is what I'm using now, which works great for me.
PHP Code:
<?php include 'dbconfig.php';
$query = 'SELECT `' . $game . '` FROM `games`';
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)) {
echo $row["$game"];
}
} else {
die('The game could not be found, please try again.');
}
?>
About adding rows, is it possible to name individual ones and get a specific one using a code? Here is what I'm using now, which works great for me.
PHP Code:
<?php include 'dbconfig.php';
$query = 'SELECT `' . $game . '` FROM `games`';
$result = mysql_query($query);
if($result) { while($row = mysql_fetch_array($result)) { echo $row["$game"]; } } else { die('The game could not be found, please try again.'); } ?>
Is anything like this possible with rows?
Thanks!
Forthfriend
Sure.
Code:
CREATE TABLE `games` (
`Name` varchar(50) NOT NULL,
`Data` longtext NOT NULL,
PRIMARY KEY (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run inserts using the name of the game (thats the field you're adding in), combined with the data. When you select it, you simply select like so:
PHP Code:
$query = 'SELECT `Data` FROM `games` WHERE `Name` = \'' . mysql_real_escape_string($game) . '\'';
Simple as that. This keeps you're table to only two fields which indexes based on the game name.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php