advancedfuture Posted May 3, 2008 Share Posted May 3, 2008 I wrote the code below to so when a form is submitted it uploads the form data to the database then directs the user to a specific page afterwards. The database query uploads just fine. But the headers dont work. It just sends the user back to the page they are on. Now if i use meta tags to refresh instead of headers it works no problem. But that is kind of a bastardized way of doing it. What am I doing wrong in the code below. **Note this is just a small overview of the total code. <?php include 'ealcontacts.php'; if($_POST['submit']) { $fname = $_POST['fname']; $lname = $_POST['lname']; $contact1 = $_POST['contact1']; $method1 = $_POST['method1']; $contact2 = $_POST['contact2']; $method2 = $_POST['method2']; $query = "INSERT INTO contacts SET fname='$fname', lname='$lname', contact1='$contact1', method1='$method1', contact2='$contact2', method2='$method2'"; $results = mysql_query($query); if($results) { header( 'Location: listingthankyou.php?idnumber='.$row->idnumber.''' ); } else { header( 'Location: siteerror.php' ); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/ Share on other sites More sharing options...
BlueSkyIS Posted May 3, 2008 Share Posted May 3, 2008 drop the single-quoted single-quote: header( 'Location: listingthankyou.php?idnumber='.$row->idnumber); Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532193 Share on other sites More sharing options...
redarrow Posted May 3, 2008 Share Posted May 3, 2008 valadate that insert as well............. mysql_real_escape_string() function on those posting varables Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532195 Share on other sites More sharing options...
advancedfuture Posted May 3, 2008 Author Share Posted May 3, 2008 well I made the change to the header with the quotes, still just sits on the page. I dont have the SQL validation, but I know that it is working because I am seeing the results hit the database each time I hit submit. 0.o Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532196 Share on other sites More sharing options...
advancedfuture Posted May 3, 2008 Author Share Posted May 3, 2008 I changed the code a bit more to add error checking to SQL insert... no errors. new code changes Also.. i know its not the URL in the header() because for error testing i tried www.google.com and that still made the page refresh onto itself. <?php include 'ealcontacts.php'; if($_POST['submit']) { $fname = $_POST['fname']; $lname = $_POST['lname']; $contact1 = $_POST['contact1']; $method1 = $_POST['method1']; $contact2 = $_POST['contact2']; $method2 = $_POST['method2']; $query = "INSERT INTO contacts SET fname='$fname', lname='$lname', contact1='$contact1', method1='$method1', contact2='$contact2', method2='$method2'"; $results = mysql_query($query); if (!$results) { die('Invalid query: ' . mysql_error()); } else { header( 'Location: listingthankyou.php?idnumber='.$row->idnumber); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532197 Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 Where are you getting $row from? Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532202 Share on other sites More sharing options...
FlyingIsFun1217 Posted May 3, 2008 Share Posted May 3, 2008 It sounds like you don't really like hack-ish methods, but in my experience, I've found javascript redirects work quite nicely. FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532205 Share on other sites More sharing options...
advancedfuture Posted May 3, 2008 Author Share Posted May 3, 2008 Earlier in the page before some HTML that seperates the aformentioned code I get $row->idnumber from here. <? $query = "SELECT * FROM Listings WHERE idnumber ='$idnumber'"; $results = mysql_query($query); while($row = mysql_fetch_object($results)) { echo '<tr><td>'; echo '<img src="Images/'.$row->idnumber.'a.jpg" width="255" height="150 border="0"></td>'; echo '<td>'; echo '<img src="Images/'.$row->idnumber.'b.jpg" width="255" height="150 border="0"></td></tr>'; echo '<tr><td width="550" height="100" bgcolor="#ffffff" align="right" colspan="2">'; echo '<br>Studio Apartment: <font size="2"><i>'.$row->studiosqft.'</font></i> Sq. Ft. <font size="2"><i>$'.$row->studioprice.'</font>/m </i><br>'; echo '1 Bedroom '.$row->bathroom1.' Bathroom Apartment: <font size="2"><i>'.$row->sqft1.'</font></i> Sq. Ft. <font size="2"><i>$'.$row->price1.'</font>/m </i><br>'; echo '2 Bedroom '.$row->bathroom2.' Bathroom Apartment: <font size="2"><i>'.$row->sqft2.'</font></i> Sq. Ft. <font size="2"><i>$'.$row->price2.'</font>/m </i><br>'; echo '3 Bedroom '.$row->bathroom3.' Bathroom Apartment: <font size="2"><i>'.$row->sqft3.'</i> Sq. Ft. <font size="2"><i>$'.$row->price3.'</font>/m </i><br>'; echo '<br><div align ="left"><font size="2">'.$row->details.'</font><br><br></td></tr>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532208 Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 Here's how I'd debug this: Change the header line to: echo "Inside of the ELSE conditional, query succeeded.<br />What's going into the header: Location: listingthankyou.php?idnumber={$row->idnumber}"; See what it says, or if it even gets up to that point, and if it's providing the correct URL. Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532210 Share on other sites More sharing options...
advancedfuture Posted May 3, 2008 Author Share Posted May 3, 2008 ok well I commented out the header() and replaced it with an echo.... the echo executes no problem so there is a problem with: header( 'Location: listingthankyou.php?idnumber='.$row->idnumber); but I know it is not the variable, because I tried header('Location: www.google.com' ); to no avail! Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532215 Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 I always use double quotes with headers. Probably does nothing, but I don't really know. And use absolute URLs or some browsers don't take the header. $url = "http://www.domain.com/path/file.php?idnumber={$row->idnumber}"; header("Location: $url"); That's how I always do it. Try making a variable and using THAT in the header. It worked for someone's problem with exec() once. Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532217 Share on other sites More sharing options...
advancedfuture Posted May 3, 2008 Author Share Posted May 3, 2008 well i fixed the issue in a different way. Rather than grabbing it from earlier in the page. I just used $_GET['idnumber']; to pull it from the URL again. It's kinda funky way of doing it if i showed you the whole page. but it works nonetheless... Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532225 Share on other sites More sharing options...
DarkWater Posted May 3, 2008 Share Posted May 3, 2008 $row must have been messed up or something. =P Glad you got it to work. Quote Link to comment https://forums.phpfreaks.com/topic/103954-solved-error-getting-redirecting-to-work-on-if-statement/#findComment-532226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.