php - duplicate database name won't echo else condition -
this code create database in sql
using input forms.
<?php //connect sql $conn = new mysqli('127.0.0.1','root',''); if( $conn -> connect_error ){ echo $conn -> connect_error; die('connection unsuccessful'); } echo 'connection sucessful'; ?> <!-- ==================================================================== --> <form action="" method="post"> <input type="text" name="db_name"> <input type="submit" value="create database"> </form> <?php //create database if( isset( $_post["db_name"] ) && $dbname = $_post["db_name"] ) if( $conn -> query("create database if not exists " . $dbname ) === true ) echo 'database created sucessfully'; else echo 'database ' . $dbname . ' exists. please try name'; //this line won't execute ?>
in case of entering duplicate database name, want echo
last line. don't know why not executing. help?
note: entering duplicate name won't create anything, page says "database created succesfully"
<?php //create database if( isset( $_post["db_name"] ) && $dbname = $_post["db_name"] ) if( $conn -> query("create database " . $dbname ) === true ) echo 'database created sucessfully'; else echo 'database ' . $dbname . ' exists. please try name'; //this line won't execute ?>
this should it, if you're using "if not exists" query successfully, if you're trying creat database name existing query fail, , not return true.
Comments
Post a Comment