Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping the dynamic url the way it is???

Status
Not open for further replies.

cturner01

Technical User
Aug 1, 2006
29
AU
Can someone please tell me how I can keep a query string in the url? In my code I have a part where if a user leaves out a field or two on a form it will display messages on that page where the query string is and when the user clicks on a button the query string disappears from the url. I don't want the query string to disappear. Thanks in advance.

Before I click on the order button it starts off at this page. Then when I click on the order button and when the combo boxes aren't selected it goes to this screenshot.

Here is the code for checking to see if the combo boxes are selected or not, etc:
Code:
$selectpacksize = $_POST['selectpacksize'];
$selectcolour = $_POST['selectcolour'];
$selecticon = $_POST['selecticon'];
$nameprint = $_POST['nameprint'];
$username = $_COOKIE['username'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$address5 = $_POST['address5'];
$arrErrors = array();

if (isset($_POST['order'])) {
	if ($selectpacksize == 'none') {
		$arrErrors['selectpacksize'] = 'Please select a pack size.';
	}
	
	//if (!empty($row['colour'])) {
	if ($selectcolour == 'none') {
		$arrErrors['selectcolour'] = 'Please select a colour.';
	}
	//}
	
	//if (!empty($row['icon'])) {
	if ($selecticon == 'none') {
		$arrErrors['selecticon'] = 'Please select an icon.';
	}
	//}
	
	// check to see if the product exists in the cart table
	$sql = mysql_query("SELECT * FROM `tbl_cart` WHERE `username` = '$username' AND `pd_id` = '$pd_id'") or die ("Could not query because: ".mysql_error());

	$check = mysql_num_rows($sql);
	
	if ($check >= 1) {
		// if the product is in the database then increase the quantity
		$insertqty = "UPDATE `tbl_cart` SET `ct_qty` = `ct_qty + 1` WHERE `username` = '$username' AND `pd_id` = '$pd_id'";
			
	}
	
	if (count($arrErrors) == 0) {
		// today's date
		$date = time();
		
		$query2 = "SELECT * FROM `tbl_product` WHERE `pd_id` = '$pd_id'";
		$r2= mysql_query($query2) or die('Query error: ' .mysql_error());
		$row2= mysql_fetch_assoc($r2);
		$pd_id = $row2['pd_id'];
		
		$insertproduct = "INSERT INTO `tbl_cart` (`ct_id`, `ct_qty`, `ct_date`, `username`, `pd_id`, `packsize`, `colour`, `icon`, `name`, `address1`, `address2`, `address3`, `address4`, `address5`) VALUES (0, 'ct_qty + 1', '$date', '$username', '$pd_id', '$selectpacksize', '$selectcolour', '$selecticon', '$nameprint', '$address`', '$address2', '$address3', '$address4', '$address5')";
		
		if (mysql_query ($insertproduct)) {
			header ('Location: viewcart.php');
		} else {
			print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
		}
	
	} else {
        // The error array had something in it. There was an error.
        // Start adding error text to an error string.
        $strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
        // Get each error and add it to the error string
        // as a list item.
        foreach ($arrErrors as $error) {
            $strError .= "<li>$error</li>";
        }
        $strError .= '</ul></div>';
    }
}

Here is the code to display the page:
Code:
<?php echo $strError; ?>
	<form name="addtocartForm" method="post" action="<?php echo $PHP_SELF; ?>">
<?php
// display the product name
echo "<div class=leftbox><h1>".$row['productname']."</h1>";

echo "<img src=/simplystuck/images/".$row['mainphoto']."></div>";

// display the description
echo "<div class=rightbox>".$row['description'];

// display the bullets
echo "<ul><li>".$row['bullet1']."</li>";
echo "<li>".$row['bullet2']."</li>";
if (!empty($row['bullet3'])) {
	echo "<li>".$row['bullet3']."</li>";
	if (!empty($row['bullet4'])) {
	echo "<li>".$row['bullet4']."</li>";
	}
	if (!empty($row['bullet5'])) {
	echo "<li>".$row['bullet5']."</li>";
	}
	if (!empty($row['bullet6'])) {
	echo "<li>".$row['bullet6']."</li>";
	}
	echo "</ul>";
}
if (!empty($row['extrainfo1'])) {
	echo $row['extrainfo1'];
}

echo "<br /><b>Product Information</b><br/ >";

echo "<b>Pack Sizes</b>: ".$row['packsize1']." / ";
if (!empty($row['packsize2'])) {
	echo $row['packsize2']." / ";
}
if (!empty($row['packsize3'])) {
	echo $row['packsize3'];
}

echo " labels<br />";

if (!empty($row['colour1'])) {
	echo "<b>Pack Colours</b>: ";
	echo $row['colour1'].", ";
}
if (!empty($row['colour2'])) {
	echo $row['colour2'].", ";
}
if (!empty($row['colour3'])) {
	echo $row['colour3'].", ";
}
if (!empty($row['colour4'])) {
	echo $row['colour4'].", ";
}
if (!empty($row['colour5'])) {
	echo $row['colour5']."<br />";
}

if (!empty($row['icon1'])) {
	echo "<b>Icons</b>: ".$row['icon1'].", ";	
}
if (!empty($row['icon2'])) {
	echo $row['icon2'].", ";
}
if (!empty($row['icon2'])) {
	echo $row['icon3'].", ";
}
if (!empty($row['icon2'])) {
	echo $row['icon4'];
}
?>

<br><br>Please choose from the options:<br>
<br><b>Pack size</b>:
	<select name="selectpacksize" id="selectpacksize">
	<option value="none" selected>Please select</option>
<?php
		print "<option value=".$row['packsize1'].">".$row['packsize1']." labels</option>";
	if (!empty($row['packsize2'])) {
		print "<option value=".$row['packsize2'].">".$row['packsize2']." labels</option>";
	}
	if (!empty($row['packsize3'])) {
		print "<option value=".$row['packsize3'].">".$row['packsize3']." labels</option>";
	}
?>
	</select>
<?php 
if (!empty($row['colour1'])) {
echo "<br /><b>Colour</b>: ";
print "<select name=\"selectcolour\" id=\"selectcolour\">";
print "<option value=\"none\" selected>Please select</option>";
//while($row = mysql_fetch_array($sql)){
	print "<option value=".$row['colour1'].">".$row['colour1']."</option>";
	if (!empty($row['colour2'])) {
	print "<option value=".$row['colour2'].">".$row['colour2']."</option>";
	}
	if (!empty($row['colour3'])) {
	print "<option value=".$row['colour3'].">".$row['colour3']."</option>";
	}
	if (!empty($row['colour4'])) {
	print "<option value=".$row['colour4'].">".$row['colour4']."</option>";
	}
	if (!empty($row['colour5'])) {
	print "<option value=".$row['colour5'].">".$row['colour5']."</option>";
	}
//}
print "</select>";
}

if (!empty($row['icon1'])) {
echo "<br /><b>Icon</b>: ";
//$sql = mysql_query("SELECT * FROM `tbl_product` WHERE pd_id = $pd_id") or die ("Could not query because: " . mysql_error());
print "<select name=\"selecticon\" id=\"selecticon\">";
print "<option value=\"none\" selected>Please select</option>";
//while($row = mysql_fetch_array($sql)){
	print "<option value=".$row['icon1'].">".$row['icon1']."</option>";
	if (!empty($row['icon2'])) {
	print "<option value=".$row['icon2'].">".$row['icon2']."</option>";
	}
	if (!empty($row['icon3'])) {
	print "<option value=".$row['icon3'].">".$row['icon3']."</option>";
	}
	if (!empty($row['icon4'])) {
	print "<option value=".$row['icon4'].">".$row['icon4']."</option>";
	}
//}
print "</select>";
}

echo "<br /><br />".$row['icon1']." <img src=/simplystuck/images/".$row['imagefile1'].">".$row['icon2']."<img src=/simplystuck/images/".$row['imagefile2'].">".$row['icon3']."<img src=/simplystuck/images/".$row['imagefile3'].">".$row['icon4']."<img src=/simplystuck/images/".$row['imagefile4'].">";

//if (!empty($row['']))) {
	//echo "<br /><br /><b>Name to be printed (max 20 characters)</b>: ";
	//echo "";
//}

// display the order button
echo "<br /><br /><input type=submit name=order value=ORDER></div>";
?>
</form>
<?php
mysql_close();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top