Jump to content

phunnydoode

New Members
  • Posts

    4
  • Joined

  • Last visited

phunnydoode's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have it set up in the cartUpdate.php two cases: 1)add 2)remove. Adding works, removing does not. Any help is greatly appreciated here's what I got: <?php if (!isset($_SESSION)) session_start(); $action = $_GET['action']; $product_id = $_GET['product_id']; switch($action) { //decide what to do case "add": $item = $_POST['item']; $price = $_POST['price']; $qty = $_POST['qty']; $product_id = $_POST['product_id']; $_SESSION['myCart'][] = array("item"=>$item,"qty"=>$qty,"price"=>$price,"product_id"=>$product_id); $_SESSION['myToti'] = $_SESSION['myToti'] + $qty; $_SESSION['myTotp'] = $_SESSION['myTotp'] + ($price * $qty); header("Location:cartView.php"); break; case "remove": unset($_SESSION['myCart'][$product_id]); header("Location:cartView.php"); break; } ?> cartview.php Which has a layout where each item in the shopping cart has a delete link <tr><td colspan='2'><h4>Shopping Cart</td><tr> <tr> <td colspan="2"> <table border="0" padding="0" cellspacing="0"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method ="post" name="cartForm" id="cartForm" onsubmit="return checkSubmit();"> <tr class="trColor"> <td width="200" class="nvtxt"><h4>Item Description</h4></td> <td width="100" class="nvtxt"><h4>Item Price</h4></td> <td width="100" class="nvtxt"><h4>Quantity</h4></td> <td width="100" class="nvtxt"><h4>Item Total</h4></td> <td width="100" class="nvtxt"><h4>Delete</h4></td> </tr> <?php foreach($_SESSION['myCart'] AS $temp) { $itmTot = $temp["qty"] * $temp["price"]; ?> <tr> <td><h4><?= $temp["item"] ?></h4></td> <td><h4>$<?= $temp["price"] ?></h4></td> <td><h4><?= $temp['qty'] ?> </h4></td> <td><h4>$<?= $itmTot ?></h4></td> <td><h4><a href="cartUpdate.php?action=remove&product_id=<?= $temp['product_id']?> ">Delete</a></h4></td> </tr> <?php } //} ?> <tr class="trColor"> <td colspan="2"> </td> <td class="nvtxt"><h4>Quantity</td> <td class="nvtxt"><h4>Total</td> </tr> <tr> <td colspan="2" /> <td><h4><?= $_SESSION['myToti'] ?></td> <td><h4>$<?= $_SESSION['myTotp'] ?></td> </tr> <tr class="trColor"><td colspan="4"> </td></tr> <tr> <td colspan="4" align="center" height="100"> <BR> <input type="submit" name="checkout" id="checkout" value="Checkout"> <BR> <input type="submit" name="continue" id="continue" value="Continue Shopping"> <input type="submit" name="submit" id="submit" value="Clear Cart" /> <?php if(isset($_POST['submit'])){ unset($_SESSION['myCart']); header("Location:index.php"); } if(isset($_POST['continue'])){ header("Location:index.php"); } if(isset($_POST['checkout'])){ header("Location:checkout.php"); } ?> </td> </tr> </form> </table> </td> </tr>
  2. <?php if (!isset($_SESSION)) session_start(); $qstr = $_SERVER['QUERY_STRING']; parse_str ( $qstr ); ?> <body> <div id="wrap"> <?php require 'header.php';?> <section> <tr><td colspan='2'><h4>Shopping Cart</td><tr> <tr> <td colspan="2"> <table border="0" padding="0" cellspacing="0"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method ="post" name="cartForm" id="cartForm" onsubmit="return checkSubmit();"> <tr class="trColor"> <td width="200" class="nvtxt"><h4>Item Description</td> <td width="100" class="nvtxt"><h4>Item Price</td> <td width="100" class="nvtxt"><h4>Quantity</td> <td width="100" class="nvtxt"><h4>Item Total</td> </tr> <?php foreach($_SESSION['myCart'] AS $temp) { $itmTot = $temp["qty"] * $temp["price"]; ?> <tr> <td><h4><?= $temp["item"] ?></td> <td><h4>$<?= $temp["price"] ?></td> <td><h4><input type="text" size="3" value="<?= $temp['qty'] ?>" ></td> <td><h4>$<?= $itmTot ?></td> </tr> <?php } ?> <tr class="trColor"> <td colspan="2"> </td> <td class="nvtxt"><h4>Quantity</td> <td class="nvtxt"><h4>Total</td> </tr> <tr> <td colspan="2" /> <td><h4><?= $_SESSION['myToti'] ?></td> <td><h4>$<?= $_SESSION['myTotp'] ?></td> </tr> <tr class="trColor"><td colspan="4"> </td></tr> <tr> <td colspan="4" align="center" height="100"> <a href="index.php">Continue Shopping</a> <BR> <a href=checkout.php>Checkout</a> <BR> <input type="submit" name="submit" id="submit" value="Clear Cart" /> <input type="submit" name="save" id="save" value="Edit Card"/> <?php if(isset($_POST['submit'])){ unset($_SESSION['myCart']); header("Location:index.php"); } ?> <?php if(isset($_POST['save'])){ } ?> Above is Viewing the cart which has two buttons. One which clears the cart and the other which will be used to input a new value such as 0 to change the cart and clear that item from the cart- I don't know how to go about doing this so any help is greatly appreciated. Here's the rest of my code. <!--cart.php--> <?php if (!isset($_SESSION)) session_start(); $qstr = $_SERVER['QUERY_STRING']; parse_str ( $qstr ); ?> <body> <div id="wrap"> <?php require 'header.php';?> <section><h4> <tr><td colspan='2'>Shopping Cart</td><tr> <tr> <td colspan="2"> <table border="0" padding="0" cellspacing="0"> <form action="cartUpdate.php" method="post" name="myForm"> <tr class="trColor"> <td width="200" class="nvtxt"><h4>Item Description</td> <td width="100" class="nvtxt"><h4>Item Price</td> <td width="100" class="nvtxt"><h4>Quantity</td> </tr> <tr height="100"> <td><h4><?= $item ?></td> <td><h4>$<?= $price ?></td> <td> <input type="text" name="qty" id="qty" size="3" placeholder="0"> </td> <input type="hidden" name="item" value="<?= $item ?>"> <input type="hidden" name="price" value="<?= $price ?>"> </tr> <tr class="trColor"><td colspan="3"> </td></tr> <tr> <td colspan="3" align="center" height="100"> <!-- continue shopping --> <a href="index.php">Continue Shopping</a> <!-- update cart --> <a href="javascript:void(0)" onclick="document.myForm.submit();">Add to Cart</a> </td> </tr> </form> </table> Script to update the cart when clicking the button "Add to Cart" <?php if (!isset($_SESSION)) session_start(); $item = $_POST['item']; $price = $_POST['price']; $qty = $_POST['qty']; $_SESSION['myCart'][] = array("item"=>$item,"qty"=>$qty,"price"=>$price); $_SESSION['myToti'] = $_SESSION['myToti'] + $qty; $_SESSION['myTotp'] = $_SESSION['myTotp'] + ($price * $qty); header("Location:cartView.php"); ?> <?php $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $query = "SELECT `inventory` FROM `bencobricks` . `product`"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); while($rows=mysqli_fetch_array($result)){ if ($qty - $rows['inventory'] < '0') { echo "Unavailable"; } } ?>
  3. Currently I show a list of users and their information. You can than click that specific user and it shows you their information to edit. My problem is it's not updating the query with the new input information. Here is the page that displays the registration information: <?php $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $query = "SELECT * FROM `bencobricks` . `users`"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); ?> <table width="1000" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="1000" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><strong>List data from mysql </strong> </td> </tr> <tr> <td align="center"><strong>Username</strong></td> <td align="center"><strong>Email</strong></td> <td align="center"><strong>Membership</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Last Name</strong></td> <td align="center"><strong>Gender</strong></td> <td align="center"><strong>Birthdate</strong></td> <td align="center"><strong>Sets</strong></td> <td align="center"><strong>Checkbox</strong></td> <td align="center"><strong>Admin Flag</strong></td> </tr> <?php while($rows=mysqli_fetch_array($result)){ ?> <tr> <td><?php echo $rows['username']; ?></td> <td><?php echo $rows['email']; ?></td> <td><?php echo $rows['membership']; ?></td> <td><?php echo $rows['firstName']; ?></td> <td><?php echo $rows['lastName']; ?></td> <td><?php echo $rows['gender']; ?></td> <td><?php echo $rows['dateOfBirth']; ?></td> <td><?php echo $rows['sets']; ?></td> <td><?php echo $rows['checkbox']; ?></td> <td><?php echo $rows['adminFlag']; ?></td> <td align="center"><a href="update.php?userID=<?php echo $rows['userID']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysqli_close($con); ?> Page that displays specific user for updating: <?php $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $id=$_GET['userID']; $query = "SELECT * FROM `bencobricks` . `users` WHERE `userID` = '$id'"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); $rows=mysqli_fetch_array($result); ?> <table width="1000" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"><strong>Username</strong></td> <td align="center"><strong>Email</strong></td> <td align="center"><strong>Membership</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Last Name</strong></td> <td align="center"><strong>Gender</strong></td> <td align="center"><strong>Birthdate</strong></td> <td align="center"><strong>Sets</strong></td> <td align="center"><strong>Checkbox</strong></td> <td align="center"><strong>Admin Flag</strong></td> </tr> <tr> <td align="center"> <input name="username" type="text" id="username" value="<?php echo $rows['username'] ; echo (isset($_POST['username']) ? $_POST['username'] : ''); ?>"> </td> <td align="center"> <input name="email" type="text" id="email" value="<?php echo $rows['email']; ?>" size="15"> </td> <td> <input name="membership" type="text" id="membership" value="<?php echo $rows['membership']; ?>" size="15"> </td> <td> <input name="firstName" type="text" id="firstName" value="<?php echo $rows['firstName']; ?>" size="15"> </td> <td> <input name="lastName" type="text" id="lastName" value="<?php echo $rows['lastName']; ?>" size="15"> </td> <td> <input name="gender" type="text" id="gender" value="<?php echo $rows['gender']; ?>" size="15"> </td> <td> <input name="dateOfBirth" type="text" id="dateOfBirth" value="<?php echo $rows['dateOfBirth']; ?>" size="15"> </td> <td> <input name="sets" type="text" id="sets" value="<?php echo $rows['sets']; ?>" size="15"> </td> <td> <input name="checkbox" type="text" id="checkbox" value="<?php echo $rows['checkbox']; ?>" size="15"> </td> <td> <input name="adminFlag" type="text" id="adminFlag" value="<?php echo $rows['adminFlag']; ?>" size="15"> </td> </tr> <tr> <td> </td> <td> <input name="id" type="hidden" id="id" value="<?php echo $rows['userID']; ?>"> </td> <td align="center"> <input type="submit" name="Submit" value="Submit"> </td> <td> </td> </tr> </table> </td> </form> </tr> </table> <?php // close connection mysqli_close($con); ?> Finally the update query: <?php function test_input($data){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } // update data in mysql database if (empty($_POST["username"])) {/* can never be empty due to design */} else {$username= test_input($_POST['username']);} $id = 'id'; $query = "UPDATE `bencobricks`. `users` SET `username` = '$username', `password` = 'NULL', `email` = 'email', `membership` = 'membership', `firstName` = 'firstName', `lastName` = 'lastName', `gender` = 'gender', `dateOfBirth` = 'dateOfBirth', `date` = 'NULL', `sets` = 'sets', `checkbox` = 'checkbox', `adminFlag` = 'adminFlag' WHERE `userID` = '$id'"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='editUser.php'>View Users Page</a>"; } else { echo "ERROR"; } ?>
  4. Hello my problem here is to have a drop down menu which gathers usernames from the database. Then with a click of a button the information for that specific user selected is shown. I'm close code wise but right now it's just showing me all users. I'm displaying the info in text box's to allow an admin to change the info. <form action="edit.php" method="post"> <select name="username" id="username"> <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $query = "SELECT `username` FROM `bencobricks` . `users`"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); if($result) { while($row = mysqli_fetch_assoc($result)) { //printf ("%s\n %s\n ", echo "<label for='username'>Username: </label> <option value='$row[username]'>$row[username] </option><br/>"; echo "<br/><br/> "; } } mysqli_close($con); ?> </select> <br /> <input name="send" id="send" type="submit" value="Edit User" /> </form> Then in the edit.php file i have this code: <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } if (isset($_POST['send'])) { $username = $_POST['username']; $query = "SELECT * FROM `bencobricks` . `users` "; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); // Print the result if($result) { while ($row = mysqli_fetch_assoc($result)) { // $query = "SELECT * FROM `bencobricks` . `users` WHERE `username` = username = $row[username]"; printf ("%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n", "<label for='username'>Username: </label> <input type='text' name='username' value='$row[username]'>" . "</input><br/>", "<label for='email'>Email: </label> <input type='text' name='email' value='$row[email]'>" . "</input><br/>", "<label for='membership'>Membership: </label> <input type='text' name='membership' value='$row[membership]'>" . "</input><br/>", "<label for='firstName'>First name: </label> <input type='text' name='firstName' value='$row[firstName]'>" . "</input><br/>", "<label for='lastName'>Last name: </label> <input type='text' name='lastName' value='$row[lastName]'>" . "</input><br/>", "<label for='gender'>Gender: </label> <input type='text' name='gender' value='$row[gender]'>" . "</input><br/>", "<label for='dateOfBirth'>Birthdate: </label> <input type='text' name='dateOfBirth' value='$row[dateOfBirth]'>" . "</input><br/>", "<label for='date'>Date: </label> <input type='text' name='date' value='$row[date]'>" . "</input><br/>", "<label for='sets'>Sets: </label> <input type='text' name='sets' value='$row[sets]'>" . "</input><br/>", "<label for='checkbox'>Checkbox: </label> <input type='text' name='checkbox' value='$row[checkbox]'>" . "</input><br/>", "<label for='admin'>Admin? </label> <input type='text' name='admin' value='$row[adminFlag]'>" . "</input><BR>", "<br/><br/> "); } } } mysqli_close($con); ?> Any help is greatly appreciated.
×
×
  • 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.