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
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).

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.