Jump to content

CherryLips

Members
  • Posts

    12
  • Joined

  • Last visited

CherryLips's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I appreciate your insight. I am taking php as a required course for my Graphic Design / Web degree in a community college and the first half of the course consisted of the teacher reading powepoints to us. The second half was hands on database stuff and the final project is, "build your own shopping cart." So hopefully this explains why it looks like I have no idea what I'm doing as well as the lack of security. Also the book we got for this class is full of errors and is for php6 which I understand isn't really out. I am a total beginner and I really am thankful for all the help I've been getting here. That being said, I have a table on my products page in my shopping cart and I'd like to be able to display an image of the product at the end of the row for each item. Currently I have the image appearing on the product page in HTML which is where you can see each product individually and add it to the cart. I'd really like to make all the images appear on the products page but I'm not sure of the proper syntax to display the images from my while loop. On another page I have the image appearing when I write the tag in HTML: <img src="<?php echo $rec['IMAGE']; ?>"> When I write the tag for my while loop, Im clearly not using proper syntax because the image won't show up. If all I write is: echo "<td>".$rec['IMAGE']."</td>"; Then just the name of the file appears and not the image itself. I understand there is a lot I still need to learn but I am just trying to get the hang of the basics right now. Thanks for any and all of your help
  2. Here is the code for the table just in case you want to see the whole thing... The line in bold is the one that I can't get to work. <?php $conn = mysqli_connect("localhost","root","","skel"); $sql = "SELECT * FROM products ;"; $result = mysqli_query($conn, $sql); $row = 1 ; echo '<form name="form1" method="post" action="product.php">' ; echo "<table border='1'>"; while ($rec = mysqli_fetch_assoc($result)) { echo "<tr>"; echo '<td><input type="submit" name="btnPost" value="'.$rec['SKU'] . '"</td>' ; echo "<td>".$rec['NAME']."</td>"; echo "<td>".$rec['DESCR']."</td>"; echo "<td>".$rec['PRICE']."</td>"; echo "<td>"<img src=".$rec['IMAGE']">."</td>" echo "</tr>"; $row++ ; } echo '</table><br><br>' ; echo '<input type="submit" name="btnPost" value="Check Out (Shopping Cart)"></form>' ; mysqli_close($conn); ?>
  3. I'm trying to insert an image and this is my code: echo "<tr>"; echo '<td><input type="submit" name="btnPost" value="'.$rec['SKU'] . '"</td>' ; echo "<td>".$rec['NAME']."</td>"; echo "<td>".$rec['DESCR']."</td>"; echo "<td>".$rec['PRICE']."</td>"; echo "<td>"<img src=".$rec['IMAGE']">."</td>"; echo "</tr>"; $row++ ; I tried just echoing the .$rec['IMAGE'] without the img tag, but all it does is echo the name of the file instead of presenting the image itself. This is the code I'm using on another page in my HTML and it works fine, but I was curious how to insert the image inside my while loop. <img src="<?php echo $rec['IMAGE']; ?>">
  4. I think my cart is almost finished. I'm just getting this message when I try to change the quantity of an item in my shopping cart (the table is appearing empty): Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\skel\co_handler.php on line 24 I have attached the co_handler (checkout handler), the qty_handler and the checkout file. I read in the FAQ's for this thread that this is because my query failed. This confuses me because it works in other aspects of my cart. I have been looking over the code and I'm lost. I think this might have something to do with my qty handler? Any insight on where to start for reconciling this issue would be much appreciated. co_handler.php qty_handler.php checkout.php
  5. Does it matter if it is called QTY in my database table? I changed the name of the form field to QTY and its working. Thanks!
  6. I am building a shopping cart with three tables in one database and when I am trying to pass the quantity of an item to my product_handler file I am getting an undefined index error regarding my variable QTY. I thought this error was due to the name being typed incorrectly because that's when I've seen this before, but I can't figure out why this isn't working. Here is my error: Notice: Undefined index: QTY in C:\xampp\htdocs\xyzlabs3\product_handler.php on line 4 I have attached the product page and the product_handler page and I'm hoping someone can help. product.php product_handler.php
  7. It was telling me the system cannot find the file specified. I ended up just going into phpMyAdmin and copying and pasting everything. Worked like a dream.
  8. Hello, I am trying to load a txt file into mysql -uroot to create a database with all the tables and everything is prewritten. Here is what I thought I was supposed to write (but it's not working): mysql -uroot < skel_mysql.txt the skel_mysql.txt file is located in xampp/mysql/bin and this is a copy of the text in the file. CREATE DATABASE skel; USE skel; CREATE TABLE customers ( ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, LAST CHAR(20) NOT NULL, FIRST CHAR(20) NOT NULL, PHONE CHAR(20) NOT NULL, SESSID CHAR(32) NOT NULL ); CREATE TABLE products ( SKU INT NOT NULL PRIMARY KEY, NAME CHAR(20) NOT NULL, DESCR VARCHAR(40) NOT NULL, PRICE DECIMAL(9,2) NOT NULL, IMAGE VARCHAR(20) NOT NULL ); INSERT INTO products VALUES(1121,'Small Lab Coat','White Lab Coat Adult Small',15.75,'labcoat.png'), (1122,'Medium Lab Coat','White Lab Coat Adult Medium',15.75,'labcoat.png'), (1123,'Large Lab Coat','White Lab Coat Adult Large',16.75,'labcoat.png'), (1124,'Beaker Kit','Set of 5 different beakers',22.05,'beakers.png'), (1125,'Petri Dishes','Set of three',9.99,'petri.png'), (1126,'Safety Glasses','Women's Safety Glasses',15.75,'wmglass.png'), (1127,'Mens Safety Glasses','Men's Safety Glasses',15.75,'mglass.png'), (1128,'Kids Safety Glasses','Kid's Safety Glasses',15.75, 'kglass.png'), ; CREATE TABLE cart ( ID CHAR(32) NOT NULL, DATE DATETIME NOT NULL, QTY INT NOT NULL, SKU INT NOT NULL ); Side note: I thought there was an error in my database so I dropped it and rewrote the code in a txt file and now I dont want to rewrite everything in the cmd prompt. This is for a simple shopping cart assignment Im doing for a PHP class.
  9. Thank you! I feel like an idiot because the issue was in my HTML and not PHP. I am beyond thankful Will set error reporting now.
  10. Hello, I am completely new to PHP and taking at the community college. My first assignment was to create a form and so I decided to create a calculation form. My problem is that it isnt returning any output and I think there may be an issue with the submit button. I am using xampp and I also have dreamweaver connected to my server. I haven't quite fifured out the error reporting for apache, but dreamweaver is giving no syntax errors. The link to my form is http://www.cherrycreatives.com/php/calculate_form.html and http://www.cherrycreatives.com/php/calculate.php Here is the code for each file(they are also attached): <!doctype html> <html> <head> <meta charset="UTF-8"> <title>PHP Form by Carrie Carrigan</title> </head> <body> <form method="post" action="calculate.php"> <p>Value: 1 <input type="text" name="val1" size=10></p> <p>Value: 2 <input type="text" name="val2" size=10></p> <p>Calculation:</p> <input type="radio" name="calc" value="add"> add <br> <input type="radio" name="calc" value="subtract"> subtract <br> <input type="radio" name="calc" value="multiply"> multiply <br> <input type="radio" name="calc" value="divide"> divide <br></p> <p><input type="button" name="submit" value="calculate"> </p></form> </body> </html> ------------------------------------------------------------------------------- <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Calculation Result</title> </head><?php if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] == '')) { header("Location: calculate_form.html"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2]; } ?> <body> <p>The result of the calculation is: <?php echo "$result"; ?></p> </body> </html> calculate.php calculate_form.html
  11. Hi Everyone! I am new to PHP and taking a course for it at Red Rocks Community College near Denver Colorado. Currently I am working on my first calculation form and for some reason I am struggling. Hopefully I can figure it out on my own, otherwise I might be looking for answers soon.
×
×
  • 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.