PHP mySQL Syntax problem
| From: | Jo Ann Comito | Date: | Tue, 07 Jan 2003 21:17:22 +0000 |
| Subject: | PHP mySQL Syntax problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-130757@lists.php.net to get a copy of this message | ||
I'm working in PHP4 and have suceeded in creating a mySQL table. I can
fill the table using the INSERT command as follows:
<?
//some code here to establish connection, define and create table, etc.
.....
MYSQL($Dbname, "INSERT INTO $Tbname_1 VALUES(1, 'John Doe', 'red')");
MYSQL($Dbname, "INSERT INTO $Tbname_1 VALUES(2, 'Jane Smith', 'green')");
......
?>
The above works fine. Here is the problem: Instead of specifying the
color, red, green, etc. I would like to generate a random color and
store it in a variable, then use the variable in the INSERT command. To
simplify the code in this example, I have just assigned a color to the
varialble.
$color = "red";
MYSQL($Dbname, "INSERT INTO $Tbname_1 VALUES(1, 'John Doe', $color)");
$color="green"
MYSQL($Dbname, "INSERT INTO $Tbname_1 VALUES(2, 'Jane Smith', $color)");
This syntax does not work. The table is created, but it has 0 rows. I
have tried a multitude of variations, including
ECHO $color
'$color'
\'$color\'
{$color}
etc.
No combination I have tried works. Could some kind person please point
me in the right direction?
Thanks,
Jo Ann