Jump to content

Keeping the dynamic url the way it is???


cturner

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/25772-keeping-the-dynamic-url-the-way-it-is/
Share on other sites

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>';
    }
}
[/code]

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();
[/code]
Before I click on the order button it starts off at [url=http://www.blueguminteractive.biz/example1.htm]this page[/url]. Then when I click on the order button and when the combo boxes aren't selected it goes to [url=http://www.blueguminteractive.biz/example2.htm]this screenshot[/url].

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.