0

Sir I have following codes to create table

<?php
function create_table(){
$query = "CREATE TABLE IF NOT EXISTS country (
id INT(6) not null AUTO_INCREMENT PRIMARY KEY, 
name VARCHAR(30) NOT NULL, reg_date TIMESTAMP)";

$host = "localhost";
$db = "mysql";
$user = "root";
$pass = "";
$conn = mysqli_connect($host, $db,$user, $pass) or trigger_error(mysqli_error(),E_USER_ERROR); 

$result=mysqli_query($conn,$query);
$count=mysqli_num_rows($result); 

        if($count==1)
        {
            echo ('<script>alert("Table created")</script>');
        }
    }
?>

<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#button").click(function(){
create_table();
});
});
</script>
</head>

<body>
<input type="submit" name="button" id="button" value="Create Table">
</body>
</html>

The codes are not working.
Please help me to sort out.

Thanks

Edited by tqmd1

2
Contributors
1
Reply
14
Views
1 Year
Discussion Span
Last Post by Stefan_1
0

You have misstake in mysqli_connect order $conn = mysqli_connect($host, $db, $user, $pass) should be like this $conn = new mysqli_connect($host, $db, $pass, $user);

Edited by Stefan_1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.