Myspace Codes - Free mobile phone's stuffs - Loans - Mortgage Loans - Shares

PDA

View Full Version : lost $id variable in $_POST statement


gregorious
Jul 31st 2007, 8:23 pm
I am trying to get some radio buttons to work, but before I even got into the logic of radio buttons I ran into a snag with my $id variable not being avaiable for the whole page [speifically - the top $_POST portion of the page].

Below is a condensed version of my page code. There is are two variables passed to this page from the previous page: $id and $imageid



<html>

<head>
<title>Untitled 3</title>
</head>
<body>

<?php
if (isset($_POST['editimage'])):
$imageresorder = $_POST['imageresorder'];
$imagerescaption = $_POST['imagerescaption'];
$imageid = $_POST['imageid'];


$sqlupdate = "UPDATE image_res SET
image_res_order='$imageresorder',
image_res_caption='$imagerescaption'
WHERE image_id='$imageid'";

if (@mysql_query($sqlupdate)) {

echo "Residential IMAGE updated!";

} else {

echo "Error UPDATING database " . mysql_error() . "Call webmaster";
}


// $setfeaturepic = "UPDATE residential SET
// res_feature_pic='$imageid',
// res_id='$id'
// WHERE res_id='$id'";

// if (!mysql_query($setfeaturepic)) {
// echo ("<p>Error UPDATING Feature Picture!"
// . $imageid . "Call webmaster");
// }

?>


<?php

else:

