Jump to content

bullbreed

Members
  • Posts

    110
  • Joined

  • Last visited

Everything posted by bullbreed

  1. Hi everyone I have a bit if an issue with some PHP i;ve been playing with. The following code is working fine to delete data from the database if (isset($_GET['p'])){ $namecheck = mysql_query("SELECT `name` FROM `store` WHERE `name` = '".$_GET["p"]." '"); $count = mysql_num_rows($namecheck); if ($count !== 0){ if ($_GET['sure'] === '1'){ mysql_query("DELETE FROM `store` WHERE `name` = '".$_GET["p"]."' LIMIT 1"); }else{ echo '<font size="2" color="#ff0000">Are you sure you want to delete this retailer? <a href="deleteretailer.php?p='.$_GET['p'].'&sure=1">Yes</a> or <a href="deleteretailer.php">No</a></font>'; } } } However if the name contains a & character such as A & B Engineering the echo message doesn't show and I can't delete the data from the database. Is the & character causing an issue as it only seems to affect those names containing it. Thanks B
  2. If you leave the insert set to php you only have to click it . Once you set it it stays set unless you change it. I dont know if there is a hotkey for it You could learn to type fast
  3. Yes In dreamweaver click on Window and make sure your INSERT menu is ticked. On your insert menu make sure that you select the php tab and you will see a button <? to click to create <?php ?> tags
  4. I'm sorry but im very new to php and dont understand :-\ Could you explain a little more please
  5. Hi Guys I have a page on my website that enables a customer to select a product, choose a colour and a size, create some custom text then send that data to my cart.php page. I'm not sure if I am doing this the correct way and haven't done a cart before. This form collects the data then posts it to the cart.php page <form action="cart.php" method="POST"> <input type="hidden" name="category" id="category" value="<?php echo $_GET['cid']; ?>" /> <input type="hidden" name="name" id="name" value="<?php echo $_GET['nid']; ?>" /> <input type="hidden" name="colour" id="colour" value="<?php echo $_GET['colid']; ?>" /> <input type="hidden" name="input" id="input" value="<?php echo $_POST['input']; ?>" /> <input type="hidden" name="fontselect" id="fontselect" value="<?php echo $_POST['fontselect']; ?>" /> <input type="hidden" name="sizeselect" id="sizeselect" value="<?php echo $_POST['sizeselect']; ?>" /> <div class="textinputgo"><input name="cart" type="submit" id="cart" value="Add to Cart" /></div> </form> This is the cart.php page which displays the product selections on the page; ( I have used tables for now but will change these to divs.) <h1>Shopping Cart</h1> <?php $submit = ($_POST['cart']); if (!isset($submit)){ echo 'Your cart is empty'; }else { //Form data $category = ($_POST['category']); $name = ($_POST['name']); $colour = ($_POST['colour']); $text = ($_POST['input']); $font = ($_POST['fontselect']); $size = ($_POST['sizeselect']); if (isset($submit)){ // This page displays the contents of the shopping cart. // Create a table and a form. echo '<table border="1" width="90%" cellspacing="3" cellpadding="3" align="left"> <tr> <td align="left" width="15%"><b>Category</b></td> <td align="left" width="15%"><b>Name</b></td> <td align="left" width="15%"><b>Colour</b></td> <td align="left" width="15%"><b>Text</b></td> <td align="left" width="10%"><b>Font</b></td> <td align="left" width="15%"><b>Size</b></td> </tr> '; echo '<tr>'; echo '<td align="left">' . $category . '</td>'; echo '<td align="left">' . $name . '</td>'; echo '<td align="left">' . $colour . '</td>'; echo '<td align="left">' . $text . '</td>'; echo '<td align="left">' . $font . '</td>'; echo '<td align="left">' . $size . '</td>'; echo '</tr>'; echo '</table>'; } } ?> My questions are; 1. How do I add the facility to increse the quantity of the products on the cart.php page? 2. If I go to another page then click on cart again the cart is empty so how do I keep the info in the cart? I'm assuming some sort of session but dont know how to do these. Thanks guyz
  6. Thanks for that. Please be aware that I have only been doing PHP for a couple of months now and at 36 yrs old its a bit like teaching an old dog new tricks. lol. Remember I come from a time of Commodore 64 and BBC Master 128. I changed the code to this; <?php $sql = "SELECT * FROM `products` WHERE `prod_name` = '".$_GET['nid']."' limit 1 "; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)){ $sizes = $row['prod_sizes']; $sizes = unserialize($sizes); $itemcount = count($sizes); } } ?> <label>Select a Size</label> <div class="textinput"> <select name="sizeselect"> <?php for ($i=0;$i<$itemcount;$i++) { ?> <option><?php echo $sizes[$i]; ?></option> <?php } ?> </select> So if I understand correctly, the issue was because the For (){} loop was performing a loop for each size option as an individual, hence individual menu form fields. But because I put the for(){} loop around only the <option>...</option> code this placed the data in one meny field. Thanks for your help.
  7. any ideas guyz and girlz For each size in the database I get an individual menu field so if there are 5 sizws I get 5 menu drop doen boxes
  8. How do I get them to show in one menu drop down. I remember reading somewhere about array-unique. Would this be used in the script. Im quite lost on this one.
  9. Ah yes, thank you. I set the size of the varchar to 10 (duh) he result is a little strange though now I changes it because I now get each size displayed in its own menu dropdown so if I have sizes S-M-L-XL they display in their individual drop down menus instead of all being in 1 menu drop down
  10. I have some serializes data in the db that holds the sizes of a product and i'm trying to unserialize it and show it in a menu form field but im having a few problems. Heres the code <?php $sql = "SELECT * FROM `products` WHERE `prod_name` = '".$_GET['nid']."' limit 1 "; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)){ $sizes = $row['prod_sizes']; $sizes = stripslashes($sizes); $sizes = unserialize($sizes); $itemcount = count($sizes); for ($i=0;$i<$itemcount;$i++) { ?> <div class="contwraps"> <label>Select a size</label> <div class="textinput"> <select name="sizeselect"> <option><?php echo $sizes[$i]; ?></option> </select> </div> </div> <?php } } } ?> Heres what it says on screen Notice: unserialize() [function.unserialize]: Error at offset 18 of 20 bytes in C:\xampp\htdocs\Fight-Stuff\CommunicoreCMS\includes\prodtype.php on line 92 Line 92 is - $sizes = unserialize($sizes); Whats wrong?
  11. I know some of the errors are due to the form not being completed so could I run the script from another page without the browser going to that page?
  12. Thanks for that. I did a little tinkering around and got it working but I have a few questions that probably need an advanced user. First of all here is the code <?php ini_set("display_errors", "1"); error_reporting(E_ALL); //Report any errors // Create a 165x45 image $im = imagecreatetruecolor(165, 45); $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // Get the Text String from the Text Field $string = $_POST['input']; // Get the Font Type from the Menu Field $font = $_POST['fontselect']; //Set the Path to the Font Directory $font_file = 'fonts/'; //Set the Path to the uploads folder $location = 'uploads/test.png'; // Make the background black imagefilledrectangle($im, 0, 0, 164, 44, $black); // Draw the Text from Text String using font size 14 imagefttext($im, 14, 0, 30, 30, $white, $font, $string); // Output the image to the browser header('Content-Type: image/png'); //Save the image to the uploads folder imagepng($im,$location); // Clear the image from memory imagedestroy($im); ?> Question 1 I get a few notices and errors as below. How do I sort these Warning: imagefttext() [function.imagefttext]: Could not find/open font in C:\xampp\htdocs\site\includes\prodtype.php on line 27 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\productdesign.php:11) in C:\xampp\htdocs\site\includes\prodtype.php on line 30 Question 2 I store the image that is created as 'test.png' in the 'uploads' folder but I tink I need to store it as something else because if 2 people are using the site at once the image will change to the latest users text so how would I store it related to the session? And would a user have to be logged in to start the session?
  13. is it somethiing to do with the imagepng($im);
  14. I am trying to create an image using PHP and GD library. What I want to do is; 1. User inputs required text 2. User selects a font from list 3. PHP and GD creates the image then saves it to the database in uploads folder 4. The generated image appears on screen after being called from the database The following code I did does most of this but the user form for this is on a page called productdisplay.php and the php script is on create text.php so when the image is created it doesn't yet save it but displays it on screen on create-text.php When the user runs the script I want to stay in the productdisplay.php page, save the image to the server then call it to the page. Heres my code <?php //Report any errors ini_set("display_errors", "1"); error_reporting(E_ALL); // Create a 165x45 image $im = imagecreatetruecolor(165, 45); $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // Get the Text String from the Text Field $string = $_POST['input']; // Get the Font Type from the Menu Field $font = $_POST['fontselect']; //Set the Path to the Font Directory $font_file = 'fonts/'; // Make the background black imagefilledrectangle($im, 0, 0, 164, 44, $black); // Draw the Text from Text String using font size 14 imagefttext($im, 14, 0, 30, 30, $white, $font, $string); // Output the image to the browser header('Content-Type: image/png'); imagepng($im); // Clear the image from memory imagedestroy($im); ?> What do I change to save the image, display on screen and stay on same page? Thanks B
  15. HI Guys I have some serialised data in my database related to the colour of a product. The data is actually a link to an image of a coloured square 22px x 22px representing a colour. In order to unserialise it and I used the following code; <?php $sql = "SELECT * FROM `products` WHERE `prod_name` = '".$_GET['nid']."' limit 1 "; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)){ $colours = $row['prod_colours']; $colours = stripslashes($colours); $colours = unserialize($colours); $itemcount = count($colours); for ($i=0;$i<$itemcount;$i++) { ?> <div class="colours"><a href="productdesign.php?nid=<?php echo $row['prod_name']; ?>&colid="<?php echo $row['prod_colours']; ?> > <?php echo '<img src="' .$colours[$i]. '">'; ?></a></div> <?php } } } ?> But when the colour is selected I need a nedw image to appear on screen which will be the product in the required colour. How do I add a value to the coloured square so when it is clicked I can call it as 'colid', meaning the page will be; prodtype.php?nid=value&colid=value associated with square image I hope I have explained ok.
  16. The code for the validation is at the top of the first code block and the problem isnt that it doesnt submit because it does. The problem is that the validation is there to make sure that all the fields are campleted before you submit it but currently the form will submit even if you do not fill it in.
  17. Hi. I have a form on a website which originally contained all form text fields and the validation worked fine until I was asked to add a Menu form field to it. Now the validation doesn't work at all and you can submit the form even if no values are entered in to the form. How do I validate menu form fields? Heres my code for the form with the validation (dreamweaver) <form action="cgi-bin/sendmail4.php" method="post" enctype="multipart/form-data" name="contact" target="_self" id="contact" onsubmit="MM_validateForm('fname2','','R','sname2','','R','email_from','','RisEmail','telephone2','','RisNum','postcode2','','R',,'Heard-about-us','','R''address2','','R','enquiry2','','R');return document.MM_returnValue"> <table width="100%" border="0" align="left" cellpadding="2" cellspacing="2"> <tr> <td valign="top"><p>First name: <br /> <input name="fname2" type="text" class="form" id="fname2" /> </p> </td> </tr> <tr> <td valign="top">Last name:<br /> <input name="sname2" type="text" class="form" id="sname2" /></td> </tr> <tr> <td valign="top">Address:<br /><textarea name="address2" cols="45" rows="5" class="form" id="address2"></textarea></td> </tr> <tr> <td valign="top">Email Address:<br /> <input name="email_from" type="text" class="form" id="email_from" /></td> </tr> <tr> <td valign="top">Telephone (No spaces)</td> </tr> <tr> <td valign="top"><label> <input name="telephone2" type="text" class="form" id="telephone2" /> </label></td> </tr> <tr> <td valign="top"><p>Postcode</p> <p> <input name="postcode2" type="text" class="form" id="postcode2" /> </p></td> </tr> <tr> <td valign="top">Where did you hear about us?<br /> <select name="Heard-about-us" type="text" class="form" id="Heard-about-us"> <option value="Internet Search">Internet Search</option> <option value="Received information in the post">Received information in the post</option> <option value="Yellow Pages or Yell.com">Yellow Pages or Yell.com</option> <option value="Saw a van or tanker">Saw a van or tanker</option> <option value="Existing customer">Existing customer</option> <option value="ICES year book">ICES year book</option> <option value="Municiple year book">Municiple year book</option> <option value="Other">Other</option> </select></td> </tr> <tr> <td valign="top"><label>Enquiry<br /> <textarea name="enquiry2" cols="45" rows="5" class="form" id="enquiry2"></textarea> </label></td> </tr> <tr> <td valign="top"><p> <input name="register2" type="submit" class="form" value="Send" /> </p> <p> </p></td> </tr> </table> </form> And here is the php form processor <?php ini_set('sendmail_from', 'martin@whateverurl.com'); $email_to = "martin@whateverurl.com"; $fname2 =$_POST['fname2']; $sname2 =$_POST['sname2']; $email_from =$_POST['email_from']; $telephone2 =$_POST['telephone2']; $heardabout =$_POST['Heard-about-us']; $postcode2 =$_POST['postcode2']; $enquiry2 =$_POST['enquiry2']; $address2 =$_POST['address2']; $email_subject = "Contact Page"; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; $message= "First Name: ". $fname2 . "\nLast Name: " . $sname2 . "\nEmail: " . $email_from . "\nTelephone: " . $telephone2 . "\nHeard About Us: " . $heardabout . "\nPostcode: " . $postcode2 . "\nAddress: " . $address2 . "\nEnquiry: " . $enquiry2; /* the message will contain the name and the comments */ $sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from'); if ($sent) { /*If sent direct customers to thankyou page */ header( "Location: http://www.whateverurl.com/thankyou.html" ); } else { /* If there is an error display an error message */ echo 'There has been an error sending your comments. Please try later.'; } ?> Thanks guys
  18. Hi Guys I'm trying (but failing) to unserialize some data in the database I have 5 image urls stored as a serialized array uploads/black.jpg uploads/white.jpg uploads/blue.jpg uploads/red.jpg uploads/pink.jpg The images associated with these urls are in the uploads folder How do I unserialize them and show them on screen. Here is my attempt (doesnt work) [syntax=php] <?php if (isset($_GET['cid'])){ $sql = "SELECT * FROM `products` WHERE `prod_cat` = '".$_GET['cid']."' "; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)){ $colours = unserialize($row['prod_colours']); $itemcount = count($colours); for ($i=0;$i<$itemcount;$i++) { ?> <div class="image-select"><?php echo $colours[$i]; ?></a></div> <?php } } } } ?> [/syntax] I get this notice Notice: unserialize() [function.unserialize]: Error at offset 40 of 50 bytes in C:\xampp\htdocs\folders\includes\prodcontent.php on line 24. But not sure what that is.
  19. Oh I see. Thats not quite what I wanted. You see the whole site currently runs off the index.php page, so the About Us page might be index.php?pid-2 This is so admin can add any page they wish in the cms. The site navigation is generated from the database when the admin adds a page. I would need to be able to add a page in the navigation but as its generated from the database i dont know how. Here is the code for the navigation <?php require_once('Connections/dbconnect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $query_menu = "SELECT * FROM webpages ORDER BY page_order ASC"; $menu = mysql_query($query_menu) or die(mysql_error()); $row_webpages = mysql_fetch_assoc($menu); $totalRows_menu = mysql_num_rows($menu); ?> <div id="topmenu"> <ul> <?php do { ?> <li><a href="index.php?pid=<?php echo $row_webpages['pid']; ?>"><?php echo $row_webpages['page_name']; ?></a></li> <?php } while ($row_webpages = mysql_fetch_assoc($menu)); ?> <li><a href="products.php">Products</a></li> </ul> </div> <?php mysql_free_result($menu); ?> In the example above I added a products.php page but this will always appear at the end of the navigation list as the current nav is called as a array How could I add the products.php page as a stand alone page in the middle of the nav array if that makes sense. Like this HOME ABOUT US PRODUCTS CONTACT where Home - About and Contact is generated from the code above?
  20. or is there another editor you use that does execute php?
  21. Hi guys. Not sure if this is in the right place. Have any of you had any dealings with CK Editor? I know it's a new version of FCK Editor but here is the problem. I have used it as an HTML editor in my CMS but I want to add a little php code in the source view of the editor but the editor doesn't run the script. My Navigation and page content is driven from the database (e.g. index.php?pid=1) So because there is only one page to my site I think i have to add all php into the CK editor because I don't know how to insert my own pages in between the dynamically generated pages. Whats your advice guys
  22. Hi. I'm looking for a little direction in creating my CMS project. I'm trying to create a dynamically driven navigation where the admin can add and remove pages. I have a form that ask for the following information Page Name - This is the text that is shown for the link Page Parent - For parent and child hierarchy Meta Title Meta Description Meta Keywords Page Content How do I create the links for the pages? I don't want the admin to have to type "about-us.php" I would like it so when the user adds (About Us) as a page name that the url says pid=2 or something like that. Any push in the right direction would be great.
  23. Hello When I am editing a product I have some of the data stored as an serialized array in the database. Can I use an echo statement like this value="<?php echo $row["rowname"]; ?>" to make sure checkboxes are already checked relating to the data in the database? If not, how do I do this?
  24. I had a look at W3C Schools (School at 36 years old) and came up with this to upload an image to a folder in the directory // Check for a front image. if ((($_FILES["pfrontimage"]["type"] == "image/gif") || ($_FILES["pfrontimage"]["type"] == "image/jpeg") || ($_FILES["pfrontimage"]["type"] == "image/pjpeg")) && ($_FILES["pfrontimage"]["size"] < 20000)) { if ($_FILES["pfrontimage"]["error"] > 0) { echo "Return Code: " . $_FILES["pfrontimage"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["pfrontimage"]["name"] . "<br />"; echo "Type: " . $_FILES["pfrontimage"]["type"] . "<br />"; echo "Size: " . ($_FILES["pfrontimage"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["pfrontimage"]["tmp_name"] . "<br />"; if (file_exists("uploads/" . $_FILES["pfrontimage"]["name"])) { echo $_FILES["pfrontimage"]["name"] . " This image already exists. "; } else { move_uploaded_file($_FILES["pfrontimage"]["tmp_name"], "uploads/" . $_FILES["pfrontimage"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["pfrontimage"]["name"]; } } } else { echo "Invalid file"; } But if I had say 5 images to upload would I duplicate this code 5 times on my page or could I use something like; if ((($_FILES["image1"]["type"] || $_FILES["pimage2"]["type"] || $_FILES["image3"]["type"] || $_FILES["image4"]["type"] || $_FILES["image5"]["type"] == "image/gif" || "image/jpeg" || "image/pjpeg") && ($_FILES["pfrontimage"]["size"] < 20000)) Would it be any better code and time wise to duplicate it 5 times ? Or would it be better to store them as an array or something. Also on another note; (nothing to do with the images above) when I come to edit a product and I echo out the info in the database like this <input name="prod_name" type="text" id="prod_name" size="25" value="<?php echo $row["prod_name"]; ?>"/> Can I do this echo statement with checkboxes in the form. This would mean if I used a checkbox to add some information on the addproduct.php page, when I come to edit it in editproduct.php the checkboxes will already be checked. If I uncheck a checkbox and click submit it will amend the database. Bear in mind though that the checkboxes I use store the info as an array and I serialize the info in the database.
×
×
  • 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.