Jump to content

adi123

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by adi123

  1. It worked, thanks for your help. I changed the code to this: if ($size > 1048576) { echo "<p class=\"error\">The image file size is larger than 1MB. Please reduce the size of the image and try again</p>"; $errors = true; } else if ($size < 1048576) { The file size was being checked in bytes, which was the mistake
  2. I have changed the name to tmp_name. I now get an error message saying: Notice: Undefined index: file in /upload.php on line 30 Notice: Undefined index: file in /upload.php on line 31
  3. I need help with uploading an image to my website. I would like an error to be printed when an image is bigger than 1mb, but the nothing happens. Any help please, been trying to figure out what the problem is for a couple of days know. The code is below: <?php error_reporting(0); $error_msgs = array(); $errors = false; //define ("MAX_SIZE","400"); //$max_size = "400"; function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if($_SERVER["REQUEST_METHOD"] == "POST") { $image = $_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo "<p class=\"error\">Unknown Image extension</p>"; $errors = true; } else { $size = filesize($_FILES['file']['name']); if ($size > 1024) { echo "<p class=\"error\">The image file size is larger than 1MB. Please reduce the size of the image and try again</p>"; $errors = true; } else { if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if ($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=800; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); $newwidth1=200; $newheight1=($height/$width)*$newwidth1; $tmp1=imagecreatetruecolor($newwidth1,$newheight1); $newwidth2=50; $newheight2=($height/$width)*$newwidth2; $tmp2=imagecreatetruecolor($newwidth2,$newheight2); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,$width,$height); $filename = "images/". $_FILES['file']['name']; $filename1 = "images/small_". $_FILES['file']['name']; $filename2 = "images/thumb_". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagejpeg($tmp2,$filename2,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); imagedestroy($tmp2); } } } } if (empty($_FILES['file']['name'])) { if (isset($_POST['Submit'])) { echo "<p class=\"error\">Please select an image!</p>"; $errors = true; } } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { header("Location: success.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta content="en-us" http-equiv="Content-Language"> <title>Image Upload</title> <link href=".css" media="screen, projection" rel="stylesheet" type="text/css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <style type="text/css"> a:link { color: #00F; } a:visited { color: #00F; } .error { color:#F00; } </style> </head> <body> <form method="post" action="" enctype="multipart/form-data" name="form1"> <p>Picture</p> <input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/> <p>Image maximum size <b>400 </b>kb</span></p> <input type="submit" id="mybut" value=" Upload " name="Submit"/> </form> <p> </p> <p><a href="images/">Images Folder</a></p> </body> </html>
  4. the error is that the page does not exist. The url only works when you type "www.mysite.co.uk/1245ady" but I want the url to work when you type "www.mysite.co.uk/ady".
  5. I am trying to change the url for my users on my website. The link is like this: www.mysite.co.uk/user.php?u_id=1245&username=ady I would like the link to be read as: www.mysite.co.uk/ady The code is below: RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([a-zA-Z0-9]+)\/?$ user.php?username=$1 I get an error on the page when using this code. Can someone please help. Can't figure out the error.
  6. I would like the page to echo without reloading, if its possible. Its part of a form when the user clicks an option another list menu appears below
  7. I am trying to display another list menu when "Ready Made" is selected from prod_type through an if statement but nothing happens. I don't know what the error is, can some one help please. <select name="prod_type" id="prod_type" style="padding:5px;"> <option>Select Product Type</option> <option>Ready Made</option> <option>Unstiched</option> </select> <?php if ($prod_type == 'Ready Made') { echo "<p>Size:</p>\n"; echo " <p>\n"; echo " <label>\n"; echo " <select name=\"prod_size\" id=\"prod_size\" style=\"padding:5px;\">\n"; echo " <option selected=\"selected\">Select Size</option>\n"; echo " <option>32</option>\n"; echo " <option>34</option>\n"; echo " <option>36</option>\n"; echo " <option>38</option>\n"; echo " <option>40</option>\n"; echo " <option>42</option>\n"; echo " <option>44</option>\n"; echo " <option>46</option>\n"; echo " <option>48</option>\n"; echo " <option>50</option>\n"; echo " <option>52</option>\n"; echo " <option>54</option>\n"; echo " <option>56</option>\n"; echo " <option>58</option>\n"; echo " <option>60</option>\n"; echo " </select>\n"; echo " </label>\n"; echo " <a href=\"#\" class=\"style7\">Check Size Chart </a></p>\n"; } else { echo ""; } ?>
  8. Thanks for your replies. I have fixed the problem. It was a sql problem with the pictures column in the database, which wasn't defined properly. my mistake. Works fine now.
  9. the images display properly in html code but disappear in php output.
  10. The html works fine but the php doesn't display properly. here's the difference. HTML <div class="product_box margin_r40"> <div class="image_wrapper"> <a href="../shops/adysshop/items/IMG_6724.JPG" class="jqzoom" rel='gal1' title="Product Preview" > <img src="../shops/adysshop/items/IMG_6724_small.jpg" title="triumph" style="border: 4px solid #666;"> </a> </div> <br/> <p> </p> <div class="clearfix" > <ul id="thumblist" class="clearfix" > <li><a class="zoomThumbActive" href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: '../shops/adysshop/items/IMG_6724_small.jpg',largeimage: '../shops/adysshop/items/IMG_6724.JPG'}"><img src='../shops/adysshop/items/IMG_6724_thumb.jpg'></a></li> <li><a href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: './imgProd/IMG_6972_small.jpg',largeimage: './imgProd/IMG_6972.JPG'}"><img src='imgProd/thumbs/IMG_6972_thumb.jpg'></a></li> <li><a href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: './imgProd/IMG_6900_small.jpg',largeimage: './imgProd/IMG_6900.JPG'}"><img src='imgProd/thumbs/IMG_6900_thumb.jpg'></a></li> </ul> </div> </div> PHP echo '<div class="product_box margin_r40">'; echo '<div class="image_wrapper">'; echo '<a href="../shops/'.$row['s_page'].'/items/'.$row['pic'].'" class="jqzoom" rel="gal1" title="Product Preview"><img src="../shops/'.$row['s_page'].'/items/'.$row['pic_small'].'" title="triumph" style="border: 4px solid #666;"></a>'; echo '</div>'; echo '<br/>'; echo '<p> </p>'; echo ' <div class="clearfix" >'; echo '<ul id="thumblist" class="clearfix" >'; echo '<li><a class="zoomThumbActive" href="javascript:void(0);" rel={gallery: "gal1", smallimage: "../shops/adysshop/items/IMG_6724_small.jpg",largeimage: "../shops/adysshop/items/IMG_6724.JPG"}><img src="../shops/adysshop/items/IMG_6724_thumb.jpg"></a></li>'; echo '<li><a href="javascript:void(0);" rel={gallery: "gal1", smallimage: "./imgProd/IMG_6972_small.jpg",largeimage: "./imgProd/IMG_6972.JPG"}><img src="imgProd/thumbs/IMG_6972_thumb.jpg"></a></li>'; echo '<li><a href="javascript:void(0);" rel={gallery: "gal1", smallimage: "./imgProd/IMG_6900_small.jpg",largeimage: "./imgProd/IMG_6900.JPG"}><img src="imgProd/thumbs/IMG_6900_thumb.jpg"></a></li>'; echo '</ul>'; echo '</div>'; echo '</div>'; It looks about right so why is it not working.
  11. that didn't work. Is there any other way to do this because the links in the html need to be changed in php to that from the database
  12. I am trying to output the following html code in php using echo, but it won't display properly. Can someone help me echo the following lines please, already spend a few days on it. <div class="product_box margin_r40"> <div class="image_wrapper"> <a href="../shops/adysshop/items/IMG_6724.JPG" class="jqzoom" rel='gal1' title="Product Preview" > <img src="../shops/adysshop/items/IMG_6724_small.jpg" title="triumph" style="border: 4px solid #666;"> </a> </div> <br/> <p> </p> <div class="clearfix" > <ul id="thumblist" class="clearfix" > <li><a class="zoomThumbActive" href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: '../shops/adysshop/items/IMG_6724_small.jpg',largeimage: '../shops/adysshop/items/IMG_6724.JPG'}"><img src='../shops/adysshop/items/IMG_6724_thumb.jpg'></a></li> <li><a href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: './imgProd/IMG_6972_small.jpg',largeimage: './imgProd/IMG_6972.JPG'}"><img src='imgProd/thumbs/IMG_6972_thumb.jpg'></a></li> <li><a href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: './imgProd/IMG_6900_small.jpg',largeimage: './imgProd/IMG_6900.JPG'}"><img src='imgProd/thumbs/IMG_6900_thumb.jpg'></a></li> </ul> </div> </div>
  13. I know this is probably a very obvious question and a noob for asking, but I just want to know? If you are creating a big commercial shopping website, should you squash the source code of your pages together so it makes it harder to read by the public. I have noticed that on websites like eBay or Amazon there source code is squashed together and really complicated.
  14. Noticed quite a lot of stubborn people on this website who think they know it all and have a problem helping others. I think this is the answer to your problem. <a href="your link">some text</a>
  15. I have three insert queries. I would like the file to check if the query is successful before proceeding to the next page. The if statement works fine without $result2 and $result3. Here is my code: <code> $qry = "INSERT "; $qry2 = "INSERT "; $qry3 = "INSERT "; $result = mysql_query($qry); $result2 = mysql_query($qry2); $result3 = mysql_query($qry3); //Check whether the query was successful or not if($result, $result2, $result3) { header("location: success.php"); exit(); } else { die("Query failed"); } </code>
  16. Finally solved the problem. The Sql statement was the reason for results multiplying by 4.
  17. It doesn't make a difference when I put where the item comes from. I have just noticed when I remove shops from the sql equation, it shows properly but with it there, results how 4 times more. How do I stop it from multiplying the results by 4
  18. I am selecting data from two tables in the database. The results show up correctly but four times instead of one. I checked the code and there is no loop. Can anyone please tell me what I have done wrong to make the result appear four times instead of one. <?php $category_id=$_GET['category_id']; include('pagination/paginator.class.php'); $query = "SELECT COUNT(*) FROM products ORDER BY category_id"; $result = mysql_query($query) or die(mysql_error()); $num_rows = mysql_fetch_row($result); $pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; // Number of pages to display. Must be odd and > 3 $pages->paginate(); echo $pages->display_pages(); echo "<span class=\"\">".$pages->display_jump_menu().$pages->display_items_per_page()."</span>"; $query = "SELECT products.p_id, item, description, price, pic, shops.s_page FROM products, shops WHERE category_id='$category_id' ORDER BY category_id ASC $pages->limit"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_row($result)) { echo '<div class="product_box margin_r40">'; echo '<div class="image_wrapper">'; echo '<img src="shops/'.$row['5'].'/items/'.$row['4'].'" width="100" height="100" />'; echo '<p><strong>'.$row['1'].'</strong></p>'.$row['2'].'<p><strong>£'.$row['3'].'</strong></p>'; echo '<p class="style7"><strong><a href="view.php?action=view&id='.$row['0'].'">View Item</strong></a></p>'; echo '<p><a href="cart.php?action=add&id='.$row['0'].'"><img src="images/add_to_cart.jpg" alt="Add To Cart" width="80" height="20" /></a></p>'; echo '</div>'; echo '</div>'; } echo "<table width='650'>"; echo "<th>".$pages->display_pages(); echo "<p class=\"paginate\">Page: $pages->current_page of $pages->num_pages</p>"; echo "<p class=\"paginate\">Items: $pages->limit (retrieve records $pages->low-$pages->high from table - $pages->items_total item total / $pages->items_per_page items per page)</th></p>"; echo "</table>"; ?>
  19. I have a zip code with this pattern if(preg_match("/zip/i",$field)) { if(!preg_match("/^[0-9]{5,5}(\-[0-9]{4,4})?$/", $value)) { $errors[] = "$value is not a valid zipcode."; } } the zip code is formed using the code below: function getStateCode() { $stateCode = array(1=> "AL" , "AK" , "AZ" , "AR" , "CA" , "CO" , "CT" , "DE" , "DC" , "FL" , "GA" , "HI" , "ID" , "IL" , "IN" , "IA" , "KS" , "KY" , "LA" , "ME" , "MD" , "MA" , "MI" , "MN" , "MS" , "MO" , "MT" , "NE" , "NV" , "NH" , "NJ" , "NM" , "NY" , "NC" , "ND" , "OH" , "OK" , "OR" , "PA" , "RI" , "SC" , "SD" , "TN" , "TX" , "UT" , "VT" , "VA" , "WA" , "WV" , "WI" , "WY" ); return $stateCode; } function getStateName() { $stateName = array(1=> "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"); return $stateName; } The code above doesn't form a valid zip code CODE tags are neat.
  20. SOLVED THE PROBLEM WITHOUT ANY HELP FROM THIS WEBSITE>...
  21. theres a tutorial on this link for what you are trying to do: http://api.joomla.org/__filesource/fsource_Joomla-Framework_HTML_joomlahtmlpagination.php.html
  22. I have tried debugging the sql statement. On the checkout page i get the error : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Membership.php on line 18 All i need is the id of the user from login to be passed to the checkout page, so i can get user info from the details table. can someone please provide some help, on getting the id.
  23. this is the code on the login page require_once 'dbcon.php'; require_once 'Membership.php'; $membership = new Membership(); // If the user clicks the "Log Out" link on the index page. if(isset($_GET['status']) && $_GET['status'] == 'loggedout') { $membership->log_User_Out(); } // Did the user enter a password/username and click submit? if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) { $response = $membership->validate_User($_POST['username'], $_POST['pwd']); } this is the code after login, where it should get id of the user echo $membership->getCustId($un, $pwd);
  24. I am trying to get the user id after login so i can get data from another table with the same user id. heres my code. membership.php <?php require 'Mysql.php'; class Membership { function getCustId($un, $pwd) { $con = mysql_connect("DB_SERVER","DB_USER","DB_PASSWORD"); mysql_select_db("DB_NAME", $con); if (!$con) { die('Could not connect: '.mysql_error()); } //$customer_id=""; $sql = "SELECT id FROM login WHERE username ="."$un"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $customer_id=$row{'customer_id'}; echo $customer_id; } mysql_close($con); return $customer_id; $postid = $_POST['customer_id']; } function validate_user($un, $pwd) { $mysql = New Mysqlcon(); $ensure_credentials = $mysql->verify_Username_and_Pass($un, md5($pwd)); $customer_id = $_GET['customer_id']; /*error_log(1,"#### customer ID=$customer_id","0"); if($customer_id) { $_SESSION['customer_id'] = $customer_id; }*/ if($ensure_credentials) { $_SESSION['status'] = 'authorized'; $_SESSION['username'] = ucfirst($un); //$ref = $_SERVER['http_referrer']; //header( 'refresh: 5; url='.$ref); header("location: ../cart/checkout.php?name=$un&id=$customer_id"); } else return "Please enter a correct username and password"; } function log_User_Out() { if( isset($_SESSION['status']) && isset($_SESSION['username']) ) { unset($_SESSION['status']); unset($_SESSION['username']); if(isset($_COOKIE[session_name()])) setcookie(session_name(), '', time() - 1000); session_destroy(); } } function confirm_Member() { session_start(); if($_SESSION['status'] !='authorized') header("location: ../login/login.checkout.php"); } } ?> mysql.php <?php class Mysqlcon { private $conn; function __construct() { $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database.'); } function verify_Username_and_Pass($un, $pwd) { $query = "SELECT * FROM login, customerDetails WHERE username = ? AND pwd = ? AND login.id = customerDetails.id LIMIT 1"; if($stmt = $this->conn->prepare($query)) { $stmt->bind_param('ss', $un, $pwd); $stmt->execute(); if($stmt->fetch()) { $stmt->close(); return true; } } } } ?>
  25. I have a login script which displays the username after login. I am trying to display the firstname but the firstname is in a different table. The two tables are login and customer info, the login table containing the id, username and pass. The customer info table contains all of the customers personal info with the same id as login. function verify_Username_and_Pass($un, $pwd) { $query = "SELECT firstname FROM login, customer_info WHERE username = ? AND pwd = ? AND login.id = customer_info.id LIMIT 1"; if($stmt = $this->conn->prepare($query)) { $stmt->bind_param('ss', $un, $pwd); $stmt->execute(); if($stmt->fetch()) { $stmt->close(); return true; } } } function validate_user($un, $pwd) { $mysql = New Mysqlcon(); $ensure_credentials = $mysql->verify_Username_and_Pass($un, md5($pwd)); if($ensure_credentials) { $_SESSION['status'] = 'authorized'; $_SESSION['username'] = ucfirst($un); header("location: myprofile.php"); } else return "Please enter a correct username and password"; } <p>Hello <? echo $_SESSION['firstname']; ?> (<?php echo $_SESSION['username']; ?>) </p> firstname does not show
×
×
  • 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.