mysql - No Database Selected Php -
this simple task, trying compare username in database. testing out in single php file before properly. code below. have user, in database , checking if in there.
<?php $db_connect = mysql_connect("127.0.0.1", "root", "anwesha01", "mis"); //check if connection worked. if(!$db_connect) { die("unable connect database: " . mysql_error()); } //for testing purposes only. else { echo "database connect success!"; } $user = "alj001"; $query = "select username `user` `username` = '".$user."'"; //what being passed through database. echo "<p><b>this being queried:</b> " . $query; //result if (mysql_query($query, $db_connect)) { echo "<br> query worked!"; } else { echo "<p><b>mysql error: </b><br>". mysql_error(); } ?>
the result is:
database connect success! this being queried: select username
user
username
= 'alj001'mysql error: no database selected
first had mysql_query without $db_connect above, put in , still "no database selected".
ive looked @ w3c schools mysql_query function, believe have done correctly. http://www.w3schools.com/php/func_mysql_query.asp
because haven't called mysql_select_db
. note the 4th parameter mysql_connect
not think is.
that said, you should using pdo
or mysqli
, not plain mysql_
functions, since they're deprecated.
Comments
Post a Comment