Jump to content

Reditecting pages based on logic


SpringVark

Recommended Posts

Newbie here, apologies in advance!

 

I am trying to use the header function to forward one of any number of locations (taken from a db) based on the value of a response param:

 

<?php include '../include/db/db-open.php'; ?>

<?php

    $postTypeId = $_POST['postTypeId'];

    $postTypesResults  = $mysqli->query("select id, editPageUrl from post_types where active = 1");

?>

<?php include '../include/db/db-close.php'; ?>

<?php

    while ($postTypesResult = $postTypesResults->fetch_object()) {

        if ($postTypesResult->id == $postTypeId) {

            header("Location: ".$postTypesResult->editPageUrl);

        }

    }

?>

 

The value of $postTypeId is always blank if echoed (explining why the condition to forward is never met).

 

Two questions:

[*]Is there anything obvious I am doing wrong causing $postTypeId to always be blank?

[*]Can the header function be used in this way?

 

Thanks for any help!

 

Link to comment
https://forums.phpfreaks.com/topic/178133-reditecting-pages-based-on-logic/
Share on other sites

Hi

 

Yes, I have echoed $postTypeId and the result is nothing. The page it is coming from includes a select tag with name="postTypeId";

 

Is the MySql WHERE function you describe a php function? And if so, how would I use it? I only ask out of ignorance (my sql did include a where clause).

I mean kind of like this (also changed some other stuff to make it look nicer).

 

<?php
include '../include/db/db-open.php';

$postTypesResults = $mysqli->query("SELECT editPageUrl FROM post_types WHERE active = 1 AND id = " . ((int) $_POST['postTypeId']) . " LIMIT 1");

include '../include/db/db-close.php';

if ($postTypesResult = $postTypesResults->fetch_object()) {
header("Location: ".$postTypesResult->editPageUrl);
exit;
}
else {
echo 'Link not found';
}

 

Yes, I have echoed $postTypeId and the result is nothing. The page it is coming from includes a select tag with name="postTypeId";

 

Are you sure it's submitting using POST and not GET?

The result of the var_dump:

array(8) { ["postTypeId"]=>  string(0) "" ["publisher"]=>  string(0) "" ["author"]=>  string(0) "" ["title"]=>  string(0) "" ["tagline"]=>  string(0) "" ["content"]=>  string(0) "" ["dateToPublish"]=>  string(0) "" ["dateToExpire"]=>  string(0) "" } Link not found

 

Very weird as most of those other fileds are simply text boxes (some of which I'd filled in).

 

db-open.php shouldn't cause any problems:

<?php
    $mysqli = new mysqli('localhost','auser','password','dbname');
?>

 

I'm stumped.

I LIED in my previous post - those input text field values DID come through:

array(8) { ["postTypeId"]=>  string(0) "" ["publisher"]=>  string(4) "Jill" ["author"]=>  string(4) "Jack" ["title"]=>  string(11) "Jack & Jill" ["tagline"]=>  string(12) "Go Up a hill" ["content"]=>  string(0) "" ["dateToPublish"]=>  string(0) "" ["dateToExpire"]=>  string(0) "" } Link not found

 

So it looks like the problem must be with my select list...

 

*rushes off to take another look-see*

Here's the first bit:

 

<form name="defaultForm" method="post" action="/skydive/admin/editPostForward.php">
<table border="0" cellpadding="5">
<thead>
<tr>
	<th>Field</th>
	<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
	<td>Post Type</td>

	<td>
	<select name="postTypeId">
		<option value="1">News Item</option>
		<option value="2">Weekend Report</option>
		<option value="3">Notice</option>
		<option value="4">Site Page: About</option>
		<option value="5">Site Page: Static Line</option>
	</select>
	</td>
</tr>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.