Hangwire Posted September 13, 2010 Share Posted September 13, 2010 Hi, I need a quick tip. I want this script to produce an output of "Table created" if it succesfully creates a table. <?php $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create table mysql_select_db("my_db", $con); $sql = "CREATE TABLE People ( FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql,$con); mysql_close($con); ?> I tried to do it on my own, but I guess I'm still completely new to php I tried: <?php $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create table if (mysql_select_db("my_db", $con)) { echo "Table created"; } else { echo "Error creating Table: " . mysql_error(); } $sql = "CREATE TABLE People ( FirstName varchar(15), LastName varchar(15), Age int )" // Execute query mysql_query($sql,$con); mysql_close($con); ?> It gave me an error with the last two lines mysql_query($sql,$con); mysql_close($con); I removed them and it really did give the output "Table created" yet it didn't create the table in the database. I'm having a feeling that I need to add an "if" statement, something of the sort. if (sql(CREATE TABLE Persons)) But I'm also getting the feeling something there is wrong, I still haven't tried it. Help? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/213331-output-to-create-table/ Share on other sites More sharing options...
Hangwire Posted September 13, 2010 Author Share Posted September 13, 2010 bump? Quote Link to comment https://forums.phpfreaks.com/topic/213331-output-to-create-table/#findComment-1110758 Share on other sites More sharing options...
mikosiko Posted September 13, 2010 Share Posted September 13, 2010 The answer is simple... go back to the first code that you posted and take a look here http://php.net/manual/en/function.mysql-query.php and read carefully the part about "Return Values".... the answer will came up to you clear as water.... fresh water. Quote Link to comment https://forums.phpfreaks.com/topic/213331-output-to-create-table/#findComment-1110768 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.