MySQL Forums
Forum List  »  PHP

Re: Need help with php variables in MySQL Query
Posted by: Ryan Shast
Date: July 20, 2008 08:49AM

I also tried what you did, and it worked:

$user2 = "1234567890";
$name2 = "John Smith";
$review = 'CREATE table `' . $user2 . '` (name char(30) NOT NULL)';
mysql_query( $review );
$addinfo = "INSERT INTO `" . $user2 . "` (name) VALUES ('" . $name2 . "')";
mysql_query( $addinfo ) or die(mysql_error());

I got no errors and in my MySQL database there was a table named 1234567890 with a row called name, and data known as "John Smith".

But I am not using directly-defined variables, I am grabbing the $user variable from another .php page using the "require_once" method, and it seems to be working when making the table, but I don't know if it isn't working for the "insert into" query.

This is what I have set to the other variable:
$name="<fb:name uid='$user' useyou='false' linked='false' firstnameonly='true'/>"

The above is a tag for a library I downloaded and installed on my server for making a Facebook application. $user is grabbed from a page within the library.
If I did this:

echo ("<fb:name uid='$user' useyou='false' linked='false' firstnameonly='true'/>")

It would print "Ryan" on the .php page when called, So it is working. But maybe there is a problem with storing $user inside $name and then calling both variables $name and $user. I hope this helps!

Thanks for replying! Because of you, I was able to figure out that it was the variables that were faulty, not the structure of the query.

~Ryan

Options: ReplyQuote


Subject
Written By
Posted
Re: Need help with php variables in MySQL Query
July 20, 2008 08:49AM
July 20, 2008 09:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.