Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Variables in mySQL statement

Status
Not open for further replies.

madcode

Programmer
Jan 19, 2003
1
US
Problem,
I use a form data to create a string which will contain info for an sql table builder. It works if I type in info manually, but when I drop in into a string, doesn't work, for examples sake, here is a print $sql:
The master SQL STRING IS: apple CHAR(2), BANNAG CHAR(2), ORGANGE CHAR(2)
So I know the string has the right value, just won't work in code. Any help is greatly appreciated.

# variable table is name of table passed in form data
# $sql is the string value which contains table creation data


# ISSUE SQL STATEMENT TO BUILD TABLE
$resultID=mysql_query("CREATE TABLE $table($sql))",$linkID);

# CHECK FOR SUCCESS!!!
if ($resultID != FALSE)
{
print &quot;<FONT COLOR=GREEN>Table created Successfully!!&quot;;
}
else
{
print &quot;<FONT COLOR=RED>Sorry dude, work on your code !!&quot;;
}
 
Have you tried redirecting the output to the screen instead of to MySQL just to be sure the string you end up with is correct? You could then copy and paste from the browser to MySQL via PHPMyAdmin and see if you get errors
 
Actually, I think $table and $sql are separate variables, $table containing the table name and $sql containing the SQL to create the table. Have you tried concatenating the string (&quot; . $table . &quot;(&quot; . $sql . &quot;)&quot;), so you don't confuse PHP? //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top