migroo Posted January 31, 2010 Share Posted January 31, 2010 Okay I don't know if this is the correct way of using PHP variables in my mysql code: $sql = "CREATE TABLE zpost_".$t.$r." ( ID int NOT NULL AUTO_INCREMENT, Content text, Date VARCHAR(20), PRIMARY KEY (ID) )"; // Execute query mysql_query($sql,$con); Its not creating the database.I declare the variables in the header. $t is a name I have the user impute in a forum and $r is a random number.Thanks!P.S Not sure if I should post this here or in the PHP thread. If this is the wrong place please tell me. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted January 31, 2010 Share Posted January 31, 2010 Yes you can use variables but you dont need all the "".... business when in a mysql query, you can just use the variableBest to try and combine your varibles before hand though, then you only have 1 variable that is the complete table name rather than part text and part variable combo in the mysql query Link to comment Share on other sites More sharing options...
migroo Posted January 31, 2010 Author Share Posted January 31, 2010 Okay here is what I have done: $m="zpost_".$t.$r;$sql = "CREATE TABLE $m; ( ID int NOT NULL AUTO_INCREMENT, Content text, Date VARCHAR(20), PRIMARY KEY (ID) )"; I have it echo my $m variable and it looks like it should but it still is not creating my data table. Also if I don't use the $m and instead I just write test it creates the data table test. I don't know what I am doing wrong. Link to comment Share on other sites More sharing options...
migroo Posted January 31, 2010 Author Share Posted January 31, 2010 I figured it out I just needed to omit the semicolon after the $m variable. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted January 31, 2010 Share Posted January 31, 2010 Its not a semicolon its an evil pair of eyes winking at you Link to comment Share on other sites More sharing options...
migroo Posted January 31, 2010 Author Share Posted January 31, 2010 Lol yup. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.