ludo1960 Posted January 16, 2019 Share Posted January 16, 2019 (edited) I have the following code, The table 'TEST' is not created but the code reports "Table has been created" Any idea what is wrong? <?php $conn = mysqli_connect("localhost","myuser","mypassword","mydatabase"); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $create_table = "CREATE TABLE IF NOT EXIST `TEST` ( ID INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, County VARCHAR(50) NOT NULL, Country VARCHAR(50) NOT NULL )"; $create_tbl = $conn->query($create_table); if ($create_table) { echo "Table has been created"; } else { echo "error!!"; } Edited January 16, 2019 by ludo1960 Quote Link to comment Share on other sites More sharing options...
Barand Posted January 16, 2019 Share Posted January 16, 2019 Of course it tells you it has been created. You are creating a atring variable then checking if there is a value in it. To check creation of the table you need to check the query result - $create_tbl And it should be "EXISTS", not "EXIST" Quote Link to comment Share on other sites More sharing options...
ludo1960 Posted January 16, 2019 Author Share Posted January 16, 2019 Thank you for spotting my errors, all working nicely now. Cheers! Quote Link to comment 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.