Where's the mistake?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Where's the mistake?

Post 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);   
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply