Some Poster55 Posted December 24, 2008 Share Posted December 24, 2008 Hi, I have a page where a user types in their username, and gets sent to another page where their account information is extracted from the database and displayed on the page. My database is set up so that each user has their own table. This all works fine, except obviously when someone who does not have their own table in the database types in and submits their name. Basically, I want the script to first check if the user's table already exists. But if it doesn't, I need it to create a table with that username as the table's name. Here's what I was trying: $user_table = mysql_real_escape_string($_POST["user_select"]); $result = mysql_query("SELECT * FROM $user_table WHERE id='1'") or die($create == 1); if ($create == 1) { mysql_query("CREATE TABLE $user_table( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(20))") or die(mysql_error()); } Basically, I just need to define a variable as a number if the original mysql query dies - but the above piece of code doesn't seem to be creating a new table if a non-existing name is submitted. I imagine it's possible to directly place the entire create table function within the Or Die(), but I need to specifically define $create as "1" if the original mysql query fails, as the $create variable will be used in other places. Help would be greatly appreciated, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/138349-solved-defining-a-variable-if-a-mysql-query-dies/ Share on other sites More sharing options...
JasonLewis Posted December 24, 2008 Share Posted December 24, 2008 Because you have die(), remove die, so that it becomes: $result = mysql_query("SELECT * FROM $user_table WHERE id='1'") or ($create = 1); I'm sure that's the syntax, because I did it once before. Quote Link to comment https://forums.phpfreaks.com/topic/138349-solved-defining-a-variable-if-a-mysql-query-dies/#findComment-723408 Share on other sites More sharing options...
Some Poster55 Posted December 24, 2008 Author Share Posted December 24, 2008 Ah, makes sense..thanks! Quote Link to comment https://forums.phpfreaks.com/topic/138349-solved-defining-a-variable-if-a-mysql-query-dies/#findComment-723410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.