2017-01-22 6 views
0

イムは完全にこのエラーによりconfised:MySQLのnum個の行のヘルプ問題

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\le\login.php on line 10

いずれかが私を助けることができますか?私はあなたがDBとの対話にmysqliのを使用することをお勧めし

<?php 
$username = $_POST['username']; 
$password = $_POST['password']; 

if ($username&&$password) 
{ 
$connect = mysql_connect("localhost", "root", "") or die("Could'nt Connect"); 
$query = mysql_query("SELECT * FROM users WHERE username='$username'"); 
mysql_select_db("shit") or die("cant find db"); 
$numrows = mysql_num_rows($query); 
echo $numrows; 
} else 
    die("please enter username and a password"); 

?> 
+1

クール、あなたはそれを選択する前に、データベースを照会します。 –

+0

@u_mulder phpmyadminの画像ですか? –

+0

'$ query'の前に' mysql_select_db'を移動してください。また、SQLインジェクションも可能です。 – chris85

答えて

0

:私はPHPで

コード新たなんです。 mysql_queryは非推奨です。ここではドキュメントを参照してください:http://php.net/manual/en/function.mysql-query.php

あなたが行うことができますmysqliのでDBに接続するには:

$DBhost = "localhost"; 
$DBuser = "your-user"; 
$DBpass = "your-password"; 
$DBName = "your-db-name"; 

// Create connection 
$mysqli = new mysqli($DBhost, $DBuser, $DBpass, $DBName); 

// Check connection 
if ($mysqli->connect_error) { 
    die("Connection failed: " . $mysqli->connect_error); 
} 
+1

はい、問題ありませんが、すべてのOPのコードを変換することなく、これはむしろ役に立たないです。 – RiggsFolly

+0

誰かが既にコメントの質問に回答しました。ベストプラクティスで同じことをする別の方法を指摘しただけです。私はコメントを残していただろうが、私は最近スタックオーバーフローに登録しているので、できなかった。 – al27091