<?php
//page2
session_start();
if (session_is_registered('usuario')){
}
else{
header("Location: acceso6.html?errorusuario=si");
}
$session= session_id();
$base="";
$conexion=mysql_connect("","","");
mysql_select_db($base,$conexion);
$pegar2 = "SELECT Inmo FROM Sesiones WHERE Sesion='$session'";
$row = mysql_fetch_array($pegar2);
$Inmo = $row["Inmo"];
?>
ERROR:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /chs/p1/costa4seasons.com/home/html/panelcontrol.html on line 13
?>
Why this error?
Moderator: General Moderators
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
As microthick said, you need to query the database before trying to work with the result. You would also probably find it helpful to put error handling in and use non-register globals dependant code:
Mac
Code: Select all
<?php
session_start();
// check for the value in the $_SESSION array, don't use the deprecated
// function session_is_registered()
if (empty($_SESSION['usuario'])){
header('Location: acceso6.html?errorusuario=si');
// put the exit() call in to ensure that the code does not continue
// executing - it's a failsafe.
exit();
}
$session = session_id();
$base = '';
// put error handling in to make sure that problems are easy to identify
// and deal with
$conexion = mysql_connect('', '', '') or die(mysql_error());
mysql_select_db($base, $conexion) or die(mysql_error());
$pegar2 = "SELECT Inmo FROM Sesiones WHERE Sesion='$session'";
// here's the mysql_query() call you were missing, it also has error
// handling just in case the query does not work as expected.
$result = mysql_query($pegar2) or die(mysql_error().'<p>'.$pegar2.'</p>');
// you need to check that there was a result before trying to do anything
// with the returned data
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($pegar2);
$Inmo = $row['Inmo'];
// rest of code...
} else {
// give a message if the session doesn't exist or maybe run the same
// redirect code as before.
echo 'That session does not exist!';
}
?>