I'm intending on having my php file query to have a table created on my database if one doesn't already exist. I've used the following below but I seem to get the error Warning: mysqli_query(): Empty query for the same php. What am i doing wrong?
$query = "";
$result = mysqli_query($conn, $query);
if(empty($result)) {
$query = "CREATE TABLE orders(order_id int(11) AUTO_INCREMENT, order_cost int(11), order_time timestamp CURRENT_TIMESTAMP, order_firstname varchar(15), order_lastname varchar(40), order_phone int(10), order_email varchar(40), order_card int(16), order_status varchar(9)";
echo $query;
$result = mysqli_query($conn, $query);
}
You should use CREATE TABLE IF NOT EXISTS
to eliminate the error that occurs when you create a table with same name multiple times
Hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.