Page 1 of 1

Returning to same userid? [Solved]

Posted: Tue Apr 17, 2007 3:27 am
by jmansa
I'm trying to make an updatescript, and after finishing the update I want to go back to the main page for the same user. I have tryid this, but it doesnt work...

Code: Select all

$ClubID=$_POST['ClubID'];
$Region=$_POST['Region'];
$Letter=$_POST['Letter'];
$ClubName=$_POST['ClubName'];

$dbhost = 'myhost';
$dbuser = 'username;
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'database';
mysql_select_db($dbname);

$query="UPDATE clubs SET ClubID='$ClubID', Region='$Region', Letter='$Letter', ClubName='$ClubName' WHERE ClubID='$ClubID'";
mysql_query($query);

if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}
echo "Club Updated...";


echo '<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="refresh" content="1;URL=http://www.mypage.com/admin/index.php?clubid=' .$query['ClubID']. '">
<title>Clubadmin - Aproved</title>
</head>';
mysql_close();
In my adress field I get this.
Can't find my error???

Posted: Tue Apr 17, 2007 5:38 am
by CoderGoblin
The normal method of redirecting the user with php is to use header.

Code: Select all

<?php
//  processing code goes here
..
..
if ($ok) {
  header("Location:http://page_to_jump_to.html?options");
  exit;
}
..
..
..

// Output html block
..
..
?>
Note: for header to work no output should be before it. Even an empty line will cause the header redirect to fail. the <?php tag must therefore be at the top of the file. You may need to adjust coding style to allow for this.

To answer your specific query however shouldn't $query['ClubID'] be just $ClubID in the url?

Posted: Tue Apr 17, 2007 6:54 am
by jmansa
I have tryid this:

Code: Select all

if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}

if ($ok) { 
  header("Location:http://www.mypage.com/index.php?clubid=$ClubID"); 
  exit; 
} 
mysql_close();
But nothing happens? Why?

Posted: Tue Apr 17, 2007 8:08 am
by mentor
You are missing a quote in

Code: Select all

$dbuser = 'username;
see if this condition evaluates to true

Code: Select all

if ($ok)
If still have the problems, post your current code.

Posted: Tue Apr 17, 2007 8:27 am
by jmansa
My code looks like this:

Code: Select all

<?
$ClubID=$_POST['ClubID'];
$ClubName=$_POST['ClubName'];

$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'database';
mysql_select_db($dbname);

$query="UPDATE clubs SET ClubID='$ClubID', ClubName='$ClubName' WHERE ClubID='$ClubID'";
mysql_query($query);

if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}

if ($ok) { 
  header("Location:http://www.mypage.com/index.php?clubid=$ClubID"); 
  exit; 
} 
mysql_close();
?>
Hope that helps...

Posted: Tue Apr 17, 2007 8:34 am
by mentor
$ok is undefined. Your condition evaluates to false

Code: Select all

if ($ok)
You are executing query twice.

Try something

Code: Select all

if(mysql_affected_rows()==-1){ 
	print "Error Occurred:". mysql_error() ; 
	exit(); 
} 

header("Location:http://www.mypage.com/index.php?clubid=$ClubID"); 
exit;

Posted: Tue Apr 17, 2007 9:13 am
by jmansa
Great... That did the job, but... How do I make it pause for about 2 sec. telling the user that the update has been aproved?

Posted: Tue Apr 17, 2007 9:23 am
by feyd
It's not possible to delay the redirection when using header(). You will need to use meta-tag based redirection if you wish to delay it.