$id = $_GET['id'];
$imageget = @mysql_query("SELECT
image_id,
image_res_id,
image_res_order,
image_res_caption
FROM image_res, residential
WHERE image_res_id='$id' AND image_id='$imageid'");

if (!$imageget) {
echo("Error SELECTING data from database!" . mysql_error() . "Call webmaster");
exit();
}
while ($imgarray = mysql_fetch_array($imageget)) {
$imageid = htmlspecialchars($imgarray["image_id"]);
$imageresorder = htmlspecialchars($imgarray["image_res_order"]);
$imagerescaption = htmlspecialchars($imgarray["image_res_caption"]);
}
?>


<?php endif; ?>

<form action='<?php echo $_SERVER[PHP_SELF];?>' method='post'>

<table width='300' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='150' align='left' valign='top'>
<span class='caption_cap'>Display Order</span><br>
<input name='imageresorder' class='body01' size='3' maxlength='3' value='<?php echo $imageresorder;?>'><br>
</td>

<td width='150' align='left' valign='top'><span class='caption_cap'>Feature Picture</span><br>
<input name='featurepic' type='radio' value='<?php $image_res_id;?>' ><span class='caption_cap'>yes</span>
<input name='featurepic' type='radio' value='' checked='' ><span class='caption_cap'>no</span>
</td>
</tr>
</table>

<input name='imageid' type='hidden' value='<?php echo $imageid;?>' >

<span class='caption_cap'>Picture Caption</span><br>
<input name='imagerescaption' class='body01' size='36' maxlength='64' value='<?php echo $imagerescaption;?>'>

<br>
<div align='center'><input type='submit' name='editimage' class='body01' value=' SAVE '></div>
</form>


<?php
$resselect = @mysql_query("SELECT
res_street01,
res_city,
FROM residential WHERE res_id='$id'");

if (!$resselect) {
echo("Error selecting RESIDENTIAL data from database!" . mysql_error() . "Call webmaster");
exit();
}

while ($resarray = mysql_fetch_array($resselect)) {

$resstreet01 = htmlspecialchars($resarray["res_street01"]);
$rescity = htmlspecialchars($resarray["res_city"]);
}

?>

<div align="center"><span class="caption_cap">Record Id&nbsp;&nbsp; <?php echo $id; ?></span></div>
<hr align='center' width='450' size='1' noshade>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td align="left" width="200"valign="top">
<span class="listing01">
<strong><?php echo $restype ;?></strong><br>
<?php echo $resstreet01 ;?><br>
<?php echo $rescity ;?></span>
</td>
</tr>
</table><br>

<?php

$imgselect = @mysql_query("SELECT
image_id,
image_res_order,
image_res_caption,
FROM image_res
WHERE image_res_id='$id' ORDER by image_res_order");
if (!$imgselect) {
echo ("Error SELECTING data from database!" . mysql_error() . "Call webmaster");
exit();
}
while ($imgarray = mysql_fetch_array($imgselect)) {
$imageresorder = htmlspecialchars($imgarray["image_res_order"]);
$imagerescaption = htmlspecialchars($imgarray["image_res_caption"]);


echo "<table width='340' align='center' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='170'><span class='body01'><strong>$imageresorder </strong></span>
<span class='caption_cap'>Display Order</span></td>

<td width='170' align='left'><br><span class='caption_cap'>Picture Caption</span><br>
<span class='body01'><strong>$imagerescaption</strong></span></td>
</tr>
</table>";
}

?>


<?php @require_once('../includes/copyright.php'); ?>

<?php mysql_close() ?>
</body>
</html>


The commented portion is my radio button code, that is where I need the $id variable - in the WHERE mysql statement.

The $id tag seems to work everywhere else. What am I missing? Is there an "eregi (left-brain && hip-check)" function I need to study?

I tried the placing the $id = (int)$_GET['id']; as shown below, but the $id variable is dead after the if (isset($_POST['editimage'])): statement and begins to return the value again after else: staement (see full code above)


<?php

$id = (int)$_GET['id'];
echo $id; <-----------works!
if (isset($_POST['editimage'])):
$imageresorder = $_POST['imageresorder'];
$imagerescaption = $_POST['imagerescaption'];
$imageid = $_POST['imageid'];

$sqlupdate = "UPDATE image_res SET
image_res_order='$imageresorder',
image_res_caption='$imagerescaption'
WHERE image_id='$imageid'";

if (@mysql_query($sqlupdate)) {

echo "Residential IMAGE updated! $id "; <-----does not work!

gregorious
Jul 31st 2007, 9:51 pm
I may not be the sharpest tool in the shed; but my testing
makes mesuspect these two colons. Outside of the colons
the $id variable works.


<?php
if (isset($_POST['editimage'])):

<?php
else:

Code from orignial message in this tread. Anyone got a clue?

ecentricNick
Aug 1st 2007, 2:52 am
Your form is being posted, but you're using $_GET['id'] rather than $_POST['id']?

Plus you're logic doesn't look right, you possibly only store $id if there is no editimage? Is that correct? But, to be honest, I can't work out your if blocks using that : format (as Gregorious pointed out) - particularly as you've mixed formats - sometimes :, sometimes braces.

Can you change it all to braces and re-post?

nagasharmi
Aug 1st 2007, 5:40 am
<?php

$id = (int)$_GET['id'];
echo $id;
if (isset($_POST['editimage']))
{
$imageresorder = $_POST['imageresorder'];
$imagerescaption = $_POST['imagerescaption'];
$imageid = $_POST['imageid'];
$sqlupdate = "UPDATE image_res SET image_res_order='$imageresorder', image_res_caption='$imagerescaption' WHERE image_id='$imageid'";
if (@mysql_query($sqlupdate))
{

echo "Residential IMAGE updated! $_POST['id']";
}
}

<form action="thsform.php" method="post">
<input type="hidden" id="id" name="id" value="<? echo $_GET['id'] ?>" />
</form>

BZ what is the problem.

if (isset) function will work whenever form will submit but in this submit how can it get $_GET method.
so first $id willstroe into temp textbox and move from form into your process.

is it clear

gregorious
Aug 1st 2007, 9:58 am
I have added a jpg to this thread to help clarify the page design.

http://www.forthosewhowait.com/images/cms-editpage02.jpg

The POST / ELSE removes the form and reports a successful upload when the user submits.

I have tried POST and GET to bring the $id variable into the POST / ELSE but nothing seems to bring the value into that dead zone.

gregorious
Aug 1st 2007, 10:57 am
This is the URL being passed from the previous page.

http://localhost/admin/edit_res_image.php?id=136&imageid=236

I find it intersesting that the $imageid is being passed through out the page, but not the $id

Brewster
Aug 1st 2007, 11:33 am
$imageid is being posted. Here is where in your script:


<input name='imageid' type='hidden' value='<?php echo $imageid;?>' >

Brew

gregorious
Aug 1st 2007, 11:57 am
$imageid is being posted. Here is where in your script:


<input name='imageid' type='hidden' value='<?php echo $imageid;?>' >

Brew

Your are a genius!!

This is the second time a hidden value in the form has cost me hours on this project. I am going to learn from this one.

SOLUTION! - to pass FORM variables back up to the POST they must be declared in the FORM.
<input name='id' type='hidden' value='<?php echo $id;?>' >

Only one question left... is there a willing hair donor out there?

.