Re: PHP mySQL Syntax problem

From: Date: Wed, 08 Jan 2003 12:17:30 +0000
Subject: Re: PHP mySQL Syntax problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130759@lists.php.net to get a copy of this message
MYSQL($Dbname, "INSERT INTO $Tbname_1 VALUES(1, 'John Doe', '$color')"); - single quotes around $color Jo Ann Comito wrote:
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


« previous php.general (#130759) next »