PHP MySQLI not inserting variable -


i trying create database user input,the problem while query believe correct doesnt create new database if try without using variable puting database name myself works variable doesnt.

<?php  $con = mysqli_connect("localhost","root","");  if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }   else{        echo "connected successfuly";   }  $postresult = $_post[dbname]; echo $postresult;  $runsql = $con->query("create database".$postresult."");  ?> 

the solution below fixed issue.

<?php  $con = mysqli_connect("localhost","root","");  if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }   else{        echo "connected successfuly";   }  $postresult = $_post['dbname']; echo $postresult;  $safestring = $con->real_escape_string($postresult);  $runsql = $con->query("create database ".$safestring."");  printf("errormessage: %s\n", $con->error); ?> 

remove space from.

$runsql = $con->query("create database".$postresult.""); 

database registered keyword. plus, it's put indexes in quotes unless you're referring variable defined using

define('var', 'my var'); 

so final code should like:

$postresult = $_post['dbname']; echo $postresult;  $runsql = $con->query("create database ".$postresult.""); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -