Hi just playing around with some php code.
I am making a shopping site and implemented an discount code button and could do with some advise.
Heres the code.
if(isset($_GET['codebutton']));{
$codeInput = $_GET['code'];
if($codeInput == 'halfprice1'){
$sql = "SELECT * FROM shop";
$result = mysql_query($sql);
$itemCount = mysql_num_rows($result);
echo "<div id='container'> ";
echo "<h4> Discount Code succesfull, 50% off has been actioned </h4></br><hr><br>";
echo '
<form action="order.php" method="GET">
<input type="submit" name="high" value="Order By Highest Cost"> </input>
<input type="submit" name="low" value="Order By Lowest Cost"> </input>
<input type="submit" name="three" value="Top 3 Choices"> </input></br></br>
<input style="height:30px;" type="text" name="code" value="Enter Discount Code"> </input>
<input type="submit" name="codebutton" value="Submit Discount Code"> </input>
</form>';
while ( $db_field = mysql_fetch_assoc($result) )
{
$id = $db_field['id'];
$newCost = $db_field['cost'] / 2;
echo "<table>";
echo "<tr><td style='height:60px; background:#333; border:1px solid #fff; margin-bottom:1px;'><a style='color:#fff' href='prod.php?id=$id'>" . $db_field['title'] . "</a></td></tr>";
print "<tr><td>" .$db_field['brand'] . "</td></tr>";
print "<tr><td style='background:#333; color:#fff; border:1px solid #fff'>" .$newCost . "</td></tr>";
print "<tr><td>" .$db_field['img'] . "</td></tr>";
echo "</table>";
}
echo "<div class='clearfix'> </div></div>";
echo "<div id='back'>
<a href='loadTable.php'> <p> Click Here to go Back to the Catalogue </p> </a>
</div></div>";
echo "<div id='count'> <p> There are now {$itemCount} items in this catalogue </p> </div> ";
}else {
This is an if statement where if the correct discount code is entered the price becomes halfed, in the case of the else part is there a way to keep it the same without having to copy the code yet again minus the divided by two maths?
Thanks
Aucun commentaire:
Enregistrer un commentaire