Posted By

kkw on 08/28/11


Tagged


Versions (?)

add-new-item


 / Published in: PHP
 

URL: add-new-item

  1. <?php
  2. include ('connection.php');
  3.  
  4. // check why quotations saved as quatations in the database
  5.  
  6. $item = addslashes($_POST['name']); // addslashes is to add \ backslashes before characters that need to be quoted in database
  7. $price = addslashes($_POST['price']); // addslashes is to add \ backslashes before characters that need to be quoted in database
  8.  
  9. // Remove html tags from the fields (security)
  10. $item = strip_tags($_POST['name']);
  11. $price = strip_tags($_POST['price']);
  12.  
  13. // Remove spaces from the price field
  14. $price = str_replace(' ','',$price);
  15.  
  16. if ($item =='' or $price=='') { header('location:msg_missing-fields.php'); }
  17.  
  18. else {
  19.  
  20. // Insert the item in the items table in the database
  21. $query_insert_item ="INSERT INTO items SET item='$item', price='$price'";
  22. $result_insert_item =mysql_query($query_insert_item);
  23.  
  24. header('location:msg_item-added.php');
  25.  
  26. }
  27.  
  28. ?>

Report this snippet  

You need to login to post a comment.