Jump to content

damiendarien

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

damiendarien's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. problem with the table has been fixed. (operator error) didnt have CSS in the same folder. added __wakup() to make the rest work. Thanks to whoever looked.
  2. ****UPDATE**** Now i got it to show up but as far as the table being layed out properly --- ITS NOT. thanks
  3. <?php class OnlineStore { private $DBConnect = NULL; private $storeID = ""; private $inventory = array(); private $shoppingCart = array(); function __construct() { include("inc_OnlineStoreDB.php"); $this->DBConnect = $DBConnect; } function __destruct() { if (!$this->DBConnect->connect_error) $this->DBConnect->close(); } public function setStoreID($storeID) { if ($this->storeID != $storeID) { $this->storeID = $storeID; $SQLstring = "SELECT * FROM inventory " . " where storeID = 'jw" . $this->storeID . "'"; $QueryResult = $this->DBConnect->query($SQLstring); if ($QueryResult === FALSE) { $this->storeID = ""; } else { $this->inventory = array(); $this->shoppingCart = array(); while (($Row = $QueryResult->fetch_assoc()) !== NULL) { $this->inventory[$Row['productID']] = array(); $this->inventory[$Row['productID']]['name'] = $Row['name']; $this->inventory[$Row['productID']]['description'] = $Row['description']; $this->inventory[$Row['productID']]['price'] = $Row['price']; $this->shoppingCart[$Row['productID']] = 0; } } } } public function getStoreInformation() { $retval = FALSE; if ($this->storeID != "") { $SQLstring = "SELECT * FROM store_info " . " WHERE storeID = '" . $this->storeID . "'"; $QueryResult = @$this->DBConnect->query($SQLstring); if ($QueryResult !== FALSE) { $retval = $QueryResult->fetch_assoc(); } } return($retval); } public function getProductList() { $retval = FALSE; $subtotal = 0; if (count($this->inventory) > 0) { echo "<table width='100%'>\n"; echo "<tr><th>Product</th><th>Description</th>" . "<th>Price Each</th><th># in Cart</th>" . "<th>Total Price</th><th> </th></tr>\n"; foreach ($this->inventory as $ID => $Info) { echo "<tr><td>" . htmlentities($Info['name']) . "</td>\n"; echo "<td>" . htmlentities($Info['description']) . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price']); echo "<td class='currency'>" . $this->shoppingCart[$ID] . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price'] * $this->shoppingCart[$ID]); echo "<td><a href='" . $_SERVER['SCRIPT_NAME'] . "?PHPSESSID=" . session_id() . "&ItemToAdd=$ID'>Add " . " Item</a></td>\n"; $subtotal += ($Info['price'] * $this->shoppingCart[$ID]); } echo "<tr><td colspan='4'>Subtotal</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $subtotal); echo "<td>$nbsp;</td></tr>\n"; echo "</table>"; $retval = TRUE; } return($retval); } public function addItem() { $ProdID = $_GET['ItemToAdd']; if (array_key_exists($ProdID, $this->shoppingCart)) $this->shoppingCart[$ProdID] += 1; } } ?> having an issue to where nothing is appearing on the page and getting the Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\PHP\Chapter.10\class_OnlineStore.php on line 24 HERE IS THE MAIN PAGE <?php session_start(); require_once("class_OnlineStore.php"); $storeID = "COFFEE"; $storeInfo = array(); if (class_exists("OnlineStore")) { if (isset($_SESSION['currentStore'])) $Store = unserialize($_SESSION['currentStore']); else { $Store = new OnlineStore(); } $Store->setStoreID($storeID); $storeInfo = $Store->getStoreInformation(); } else { $ErrorMsgs[] = "The OnlineStore class is not available!"; $Store = NULL; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $storeInfo['name']; ?></title> <link rel="stylesheet" type="text/css" href="<?php echo $storeInfo['css_file']; ?>" /> </head> <body> <h1><?php echo htmlentities($storeInfo['name']); ?></h1> <h2><?php echo htmlentities($storeInfo['description']); ?></h2> <p><?php echo htmlentities($storeInfo['welcome']); ?></p> <?php $Store->getProductList(); $_SESSION['currentStore'] = serialize($Store); ?> </body> </html> I HAVE REVIEWED IT OVER AND OVER AGAIN AND I CANT SEE THE PROBLEM. MAYBE SOMEONE FROM THE OUTSIDE CAN HELP OUT.
  4. thanks for your response but i had already figured it out to add the echo. Thats not the way it is supposed to be coded from the book, but it is the way i am coding it to get it to work. Thanks. I was coming here to mark "Solved" but I forgot the response time here is VERY GOOD here. Glad i joined this forum.
  5. i am having issues getting the variables to show up on localhost server within the body element. is it something in the codes or something in the php.ini settings? here is some sample code <h1>Skyward Aviation</h1> <h2>Contact Information</h2> <form action="ContactUpdate.php" method="get"> <table frame="border" rules="cols"> <colgroup width="50%" /> <colgroup width="50%" /> <tr> <td align="right" valign="top"> <p>First Name <input type="text" name="first_name" value="<?= $First ?>" size="36" /></p> <p>Last Name <input type="text" name="last_name" value="<?= $Last ?>" size="36" /></p> <p>Phone <input type="text" name="phone" value="<?= $Phone ?>" size="36" /></p> </td> <td align="right" valign="top"> <p>Address <input type="text" name="address" value="<?= $Address ?>" size="40" /></p> <p>City <input type="text" name="city" value="<?= $City ?>" size="10" /> State <input type="text" name="state" value="<?= $State ?>" size="2" maxlength="2" /> Zip <input type="text" name="zip" value="<?= $Zip ?>" size="10" maxlength="10" /></p> </td> </tr> </table> <p><input type="hidden" name="PHPSESSID" value='<?php echo session_id() ?>' /> <p><input type="submit" value="Submit" /></p> </form> In the page is shows <?= $First ?> in the area First Name textbox.
  6. Thanks both of you. That solved it. like i said i knew it would be something simple that i was overlooking. Thanks again.
  7. trying to figure this problem out. sucks being a newbie maybe i will gain enough knowledge to be able to help out others in the near future. <?php session_start(); $DBConnect = @mysqli_connect("localhost", "**********", "**********") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "skyward_aviation"; @mysqli_select_db($DBConnect, $DBName) Or die("<p>Unable to select the database.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $CustomerName = ""; if (isset($_COOKIE['customerName'])) $CustomerName = $_COOKIE['customerName']; $TableName = "mileage"; $Mileage = 0; $SQLstring = "SELECT SUM(mileage) FROM $TableName WHERE flyerID='{$_SESSION['flyerID']}"; $QueryResult = @mysqli_query($DBConnect, $SQLstring); if (mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); $Mileage = number_format($Row[0], 0) ; mysqli_free_result($QueryResult); } mysqli_close($DBConnect); ?> i know its a simple stupid error but cant remember nor figure it out. HERES THE ERROR Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\PHP_Projects\Chapter.10\FrequentFlyerClub.php on line 23
  8. no that is in the next section working on that now. but it is SUPPOSED!!(being the relative term) to work without cookies. llol
  9. thanks. i knew all it would take is another set of eyes to view it and solve. Had another issue but it was another simple mistake on mislabeling variables. But now i have the issue to where when it is trying to show results inside the body element <?= $FlyerID => but in the page it doesnt show up. How can i fix this? is it something in the php.ini file? Also for some reason when i go through the pages to the site it doenst hold the username and password and says i need to sign in again. What would cause that? Thanks again
  10. I am having an issue with this code. Im trying to find the problem listed as the error but i might need someone from the outside to look at it for me. <?php if (empty($_GET['email']) || empty($_GET['email_confirm']) || empty($_GET['password']) || empty($_GET['password_confirm'])) exit("<p>You must enter values in all fields of the Frequent Flyer Registration form! Click your browser's Back button to return to the previous page.</p>"); else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_GET['email'])) exit("<p>You must enter a valid e-mail address! Click your browser's Back button to return to the previous page.</p>"); else if ($_GET['email'] != $_GET['email_confirm']) exit("<p>You did not enter the same e-mail address! Click your browser's Back button to return to the previous page.</p>"); else if ($_GET['password'] != $_GET['password_confirm']) exit("<p>You did not enter the same password! Click your browser's Back button to return to the previous page.</p>"); else if (strlen($_GET['password']) < 5 || strlen($_GET['password']) > 10) exit("<p>Your password must be between 5 and 10 characters! Click your browser's Back button to return to the previous page.</p>"); $DBConnect = @mysqli_connect("localhost", "********", "********") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "skyward_aviation"; @mysqli_select_db($DBConnect, $DBName) Or die("<p>Unable to select the database.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $TableName = "frequent_flyer"; $Email = addslashes($_GET['email']); $Password = addslashes($_GET['password']); $SQLstring = "SELECT * FROM $TableName"; $QueryResult = @mysqli_query($DBConnect, $SQLstring); if (mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); do { if (in_array($Email, $Row)) exit("<p>The e-mail address you entered is already registered! Click your browser's Back button to return to the previous page.</p>"); $Row = mysqli_fetch_row($QueryResult); } while ($Row); mysqli_free_result($QueryResult); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$Email', '$Password', NULL, NULL, NULL, NULL, NULL, NULL, NULL)"; $QueryResult = @mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $FlyerID = mysqli_insert_id($DBConnect); mysqli_close($DBConnect); ?> <p>Your new frequent flyer ID is <strong> <?= $FlyerID ?></strong>.</p> here is the error on the page Parse error: syntax error, unexpected $end in C:\xampp\htdocs\PHP_Projects\Chapter.10\RegisterFlyer.php on line 73 Thanks for any help on this issue, ive been going crazy
  11. and everything worked properly after i added a whole line of code i missed (duhhhh me) THANKS again. How do i mark this as solved now? I am new to this forum. Sorry for the new posts didnt notice the "Modify" button. wont happen again
  12. now i realize what you were saying so i added $QueryResult = mysqli_query($DBConnect, $SQLstring) ahead of what you replied
  13. Thank you for your response. This is for a school assignment that is why i have to put the @'s in there and that is the way the code is in the book and that is how the instructor wants it but in working order. I have went throughout the assignment numerous times and it is exactly as the code in the book is supposed to be with the exception of it working lol. I would rather eliminate that section of code and just manually create the DB in phpMyAdmin but that block of code is supposed to check for the database and if its not there then CREATE it. Any further help to solve this would be greatly appreciated. Oh yeah and yes i am new to PHP as if anyone hasnt noticed lol
  14. Having an issue with this code, there are 3 parts and it is a simple guestbook type thing. But my problem is that it worked the first time I signed the guestbook but now its saying Unable to create the table. Error code 1050: Table 'visitors' already exists << I know it already exists but WHY is it trying to create it again? << Heres the code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guest Book</title> </head> <body> <?php if (empty($_GET['first_name']) || empty($_GET['last_name'])) die("<p>You must enter your first and last name! Click your browser's Back button to return to the Guest Book form.</p>"); $DBConnect = @mysqli_connect("localhost", "***********", "***********") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "guestbook"; if (!@mysqli_select_db($DBConnect, $DBName)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; echo "<p>You are the first visitor!</p>"; mysqli_select_db($DBConnect, $DBName); } $TableName = "visitors"; $SQLstring = "SELECT * FROM $TableName"; if (!$QueryResult) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to create the table.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; } $LastName = addslashes($_GET['last_name']); $FirstName = addslashes($_GET['first_name']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; echo "<h1>Thank you for signing our guest book!</h1>"; mysqli_close($DBConnect); ?> </body> </html> Can someone please point my to the right direction. Getting frustrated and I am assuming it is something quite simple i am overlooking. Thanks in advance.
×
×
  • 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.