Jump to content
  • 0

Выборка, помогите


Golgi
 Share

Question

<?php session_start(); 
$dbhost = "localhost";
$dbuser = "admin";
$dbpass = "school";
$dbname = "e_school";

$db = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$db) {
die('Не могу подключится: ' . mysql_error());
}
mysql_select_db($dbname,$db);

if (isset($_POST['login']) && ($_POST['login'] !== '')) {$login = trim($_POST['login']);} else { die('<p class="error">Пустое поле Логин</p>');}
if (isset($_POST['password']) && ($_POST['password'] !== '')) {$password = trim($_POST['password']);} else { die('<p class="error">Пустое поле пароль</p>');}

$login = stripslashes($login);
$login = htmlspecialchars($login);
$password = stripslashes($password);
$password = htmlspecialchars($password);
$password = md5($password);

$base = mysql_query("SELECT id,password,fname,lname FROM sc_user_profiles WHERE login='$login'",$db);
$fun1 = mysql_fetch_array($base);

if ($fun1['password'] == $password)
{
$_SESSION['login'] = $login;
$_SESSION['password'] = $password;
$_SESSION['id'] = $id;
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
echo "Fuck yea!";
}

?>

Пишет ошибку Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in X:\home\e-school.ru\www\login.php on line 14

не пойму в чем проблема(

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

mysql_fetch_array не любит работать со значением false.


mysql_select_db($dbname,$db) or die('mysql_select_db error');
...
$base = mysql_query("SELECT `id`,`password`,`fname`,`lname` FROM `sc_user_profiles` WHERE `login`='$login'",$db) or die('mysql_query error');

Замечу, что в запросе названия полей и таблиц лучше заключать в `косые кавычки`, а строковые значения полей - 'в прямые'.

  • Like 1
Link to comment
Share on other sites

  • 0

проблема до сих пор актуальна

Проблема в вашем запросе, проверьте его правильность. mysql_fetch_array() должен получать результат запроса, а в вашем случае,как уже написал Radiocity он скорее всего получает false.

Чтобы понять ошибку напишите запрос вот так


$base = mysql_query("SELECT id,password,fname,lname FROM sc_user_profiles WHERE login='$login'",$db) or die(mysql_error());

и включите отображение всех ошибок, если еще не включено

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy