php mysql database connection error -
i have following php code gets user login details html form:
$con=mysqli_connect("host","user","pass","db"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $query = "select username users user='$_post[username]' limit1"; $result = mysql_query($query); echo result;
but when run it, seem getting these errors:
warning: mysql_query() [function.mysql-query]: can't connect local mysql server through socket '/directory omitted' (2) in /directory omitted on line 10
warning: mysql_query() [function.mysql-query]: link server not established in /directory omitted on line 10
can please out? much!
you have mixed mysqli
mysql
there's lot of typos
code should be:
$con = mysqli_connect("host","user","pass","db"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $u = $_post['username']; $sql = "select username users user='$u' limit 1"; $query = mysqli_query($con, $sql); if ($row = mysqli_fetch_assoc($query)) { echo $row['username']; }
hope worked.
or if need rows printed should be:
while ($row = mysqli_fetch_assoc($query)) { echo $row['username']; }
Comments
Post a Comment