
emvy03
Members-
Posts
62 -
Joined
-
Last visited
Never
Everything posted by emvy03
-
Apologies for being thick!! I'm assuming the query the server will execute is: INSERT INTO products (product_name,price,details,category,date_added,small,medium,large) VALUES('$product_name','$price','$details','$category',now(),'$small','$medium','$large') Cheers lads!
-
Okay, here's the code for my 'add_item' page. I'm new to php so i'm anticipating there to be a few errors :-\ <?php if(isset($_POST['product_name'])){ $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category= mysql_real_escape_string($_POST['category']); $details = mysql_real_escape_string($_POST['details']); $small = mysql_real_escape_string($_POST['small']); $medium = mysql_real_escape_string($_POST['medium']); $large = mysql_real_escape_string($_POST['large']); $sql = mysql_query("SELECT id FROM products Where product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); if($productMatch > 0){ echo 'Sorry, that product name already exists <a href="add_item.php">click here</a>"'; exit(); } $sql = mysql_query("INSERT INTO products (product_name,price,details,category,date_added,small,medium,large) VALUES('$product_name','$price','$details','$category',now(),'$small','$medium','$large'") or die(mysql_error()); $pid = mysql_insert_id(); $newname = "$pid.jpg"; move_uploaded_file($_FILES['fileField']['tmp_name'],"../shop/images/$newname"); $sql = mysql_query("SELECT * FROM products"); $test = mysql_num_rows($sql); if($test = 5){ echo 'Uploaded Successfully. Click <a href="add_item.php">here</a> to add another item or go to <a href="inventory_list.php">your store list</a>'; exit(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Lad Label Home</title> <link rel="stylesheet" href="../shop/style/style.css" type="text/css" /> </head> <body> <div align="center" id="mainWrapper"> <? include "../pagecomponents/header.php"; ?> </div> <div id="pageContent"> <div align="right"> <a href="index.php">Manager Home</a> <a href="inventory_list.php">Back to Store List</a> </div> <div align="left"> <h2>Add New Item</h2> <form action="add_item.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post" > <table width="100%" border="0"> <tr> <td width="20%">Product Name</td> <td width="80%"><label> <input name="product_name" type="text" id="product_name" size="64" /> </label> </td> </tr> <tr> <td>Price</td> <td><label> £ <input name="price" type="text" id="price" size="12" /> </label> </td> </tr> <tr> <td>Category</td> <td><label for="category"> <select name="category" id="category"> <option value="T-Shirt">T-Shirt</option> <option value="Hoody">Hoody</option> <option value="Polo">Polo</option> </select></label></td> </tr> <tr> <td>Details</td> <td><label> <textarea name="details" id="details" cols="64" rows="5"></textarea> </label> </td> </tr> <tr> <td>Sizes Available</td> <td><p> <label> <input type="checkbox" name="small" value="1" /> Small</label> <label> <input type="checkbox" name="medium" value="1" /> Medium</label> <label> <input type="checkbox" name="large" value="1" /> Large</label> </p> </tr> <tr> <td>Colours Available</td> <td> </td> </tr> <tr> <td>Product Image</td> <td><label><input type="file" id="fileField" name="fileField" /></label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add this Item" /> </label></td> </tr> </table> </form> </div> </div> <div id="pageFooter"></div> </div> </body> </html>
-
Hi guys, Sorry for the lack of the 'code' tags, won't happen next time! Thanks alot for the help, it's greatly appreciated. I am still getting a similar error: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1','1','1'' at line 2' Does it matter that I am doing things locally on my system and not live on a website yet? Ta very much.
-
Ok, So to start off with I have made a new column in the database table for each field, i.e. a 'small' column, 'medium' column, 'large' column since the check box is meant to represent clothing size. Then in my check box I have given each 'option' a respective name i.e. Small => 'small, Medium => 'medium', Large => 'large'. Then I have set a new php variable for each 'option' Then in my mysql query I have got: $sql = mysql_query("INSERT INTO products (product_name,price,details,category,date_added,Small,Medium,Large) VALUES('$product_name','$price','$details','$category',now()),'$small','$medium','$large'") or die(mysql_error()); However, when I run this code I get the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Small','Medium','Large'' at line 2 Any ideas. P.S. I'm trying to start off with the basics and then eventually write the code so that only selected values are uploaded. Cheers.
-
Hi, Ta for the quick reply. The only code I have is for for the checkbox: <p> <label> <input type="checkbox" name="size" value="small" id="size_0" /> Small</label> <label> <input type="checkbox" name="size" value="medium" id="size_1" /> Medium</label> <label> <input type="checkbox" name="size" value="large" id="size_2" /> Large</label> <label> <input type="checkbox" name="size" value="extralarge" id="size_3" /> Extra Large</label> I can connect to the mysql database fine, and can insert other fields, like normal text, but I don't know how to take the info from the check boxes and put them into the database. Cheers.
-
Hi, I am trying to build a shop and so need to build a page where the user can specify which sizes are available. I was therefore wondering if there is a way to grab the data from a check box group in a from and insert that into a row in a mysql table? Thanks.
-
Hi, Thanks alot for your replies! I was being a total prat, it was a path issue; I missed a '/' at the start of the code. Cheers for pointing it out.
-
Hi guys, I'm building a website in php and am trying to 'include' a php page into the main index file. However, the problem I have is that while images display fine in the standalone php file, when I 'include' this in my index file the images wont display. Instead I get the broken link symbol. Thanks.
-
Hi guys, I've been experimenting with a CMS, and have learnt quite a bit on how to script one. But what I want to do now is write the script so that in the index page, only the title is displayed but then when you click on the title it links you to the whole article. Is there a way to do this. function get_content($id = '') { if($id !=""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM ppyfc_content WHERE id= '$id'"; $return = '<p><a href="index.php">Go back to Content</a></p>'; else: $sql = "SELECT * FROM ppyfc_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) !=0): while($row = mysql_fetch_assoc($res)){ echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>'; echo '<div id="result">' . $row['home'] . ' ' . $row['score'] . ' ' . $row['away'] . '</div>'; echo '<div id="result">' . $row['home1'] . ' ' . $row['score1'] . ' ' . $row['away1'] . '</div>'; } This is the code to get and display the content from the database atm. Thanks lads/lasses.
-
Legend. Cheers for that mate.
-
Hi, Thanks for that guys. Also, I was wondering if there is a way to assign an id to a post when adding it to the database. The reason I ask is the current 'add-content' script doesn't assign an id to the posts and therefore the database won't accept the new post because the 'id' column can't be null. Hope I've explained it at least a little. Cheers guys.
-
Alright Lads. I've had a go at building a CMS using an apache server, but this is all local to my PC and I was wondering how to go about uploading it to the internet. The problem I think I am having is that I am using phpmyadmin locally, however when I upload the cms to the internet it tells me that it failed to connect to the database. I assume this is due to the fact the CMS is online, while the database is still saved locally. Apologies for asking such a daft question but I am really quite new to php scripting and web design. Cheers.