Mysql_num_rows(); error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (website)
maar ik snap er niets van ik kan de fout in de code niet vinden kan iemand mij helpen
//CODE//
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once('bin.php');
require_once('config.php');
$lang= $_POST['lang'];
$user= $_POST['user'];
$pass = $_POST['pass'];
$ip= $_SERVER['REMOTE_ADDR'];
if ($_POST['action'] == '1'){
$link = mysql_connect("localhost", "$db_user", "$db_pass");
mysql_select_db("$db_name", $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = '$user' AND password = '$pass'", $link);
$num_rows = mysql_num_rows($result);
if (($num_rows == '1')){
session_start();
$_SESSION['username'] = '$user';
$_SESSION['acces'] = 'TRUE';
$_SESSION['time'] = time();
if (($lang == 'default')){
$lang = $row_users['language'];
header("Location:index3.php?lang='$lang'");
exit();
}
else if (($lang == $row_users['language'])){
header("Location:index3.php?lang='$lang'");
exit();
} else {
$query2 = "UPDATE users_systems SET language = '$lang' WHERE username = '$user'";
$execute = mysql_query($query2);
header("Location:index3.php?lang='$lang'");
exit();
}
} else {
$login = "failure";
}
}
?>
require_once('bin.php');
require_once('config.php');
$lang= $_POST['lang'];
$user= $_POST['user'];
$pass = $_POST['pass'];
$ip= $_SERVER['REMOTE_ADDR'];
if ($_POST['action'] == '1'){
$link = mysql_connect("localhost", "$db_user", "$db_pass");
mysql_select_db("$db_name", $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = '$user' AND password = '$pass'", $link);
$num_rows = mysql_num_rows($result);
if (($num_rows == '1')){
session_start();
$_SESSION['username'] = '$user';
$_SESSION['acces'] = 'TRUE';
$_SESSION['time'] = time();
if (($lang == 'default')){
$lang = $row_users['language'];
header("Location:index3.php?lang='$lang'");
exit();
}
else if (($lang == $row_users['language'])){
header("Location:index3.php?lang='$lang'");
exit();
} else {
$query2 = "UPDATE users_systems SET language = '$lang' WHERE username = '$user'";
$execute = mysql_query($query2);
header("Location:index3.php?lang='$lang'");
exit();
}
} else {
$login = "failure";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Identificeer u zelf</title>
<style type="text/css">
<!--
.style1 {
font-size: 14px;
font-weight: bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
</head>
<body onload="MM_popupMsg('Acces Denied')"><body>
<form action="index2.php" method="post" name="loginform">
<table width="547" border="0">
<tr>
<td colspan="2"><div align="center" class="style1">Login</div></td>
</tr>
<tr>
<td width="154"><span class="style2">Username:</span></td>
<td width="299"><label>
<input name="user" type="text" class="style2" id="user" size="30" maxlength="30" />
</label></td>
</tr>
<tr>
<td><span class="style2">Password:</span></td>
<td><label>
<input name="pass" type="password" class="style2" id="pass" size="30" maxlength="30" />
</label></td>
</tr>
<tr>
<td><span class="style2">interface Language</span></td>
<td><label>
<select name="lang">
<option value="default">User default</option>
<option value="NL">Nederlands</option>
<option value="EN">English</option>
</select>
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" value="Login" name="submit">
</label></td>
</tr>
</table>
<input name="Date" type="hidden" id="Date" value="" />
<input name="ip" type="hidden" id="ip" value="" />
<input name="action" type="hidden" id="action" value="1" />
</form>
</body>
</html>
//EIND CODE//
dit topic, ook daar ontbrak de foutafhandeling. Dat is de basis van ieder goed script, vergeet dan niet!
Zie http://www.php.net gekeken maar wat daar staat neem ik over en nog steeds de error
ja maar hoe moet het dan wel ik snap dit dus niet. ik heb op Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
$link = mysql_connect("localhost", "$db_user", "$db_pass");
mysql_select_db("$db_name", $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = '$user' AND password = '$pass'", $link);
$num_rows = mysql_num_rows($result);
?>
$link = mysql_connect("localhost", "$db_user", "$db_pass");
mysql_select_db("$db_name", $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = '$user' AND password = '$pass'", $link);
$num_rows = mysql_num_rows($result);
?>
Word bijvoorbeeld:
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
$link = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name, $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = ".$user." AND password = '".$pass."', ".$link) OR DIE(mysql_error());
$num_rows = mysql_num_rows($result);
?>
$link = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name, $link);
$result = mysql_query("SELECT * FROM users_systemen WHERE username = ".$user." AND password = '".$pass."', ".$link) OR DIE(mysql_error());
$num_rows = mysql_num_rows($result);
?>
En dit moet je ook doen bij je query2.
Gewijzigd op 01/01/1970 01:00:00 door Remy Brokke
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?
if($result){ // TRUE, dus de query is gelukt
// doe iets met $result
}
else { // query is mislukt, $result heeft geen inhoud en is onbruikbaar
echo mysql_error();
}
?>
if($result){ // TRUE, dus de query is gelukt
// doe iets met $result
}
else { // query is mislukt, $result heeft geen inhoud en is onbruikbaar
echo mysql_error();
}
?>
Zo moeilijk is het allemaal niet!
Gewijzigd op 01/01/1970 01:00:00 door Remy Brokke
You have an error in your SQL syntax near ' Resource id #4' at line 1
en ik heb users_system genomen en niet users_systemen wat remy schreef dus dat is het niet
Denk bijvoorbeeld aan OOP?
Maar zowiezo, je wilt toch zelf regelen wat er precies gebeuren moet..
Edit:
Antwoord voor Remy!
Antwoord voor Remy!
Gewijzigd op 01/01/1970 01:00:00 door Danny K
Komt nog eens bij dat het mislukken van een query of een query zonder resultaten, helemaal niet onverwacht is. Het is de gewoonste zaak van de wereld dat dingen mislukken of geen resultaat opleveren, anticipeer daar dan ook op.
Ik zal jullie commentaar in mijn volgende scripts mee opnemen! Bedankt!