can not create a database with PHP and my syntax i

2019-09-07 13:25发布

问题:

How is it is can not create a database on phpMyAdmin? I connect to PHP just fine, no error message. But when I am trying to create a database so phpMyAdmin, I keep getting error. In case it matters I have one page with a <form> and has a submit to my second.php file where my database code is (second.php is shown below).

I am pretty much trying to display the database in phpMyAdmin but nothing shows up:

<html>
    <body>
        <?php
            $con = mysqli_connect("localhost", "user", "password");
            if(!$con){
                echo "could not connect";
            } else {
                echo "good connection";
            }

            //creation of database
            $sql= 'CREATE DATABASE project';
            if(mysql_query($sql,$con)){
                echo 'DB created succesfully';
            } else {
                echo 'error creating DB' . mysql_errno();
            }
        ?>
    </body>
</html>

回答1:

One issue is you connected with mysqli and are using mysql the rest of the time. Pick 1 (not mysql) library and use only that.

if(mysqli_query($con, $sql)){

and

echo 'error creating DB' . mysqli_error($con);