Page 1 of 1

Where's the mistake?

Posted: Tue Nov 25, 2003 9:18 am
by Perfidus
I get the following error message processing this page, but I can't see where's the mistake:
Parse error: parse error in /chs/p1/costa4seasons.com/home/html/renamesession.php on line 19

Code: Select all

<?php
session_start();
$oldsession=session_id();
$link = mysql_connect('', '', ''); 
mysql_select_db("",$link); 
$result = mysql_query("SELECT Inmo FROM Sesiones WHERE (Sesion='$oldsession')", $link); 
while($row = mysql_fetch_array($result)) { 
$Inmo=$row["Inmo"];
$rs = mysql_query($result,$link); 
if (mysql_num_rows($rs)!=0){ 
} 
session_regenerate_id();
$session=session_id();  
$Fecha = date("Y-d-m h:i:s"); 
$sql = "INSERT INTO Sesiones ( Fecha, Inmo, Sesion)" .   
"VALUES ('$Fecha', '$Inmo', '$session')";   
$result2 = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');   
header ("Location: panelcontrol.html");   
}else {   ///ERROR SUPOSED TO BE HERE!!!
header("Location: acceso6.html?errorusuario=si");   
}   
mysql_close($link);   
?>

Posted: Tue Nov 25, 2003 9:27 am
by d3ad1ysp0rk
your if statement doesnt have anything in it.

Code: Select all

if(mysql_num_rows($rs)!=0){
}
it closes before doing anything.

im assuming you want to do everything up to the else statement if the conditions are met? then do this:

Code: Select all

<?php 
session_start(); 
$oldsession=session_id(); 
$link = mysql_connect('', '', ''); 
mysql_select_db("",$link); 
$result = mysql_query("SELECT Inmo FROM Sesiones WHERE (Sesion='$oldsession')", $link); 
while($row = mysql_fetch_array($result)) { 
$Inmo=$row["Inmo"]; 
$rs = mysql_query($result,$link); 
if (mysql_num_rows($rs)!=0){  
session_regenerate_id(); 
$session=session_id();  
$Fecha = date("Y-d-m h:i:s"); 
$sql = "INSERT INTO Sesiones ( Fecha, Inmo, Sesion)" .    
"VALUES ('$Fecha', '$Inmo', '$session')";    
$result2 = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');    
header ("Location: panelcontrol.html");    
}
else {   
header("Location: acceso6.html?errorusuario=si");    
}    
mysql_close($link);    
?>
and don't forget to end your while (add another closing bracket somewhere near the end), i'd put it in, but im not sure what you're trying to do

good luck

Posted: Tue Nov 25, 2003 9:53 am
by twigletmac
To add to what LiLpunkSkateR has posted, you will find that the problem becomes much more evident if you indent your code and add some whitespace:

Code: Select all

<?php
session_start();

$oldsession = session_id();

$link = mysql_connect('', '', '');
mysql_select_db('', $link);

$result = mysql_query("SELECT Inmo FROM Sesiones WHERE (Sesion='$oldsession')", $link);

while ($row = mysql_fetch_array($result)) {
	$Inmo = $row['Inmo'];
	$rs = mysql_query($result,$link);

	if (mysql_num_rows($rs)!=0){
	
	}

	session_regenerate_id();
	$session = session_id(); 
	$Fecha = date("Y-d-m h:i:s");
	$sql = "INSERT INTO Sesiones ( Fecha, Inmo, Sesion) VALUES ('$Fecha', '$Inmo', '$session')";   

	$result2 = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');   
	header ("Location: panelcontrol.html");   
} else {   ///ERROR SUPOSED TO BE HERE!!!
	header("Location: acceso6.html?errorusuario=si");   
}   
mysql_close($link);   
?>
If you make the changes suggested it looks like this:

Code: Select all

<?php
session_start();

$oldsession = session_id();

$link = mysql_connect('', '', '');
mysql_select_db('', $link);

$result = mysql_query("SELECT Inmo FROM Sesiones WHERE (Sesion='$oldsession')", $link);

while ($row = mysql_fetch_array($result)) {
	$Inmo = $row['Inmo'];
	$rs = mysql_query($result,$link);

	if (mysql_num_rows($rs)!=0){
		session_regenerate_id();
		$session = session_id(); 
		$Fecha = date("Y-d-m h:i:s");
		$sql = "INSERT INTO Sesiones ( Fecha, Inmo, Sesion) VALUES ('$Fecha', '$Inmo', '$session')";

		$result2 = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
		header ("Location: panelcontrol.html");
	} else {
		header("Location: acceso6.html?errorusuario=si");
	}
}

mysql_close($link);
?>
Mac