PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jmansa
Forum Commoner
Posts: 81 Joined: Wed Aug 23, 2006 4:00 am
Post
by jmansa » Tue Apr 17, 2007 3:27 am
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???
Last edited by
jmansa on Tue Apr 17, 2007 9:25 am, edited 1 time in total.
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Tue Apr 17, 2007 5:38 am
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?
jmansa
Forum Commoner
Posts: 81 Joined: Wed Aug 23, 2006 4:00 am
Post
by jmansa » Tue Apr 17, 2007 6:54 am
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?
mentor
Forum Contributor
Posts: 100 Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan
Post
by mentor » Tue Apr 17, 2007 8:08 am
You are missing a quote in
see if this condition evaluates to true
If still have the problems, post your current code.
jmansa
Forum Commoner
Posts: 81 Joined: Wed Aug 23, 2006 4:00 am
Post
by jmansa » Tue Apr 17, 2007 8:27 am
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...
mentor
Forum Contributor
Posts: 100 Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan
Post
by mentor » Tue Apr 17, 2007 8:34 am
$ok is undefined. Your condition evaluates to false
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;
jmansa
Forum Commoner
Posts: 81 Joined: Wed Aug 23, 2006 4:00 am
Post
by jmansa » Tue Apr 17, 2007 9:13 am
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Apr 17, 2007 9:23 am
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.