Member Avatar for tqmd1

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

Member Avatar for Stefce

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);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.