Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. class My_Db_Table extends Zend_Db_Table { public function overwriteMethod() { //do something parent::overwriteMethod(); } }
  2. function val($field = false) { global $dbc; $errors = false; $strlen = strlen($field); if($strlen > 3 && $strlen < 15) { $field = strip_tags($field); $field = trim($field); $field = htmlentities($field); $username = $field; $username = mysqli_real_escape_string($dbc,$username); echo $username; } else { $errors = "The field must be at least 3 characters long & no more than 15 characters!"; } if($errors) { return $errors; } } Try this and behold the magic of proper indentiation.
  3. this is a reference to the current object
  4. With the array is not wrong, with your code proably is.
  5. PHP != Java. Bye Bye!
  6. $to should contain only one e-mail address. All other e-mail address should be added to cc or bcc through the use of $headers.
  7. ignace

    drop down

    Assuming you want to select a subcategory: $link = mysql_connect("host","login","pass"); mysql_select_db("dbname", $link); $query = "select Category FROM categories"; $results = mysql_query($query, $link) or die("Error performing query"); if(mysql_num_rows($results) > 0){ echo("<select name=\"Category\">"); while($row = mysql_fetch_object($results)){ echo("<option value=\"$row->record_id\">$row->Category</option>"); } echo("</select>"); } else{ echo("<i>No values found</i>"); } if (!empty($_POST)) { if (empty($_POST['subcategory'])) { $query = 'SELECT id, subcategory FROM subcategories'; $result = mysql_query($query, $link); if (mysql_num_rows($result)) {// no need for > 0; if mysql_num_rows() == 0 then the if body won't be executed as 0 == false echo('<select name="subcategory">'); while (list($id, $subcategory) = mysql_fetch_array($result, MYSQL_NUM)) { echo("<option value=\"$id\">$subcategory</option>"); } echo('</select>'); } } else if (!empty($_POST['category'] && !empty($_POST['subcategory'])) { $cat = $_POST['category']; $subcat = $_POST['subcategory']; ..process.. } }
  8. There must be something wrong with your script, strpos() certainly accepts / as a needle. if ($pos = strpos('path/to/directory', '/')) { print 'at: '. $pos; } else { print 'no pos'; } prints "at: 4" strpos() has no special characters: if ($pos = strpos('path/to/directory?q=hello+world', '?')) { print 'at: '. $pos; } else { print 'no pos'; } prints "at: 17"
  9. Instead of just storing the available numbers, should you better store the path to the swf file and use a query like: SELECT * FROM movies ORDER BY RAND() LIMIT 1
  10. $selectUsername = !empty($_GET['username']) ? $_GET['username'] : null; .. $query = 'SELECT id, username FROM users'; $result = mysql_query($query, $db); // $db = mysql_connect() $htmlSelect = '<select name="users">'; while (list($id, $username) = mysql_fetch_array($result, MYSQL_NUM)) { $selected = !strcmp($username, $selectUsername) ? ' selected="selected"' : ''; $htmlSelect .= "<option value=\"$id\"$selected>$username</option>"; } $htmlSelect .= '</select>'; <form action="" method="post"> <label>Users: <?php print $htmlSelect; ?></label> </form>
  11. What about an a element that you make look like a button: <a href="cart.php?action=add&product=<?php print $row['id']; ?>">ADD TO CART</a>
  12. Here is the getip() function function getip() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; // shared internet } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; // behind a proxy } else { return $_SERVER['REMOTE_ADDR']; // directly connected to the internet } }
  13. What is %s? And I assume connect2db.php would be the login information for the msyql? (mysql_connect(blahblah)). So the contents of the table would be two columns, username and password, and the password in a sha1 hash? Thanks! %s is an identifier used by sprintf(): http://us3.php.net/manual/en/function.sprintf.php And yes connect2db.php is indeed creates the database connection And yes the password is a sha1() hash
  14. Yeah that will still work.
  15. ignace

    drop down

    $query = 'SELECT id, category FROM categories'; $result = mysql_query($query, $db); if ($result) { $htmlSelect = '<select name="category-select">'; while (list($id, $category) = mysql_fetch_array($result, MYSQL_NUM)) { $htmlSelect .= "<option value=\"$id\">$category</option>"; } $htmlSelect .= '</select>'; } <form action="" method="post"> ... <label>Category: <?php print $htmlSelect; ?></label> ... </form>
  16. You are probably selling more then just keyrings and adjusting the image to fit the keyring is actually just an extra service you provide towards your customers and possibly only for keyrings. So I'm questioning the importance of this service for your business? Ofcourse if your business is all about fitting images into keyrings. Then ofcourse you need a customized script and I would suggest going to job boards where you would place your script specification and they will provide you with their price on which you pick which one may start the development of this script.
  17. That's why I'm suggesting you'd better choose a system which satisfies the most of your needs. I am not entirely understanding what you are trying to do. Do you want the customer to create an image or take a photo of something they want and submit it to you with their details? I believe that would be an attachment. A server is accessible by both you (the owner) and your customers (24/7). You'll need a server anyway as you need people to be able to find you or find contact information (street address, phone number, fax number, e-mail address, ..). You will also need to start advertising your business, luckily the internet allows you to do this without spending to much money (for example: create a facebook account (or group) and add your customers as friends and keep them in the loop). All free of charge
  18. Where everyone would find it: Google! And if i'm not mistaken this is even posted in the wrong section.
  19. It's better to use timestamp's as they allow you to convert it to any format you want (remember to change timezone offsets on your db-server or web-server if they are not on the same machine or even in the same country).
  20. In your own best intrest you'd better use that what is available although it doesn't satisfy all your current ideas but I guess that in the end you want to make an income instead of being proud of something that doesn't do the trick. Plus, it's not only programming. You have to deal with other aspects aswell, like: usability, accessibility and findability. Especially the latter, if your customers can't find you, then you won't gain any income. If you build your application yourself with an insufficient knowlegde of the languages involved will surely break your application at some point which means you will lose income and this increases for every customer who is unable to use your application during that time. Decide on a system, template it to fit your specific style and you will be up-and-running in some good 3 days. And in the meantime learn the languages you need, perform research on several topics like usability, accessibility and findability (seo). Find out what the most common mistakes are with todays e-commerce systems (plus, learn where your competition fails) and apply their solutions and your common sense to your in-house product. And when it is finished, notify your customers that the website will be changing (altough make sure the change isn't to big or you may lose some) and launch it in the night, when their is no-one on the website. Have a nice cup of chocolate and head to bed
  21. You may want to take a look at the factory method design pattern: http://en.wikipedia.org/wiki/Factory_method_pattern
  22. A much cleaner version: session_start(); $defaultLanguage = 'en'; $languagesDirectory = '/path/to/languages/directory'; language_load($defaultLanguage); if (!empty($_GET['language']) && language_is_valid_code($_GET['language']) && language_is_supported($_GET['language'])) { $_SESSION['language'] = $_GET['language']; language_load($_GET['language']); } function language_is_valid_code($language_code) { return preg_match('/[a-z]{2}/', $language_code); } function language_get_path($language) { global $languageDirectory; return implode(DIRECTORY_SEPARATOR, array($languageDirectory, "lang.$language.php")); } function language_is_supported($language) { global $languagesDirectory; return file_exists(language_get_path($language)); } function language_load($language) { require_once language_get_path($language); }
  23. $languageCode = (!empty($_GET['language']) && is_lang($_GET['language'])) ? $_GET['language'] : 'en'; $languagesDirectory = '/path/to/languages/directory'; $languagesFile = "lang.$langCode.php"; //ie lang.en.php require_once $languagesDirectory . DIRECTORY_SEPARATOR . 'lang.en.php'; // default language (has all the applications translations) if(file_exists($langFile)) require_once $languagesDirectory . DIRECTORY_SEPARATOR . $langFile; // overwrites the default language //echo some stuff echo $lang['Welcome'];// if not overwritten outputs english otherwise the chosen language function is_lang($lang) { return preg_match('/[a-z]{2}/', $lang); }
  24. if (!empty($_GET['id']) && $_GET['id'] > 0) { $query = sprintf('SELECT * FROM table WHERE id = %u', (int) $_GET['id']); } else { $query = 'SELECT * FROM table'; }
  25. Check the below code i have added an row_id field which will pinpoint you wish row was selected, clicked and needs update'ing <?php session_start(); /** * @author Grant Kinsman * @copyright 2009 */ $dbhost = 'localhost'; $dbuser = 'root'; $dbpwd = 'wanker'; $conn = mysql_connect($dbhost,$dbuser,$dbpwd) or die ('Error connecting'); $dbname = 'karensKards'; mysql_select_db($dbname); $result = mysql_query('SELECT * FROM birthdays'); if (isset($_POST['submit'])) { $row_id = $_POST['row_id'];//now update this specific row $_SESSION['total'] += $_POST['price']; $_SESSION['prod']++; if (empty($_SESSION['cart'])) { $_SESSION['basket'] = array($numba => array( 'quantity' => 1, 'image' => $_POST['imgPath'], 'price' => $_POST['price'], 'info' => $_POST['details'])); } else { $_SESSION['basket'][$numba]= array( 'quantity' => 1, 'image' => $_POST['imgPath'], 'price' => $_POST['price'], 'info' => $_POST['details']); } } ?> <html> <head> <title>Mums Cards</title> <link rel="stylesheet" href="style.css" style="text/css" /> </head> <body> <div id="titleBar"> <p class="shopCar"><b>Cart</b><br> Items - <?php echo $_SESSION['prod']; ?><br> Total - £<?php echo $_SESSION['total']; ?> <a href="checkout.php" style="padding-left=0px">Checkout</a></p> </div> <div id="menu"> <a href="index.php">Home</a> <a href="products.php">Products</a> </div> <div id="main"> <div style="overflow:auto;height:630"> <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <?php while ($row = mysql_fetch_array($result)) { echo "<div class='prodInd'><img src='" .$row['imgPath']. ".jpg' style='width:125px;height:125px;margin-right:10px;float:left;cursor:pointer;' onclick='this.style.width=300;this.style.height=300' onmouseout='this.style.width=125;this.style.height=125' alt='" .$row['imgPath']. "'><br>"; echo $row['imgPath']. "<br>"; echo "Price:£" .$row['price']. "<br>"; echo "Details:" .$row['details']; echo "<input type='hidden' name='row_id' value='" .$row['id']. "'>"; // added, modify if necessary to the proper column name echo "<input type='hidden' name='image' value='" .$row['imgPath']. "'>"; echo "<input type='hidden' name='price' value='" .$row['price']. "'>"; echo "<input type='hidden' name='details' value='" .$row['details']. "'>"; echo "<input type='submit' name='submit' value='buy' style='float:right'></div>"; } ?> </form> </div> </div> </body> </html>
×
×
  • 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.