Jump to content

[SOLVED] Old values showing back up


timmah1

Recommended Posts

I have a page that updates packages.

 

The page updates the database correctly, but when I go back to the page, it shows all of the old information.

 

For example, right now, there is nothing in the database for the "name" field, but when viewing the page, it shows all the old information, and the text boxes should be showing nothing since nothing is in the database.

 

Can anybody see in the code why this would be?

 

<?php
session_start();

if(isset($_SESSION['SESS_ADMIN']) == FALSE){
	header("Location: " . $config_basedir . "login.php?error=1");
}
include('config2.php');
	$sport = $_GET['sport'];

switch($sport){

case "nba":
	$title = "NBA Basketball";
break;

case "nfl":
	$title = "NFL Football";
break;

case "ncaaf":
	$title = "NCAA Football";
break;

case "ncaab":
	$title = "NCAA Basketball";
break;
}
if($_POST['update']) {

//var_dump($_POST);    


for($i=0;$i < count($_POST['id']);$i++ ){
   $name = mysql_real_escape_string($_POST['name'][$i]);
   $price = mysql_real_escape_string($_POST['price'][$i]);
   $hint = mysql_real_escape_string($_POST['hint'][$i]);
   $starttime = date("Y-m-d");
   $hint = addslashes($hint);
   $id = (is_numeric($_POST['id'][$i]))? $_POST['id'][$i] : 0;
   
$sql = mysql_query("UPDATE packages1 SET name = '$name', price = '$price', hint = '$hint', start = '$starttime' WHERE id = '$id'")
or die("Sorry, there was a problem updating packages ".mysql_error());

//$sql1 = mysql_query("UPDATE preferences SET bball_active = '$_POST[bball_active]'")
//or die("Sorry, there was a problem setting action ".mysql_error());
   }
   
   
require("header.php");
echo "<div align='center'>$title has been updated<br></div>";
echo "<div align='center'><a href='packages.php?sport=$sport'>Go Back</a></div><br><br>";	

}
else {
require("header.php");
?>
<label for="header">Please use this form to change any variables for <?=$title;?><br></label>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<?php
  
?>
<label for="header">Section Active?<br />
<?php 
$sql1 = "SELECT bball_active FROM preferences";
$q1 = mysql_query($sql1);  
while($b = mysql_fetch_assoc($q1)) { ?>
Yes <input <?php if (!(strcmp("$b[bball_active]","1"))) {echo "checked=\"checked\"";} ?> name="bball_active" type="radio" value="1" />
No <input <?php if (!(strcmp("$b[bball_active]","0"))) {echo "checked=\"checked\"";} ?> name="bball_active" type="radio" value="0" /><br /></label>
<?php } ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<?php   
//$i = 1; 
$sql = "SELECT * FROM packages1 WHERE sport = '$sport' ORDER BY id LIMIT 5";
$q = mysql_query($sql);   
while($a = mysql_fetch_assoc($q)) { 

switch($a['package']){

case "sngl":
	$p_name = "Single";
break;

case "ult":
	$p_name = "Ultimate";
break;

case "mnth":
	$p_name = "Month";
break;

case "ssn":
	$p_name = "Season";
break;

case "po":
	$p_name = "Playoffs";
break;
}

$package_name = $a['name'];
$package_price = $a['price'];
$package_hint = stripslashes($a['hint']);
$package_id = $a['id'];

echo "<tr>";
echo "<td><label for='name'>$p_name Package</label>";
echo "<input type='text' size='50' name='name[]' value='$package_name'>$package_id<br />";
echo " </td>";
echo "<td><label for='name'>Package Price</label>";
echo "<input type='text' size='5' name='price[]' value='$package_price'></td>";
echo "<td><label for='name'>Show Hint</label>";
echo "<input type='text' size='50' name='hint[]' value='", htmlentities($package_hint, ENT_QUOTES), "'> </td>";
echo "<input type='hidden' name='id[]' value='$package_id'><br>";

echo "</tr>";
//$i++;
}
?>
</table>
<input name="update" class="button" type="submit" value="Update <?=$title;?>" />
</form>
<?php
}
require("footer.php");
?>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/151919-solved-old-values-showing-back-up/
Share on other sites

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.