Jump to content

whiskedaway

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by whiskedaway

  1. Thanks, for that, it's all working now. I suppose I should have known that, but I haven't used mysqli for a while (have been using query() instead) and have forgotten everything.
  2. I have a series of PHP files that are referenced in index.php like this: <?php include("credentials.inc"); $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); include('header.php'); include('menu.php'); include('contact.php'); include('home.php'); ?> One of my files, menu.php, brings up a JavaScript menu that was coded in Dreamweaver (yes, I cheated). However, it seems to get to the first "for" statement and stops. I can't work out what I've done wrong. <?php $h1 = mysqli_query($cxn, "SELECT areaID, area FROM area ORDER BY areaID"); echo("<ul id='MenuBar1' class='MenuBarHorizontal'>"); echo("<li><a href='index.php'>HOME</a></li>"); echo("<li><a href='#' class='MenuBarItemSubmenu'>PRODUCTS</a><ul>"); for ($a=0;$a<=count($h1);$a++) { echo("<li><a href='#' class='MenuBarItemSubmenu'>".$h1[$a]['area']."</a><ul>"); $h2 = mysqli_query($cxn, "SELECT catID, category, areaID, link FROM category WHERE areaID = '".$h1[$a]['areaID']."' ORDER BY catID"); for ($b=0;$b<count($h2);$b++) { echo("<li><a href='".$h2[$b]['link']."'>".$h2[$b]['category']."</a></li>"); } echo("</ul></li>"); } echo("</ul></li>"); echo("<li><a href='services.php'>SERVICES</a></li>"); echo("<li><a href='aboutus.php'>ABOUT US</a></li>"); echo("<li><a href='contact.php'>CONTACT</a></li></ul>"); ?> Hopefully someone has an idea of where the problem is. Thanks so much in advance!
  3. Oh gotcha. Here's the new error message: Couldn't execute query 2. Unknown column 'quantity' in 'field list'. And I think I just figured it out myself. The column is named quantity in ItemsOrdered, but it's quantityOnHand in Stock. Gah. Thanks so much for your help, I can't believe I made such a stupid error.
  4. Sorry, I don't get what you mean.
  5. Oh, I didn't even notice that. Here's the output: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/nabira/chelbig/adelaidebooks/receipt.php on line 23 Couldn't execute query 2. Line 23 is: or die ("Couldn't execute query 2.".mysqli_error());
  6. Unfortunately, that hasn't yielded any results: Couldn't execute query 2: If you want to have a look at it yourself, it's up at http://www.caitlin-helbig.com/adelaidebooks/receipt.php and you can use an orderID of 00000001.
  7. I keep getting the error "Couldn't execute query 2." which is why I think there's a problem with my query 2 syntax. I've tried these four changes to the query: $sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity') WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = quantity + '$quantity' WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = quantity + $quantity WHERE sku = '$sku'"; $sql2 = "UPDATE Stock SET quantity = (quantity + $quantity) WHERE sku = '$sku'"; It just won't work at all. The only other thing I can think of is that maybe the PHP before it is wrong, but I can't see an error in that either.
  8. I'm having a problem with my second query. I've included the PHP around it as it might help to see what I'm trying to do. $sql = "SELECT quantity, sku FROM ItemsOrdered WHERE orderID = '$_POST[orderID]'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query 1."); $rowname = mysqli_fetch_assoc($result); extract ($rowname); $sql2 = "UPDATE Stock SET quantity = (quantity + '$quantity') WHERE sku = '$sku'"; $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute query 2."); Can someone see what the problem is? I think it has to do with the quantity = (quantity + '$quantity') part.
  9. I'm really stuck, so I'm hoping someone might be able to help. I'm using PHP5 and I can't work out how to get each different row to display. Currently the first row displays over and over again until there are no more rows left in the table. So far this is what I've done: <?php include("credentials.inc"); $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT o.orderID, i.sku, i.quantity, o.staffID FROM Orders o, ItemsOrdered i WHERE o.orderID = i.orderID"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); $num = mysqli_num_rows($result); $rowname = mysqli_fetch_assoc($result); extract ($rowname); ?> <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <tr><td><strong>OrderID</strong></td><td><strong>SKU</strong></td><td><strong>Quantity</strong></td><td><strong>StaffID</strong></td></tr> <?php $i=0; while ($i < $num) { //something here to change the values of $orderID, $sku, $quantity and $staffID ?> <tr><td><?php echo $orderID; ?></td><td><?php echo $sku; ?></td><td><?php echo $quantity; ?></td><td><?php echo $staffID; ?></td></tr> <?php $i++; } ?> </table> Hope someone can help!
  10. Thank you, changing the table name from Order to Orders fixed it. Can't believe I'd forgotten about that!
  11. I'm having heaps of trouble getting one of my PHP/MySQL queries to work for some reason (and the funny thing is there are plenty that are identical to it all the way through the site) so I'm wondering if someone can spot the problem. (I've basically torn all the code apart trying to work it out and have changed values that are being submitted, etc to try and get it to work, so I'm tearing my hair out now!) $staffID = $_POST['staffID']; $date = date("Y-m-d h:i:s"); $sql2 = "INSERT INTO Order (date, staffID) VALUES ('$date', '$staffID')"; $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute insert into order query."); As it's not working, I keep getting "Couldn't execute insert into order query." The MySQL database is named Order, and has orderID, date and staffID. orderID is int(8 ), unsigned zerofill and autoincrement. date is datetime, and staffID is int(4) unsigned zerofill. Staff members enter the zeros in their staffID when putting their details into the form (so would enter 0004). Here's the full code: createorder.php <?php include("credentials.inc"); switch (@$_POST['do']) { case "neworder": $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $staffID = $_POST['staffID']; $sku = $_POST['sku']; $quantity = $_POST['quantity']; $sql = "SELECT staffID FROM Staff WHERE staffID = '$staffID'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute staff query."); $num = mysqli_num_rows($result); if ($num > 0) { //staff member found $date = date("Y-m-d h:i:s"); $sql2 = "INSERT INTO Order (date, staffID) VALUES ('$date', '$staffID')"; $result2 = mysqli_query($cxn, $sql2) or die ("Couldn't execute insert into order query."); $sql3 = "SELECT orderID FROM Order WHERE date = '$date'"; $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute select from order query."); $rowname = mysqli_fetch_assoc($result3); extract ($rowname); $sql4 = "INSERT INTO ItemsOrdered (orderID, sku, quantity) VALUES ('$orderID', '$sku', '$quantity')"; $result4 = mysqli_query($cxn, $sql4) or die ("Couldn't execute insert into ItemsOrdered query."); header("Location: success4.php"); } else { $message = "Staff member does not exist.<br />"; include("createorder.inc"); } break; default: include("createorder.inc"); } ?> createorder.inc <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Adelaide Books</title> <link href="style.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="body"> <table id="main" cellspacing="0px"> <tr><td id="logo" colspan="3"> <img src="images/logo.gif" alt="Adelaide Books"/></td> <td class="space"> </td> <td class="right"> </td></tr> <tr><td class="left"> </td> <td class="space"> </td> <td id="text"> <h1>Create New Order</h1> <form action="createorder.php" method="POST"> <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <?php if (isset($message)) { echo "<tr><td style='color:red' colspan='2' >$message <br /></td></tr>"; } ?> <tr> <td width="75px" align="right">Staff ID:</td> <td><input type="text" name="staffID" size="25" maxsize="50"></td> </tr> <tr> <td width="75px" align="right">SKU:</td> <td><input type="text" name="sku" size="25" maxsize="50"></td> </tr> <tr> <td width="75px" align="right">Quantity:</td> <td><input type="text" name="quantity" size="10" maxsize="20"></td> </tr> <input type="hidden" name="do" value="neworder"> <tr> <td colspan="2" align="center"><input type="submit" name="neworder" value="Submit"></td> </tr> </table> </form> <br/> <br/> <br/> <br/><a href="orders.php"><img src="images/back.gif" alt="Back" border="0" /></a></td> <td class="space"> </td> <td class="right"> </td></tr> </table> </div> </body> </html> Hope someone can help!
  12. Thank you! I added <input type="hidden" name="do" value="search"> and that fixed everything. I knew I'd done something really dumb!
  13. I'm actually getting no output at all, even with putting print_r($array);. I would assume that opening the page I'd get no output, but when I run the query, it should work. Here's the full code for both of the pages, hopefully it might be something that's not in the first code snippets: <?php session_start(); if (@$_SESSION['auth'] != "yes") { header("Location: management.php"); exit(); } include("credentials.inc"); switch (@$_POST['do']) { case "search": $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT staffID, name, address, phone FROM Staff WHERE staffID = '$_POST[staffID]'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); $rowname = mysqli_fetch_assoc($result); extract ($rowname); $echoName = "<tr><td><strong>Name:</strong></td><td>$name</td></tr>"; $echoID = "<tr><td><strong>ID:</strong></td><td>$staffID</td></tr>"; $echoAddress = "<tr><td><strong>Address:</strong></td><td>$address</td></tr>"; $echoPhone = "<tr><td><strong>Phone:</strong></td><td>$phone</td></tr>"; print_r($array); include("stafflook.inc"); break; default: include("stafflook.inc"); } ?> stafflook.inc <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Adelaide Books</title> <link href="style.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="body"> <table id="main" cellspacing="0px"> <tr><td id="logo" colspan="3"> <img src="images/logo.gif" alt="Adelaide Books"/></td> <td class="space"> </td> <td class="right"> </td></tr> <tr><td class="left"> </td> <td class="space"> <form action="stafflookup.php" method="POST"> Staff ID: <input type="text" name="staffID" size="25" value=""><br/> <input type="submit" name="Search" value="Search"></form></td> <td id="text"> <br/> <br/> <br/> <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <?php if (isset($echoID)) { echo "$echoID";} if (isset($echoName)) { echo "$echoName";} if (isset($echoAddress)) { echo "$echoAddress";} if (isset($echoPhone)) { echo "$echoPhone";} ?> <tr><td width="75px" align="right"> </td><td> </td></tr> </table> <br/> <br/> <br/> <br/><a href="management2.php"><img src="images/back.gif" alt="Back" border="0" /></a></td> <td class="space"> </td> <td class="right"> </td></tr> </table> </div> </body> </html>
  14. I think I've made a silly mistake somewhere, but I can't find it, so any help would be appreciated! I've used if (isset) in other parts of my website and it works fine, but I can't get it working here. Basically, the PHP is meant to run a query on my database and return $staffID, $name, $address and $phone, and then is meant to be displayed in a table that is located in stafflook.inc. Code snippets: $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT staffID, name, address, phone FROM Staff WHERE staffID = '$_POST[staffID]'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); $rowname = mysqli_fetch_assoc($result); extract ($rowname); $echoName = "<tr><td><strong>ID:</strong></td><td>$name</td></tr>"; $echoID = "<tr><td><strong>ID:</strong></td><td>$staffID</td></tr>"; $echoAddress = "<tr><td><strong>ID:</strong></td><td>$address</td></tr>"; $echoPhone = "<tr><td><strong>ID:</strong></td><td>$phone</td></tr>"; include("stafflook.inc"); stafflook.inc: <table width="250" border="0" align="center" cellpadding="2" cellspacing="2"> <?php if (isset($echoID)) { echo "$echoID";} if (isset($echoName)) { echo "$echoName";} if (isset($echoAddress)) { echo "$echoAddress";} if (isset($echoPhone)) { echo "$echoPhone";} ?> </table> If someone can see where I've made a mistake, it'd be greatly appreciated.
  15. Thank you. I suppose this is what happens when you teach yourself a programming language by referencing tutorials and not a text book -- you call things by the wrong name!
  16. I'm really hoping someone can help me. I have been searching for a few days on information regarding IDs in PHP -- that is, when you get a URL that looks like /index.php?id=46 or whatever the ID number is. Basically, what I want to do is call a particular MySQL statement depending on its ID within the database, but I only want to use one page to call each different one. I'm assuming that you do it using this ID function, but I can't find anything that tells me how to do it. Everytime I do a search throughout forums and search engines, I come back with a million entries that are referencing web addresses that have nothing to do with what I'm searching for, or parts of words, such as slendid. Can anyone point me in the right direction, or explain to me how it works? Thanks so much in advance.
  17. Wonderful, peranha's suggestion worked a treat. Thanks guys!
  18. Thanks for your quick reply. However, I've just changed it like you said, and I'm now getting this error message: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/.reet/whiskedaway/blog/add.php on line 32 Line 31 and 32 are the lines that look like this: $sql = "INSERT INTO news (username, date, title, post) VALUES ('$row['realname']', '$date', '$addtitle', '$addblog')";
  19. I just can't work it out. Basically, what I'm trying to do is access the members database and grab the realname information. My user logged in with a username on the previous PHP page, and it's saved in session. However, instead of the database saving the realname, it keeps saving "Array" instead. Here's my code: <?php session_start(); if (@$_SESSION['auth'] != "yes") { header("Location: index.php"); exit(); } include("logs.inc"); switch (@$_POST['do']) { case "add": $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql = "SELECT realname FROM members WHERE username = '{$_SESSION['logname']}'"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query 2."); $row = mysqli_fetch_assoc($result); extract ($row); $addtitle = $_POST['addtitle']; $addblog = $_POST['addblog']; $date = date("Y-m-d"); $sql = "INSERT INTO news (username, date, title, post) VALUES ('$row', '$date', '$addtitle', '$addblog')"; $result = mysqli_query($cxn, $sql) or die ("Couldn't execute query."); header("Location: successadd.php"); break; default: include("addnews.inc"); } ?> Any help would be really appreciated!
  20. There's a problem with that statement: $staff = mysqli_fetch_array($result3) or die("Couldn't execute fetch array"); if ($staff[0] == "Super Administrator") { It brings up "Couldn't execute fetch array".
  21. It's still not working. Oh and I queried the database just to make sure it was actually returning "Super Administrator", and it is. So it's a problem with the code.
  22. Thanks, I forgot that statement. *headdesk* However, it's still not working. Here's the updated code: $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql3 = "SELECT status FROM members WHERE username = '$_POST[fusername]'"; $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute query 3."); $staff = mysqli_fetch_assoc($result3); if ($staff == "Super Administrator") { $message = "Super Admin.<br />"; } else { $message = "You do not have permission to post comments.<br />"; }
  23. Hi everyone! I was hoping you might be able to pick up what I've done wrong. $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql3 = "SELECT status FROM members WHERE username = '$_POST[fusername]'"; $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute query 3."); if ($result3 == "Super Administrator") { $message = "Super Admin.<br />"; } else { $message = "You do not have permission to post comments.<br />"; } Even when the status of the user is "Super Administrator", it is skipping the if bracket and going straight to the else. So I think there's a problem, probably with the way I'm calling $result3 in the if statement. If anyone can help, it would be greatly appreciated. Thank you!
×
×
  • 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.