473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Editing or adding a record

AaronL
99
Hello,

I'm designing an e-commerce page and had a few questions.

What is the best way to edit a record? For example, I want to put an admin page together where I can edit an item for sale, change the image of the item, and change any other information.

Here is what I have so far which basically only creates the gui.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "<form action='post'>";
  3. echo "<table align='center' border='1'>";
  4. echo "<tr><td align='center' colspan='3' bgcolor='#C0C0C0'><b>Edit Product</b></td></tr>";
  5. echo "<tr><td><b>Product ID:</b> { product id }</td>
  6. <td colspan='2'><b>Title:</b> <input type='text' size='50' value='{ title }' /></td></tr>";
  7. echo "<tr><td colspan='3'><b>Catagory:</b> { catagory }</td></tr>";
  8. echo "<tr><td><b>List Price:</b> $<input type='text' size='5' name='list' /></td>
  9. <td><b>Our Price:</b> $<input type='text' size='5' name='price' /> <input type='checkbox' name='taxable' checked>Taxable?</td>
  10. <td><b>Shipping: $<input type='text' name='shipping' size='5' /></td></tr>";
  11. echo "<tr><td colspan='3'><br><center><b>Item Picture:</b> <input type='text' size='50' name='picture' /></center><br>
  12. <b>Description:</b><br><center><textarea rows='10' cols='50' name='description'>{ description }</textarea></center>
  13. <br><p align='right'>Preview</p></td></tr>";
  14. echo "</table>";
  15. echo "</form>";
  16. ?>
  17.  
That's just the basic gui, my main question is, how do I pull up a browse window to upload an image, and after I upload the image, how can I refresh the display on the edit window with the new image? Am I on the right track to creating this page?

Also, I plan on designing a username and password system. Do I mainly use cookies with that and pass the password along via POST amongst the pages and verify it with the user database everytime? I'd like this to be secure as well, and I know part of that is purchasing an SSL certificate etc...

I may be overthinking a lot of things and it's starting to discourage me.
May 8 '09 #1
6 1307
AaronL
99
Oh, and I would like to be able to add file filters to my image upload box to only upload .jpg files
May 8 '09 #2
Markus
6,050 Expert 4TB
@chelf
I think we all get that feeling sometimes.

First of all, you might consider not outputting all that html via PHP. Which would you say is the neater and more efficient of the below?

1.
Expand|Select|Wrap|Line Numbers
  1. echo "<div>";
  2. echo "<span>";
  3. echo "hi";
  4. echo "</span>";
  5. echo "</div>";
  6.  
2.
Expand|Select|Wrap|Line Numbers
  1. echo <<<EOF
  2. <div>
  3.   <span>
  4.     hi
  5.   </span>
  6. </div>
  7.  
Read: heredoc syntax.

To your second question. There is no _good_ way of knowing when a file has finished uploading. Your best option would be to have your file upload (html: <input type='file'>) on the same page, and also a submit button for it.

3rd question. You will want to look into sessions. Sessions persist until the browser is closed (or you specify otherwise) and that way you don't have to validate a person's password on each page load; just check that there is a session variable named, say, 'logged_in' set (you will set this when someone logs in).
May 8 '09 #3
AaronL
99
Ok, thank you for the advice, I modified my code as the followng:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo <<<EOT
  3. <form action='prodedit.php' method='post' enctype='multipart/formdata'>
  4. <table align='center' border='1'>
  5. <tr><td align='center' colspan='3' bgcolor='#C0C0C0'><b>Add Product</b></td></tr>
  6. <tr><td><b>Item Number:</b> { NEW }<input type='hidden' value='0' name='itemno' /></td>
  7. <td colspan='2'><b>Title:</b> <input type='text' size='50' value='{ title }' name='title' /></td></tr>
  8. <tr><td colspan='3'><b>Catagory:</b> { catagory }<input type='hidden' value='100' name='catagory' /></td></tr>
  9. <tr><td><b>List Price:</b> $<input type='text' size='5' name='list' /></td>
  10. <td><b>Our Price:</b> $<input type='text' size='5' name='price' /> <input type='checkbox' name='taxable' checked>Taxable?</td>
  11. <td><b>Shipping: $<input type='text' name='shipping' size='5' /></td></tr>
  12. <tr><td colspan='3'><br><center><b>Item Picture:</b> <input type='file' size='50' name='picture' /></center><br>
  13. <b>Description:</b><br><center><textarea rows='10' cols='50' name='description'>{ description }</textarea></center>
  14. <br><p align='right'><input type='submit' value='Add Product' /></p></td></tr></table></form>";
  15. EOT;
  16. ?>
  17.  
I have a few more questions:

I've gotten to the point where I wrote the product edit program and it takes the post data from this form and adds a record to the database. My first question is, I have an input type=file in there for image, I want the product edit program to upload that specific image to a directory, and reference it in the database. I understand the database part, but what is the best way to upload the image and error trap it in case that image name already exists and add it to the database?

I also noticed that my decimals for my prices are being removed, how do I get the .00 back in the price if the price is say $4.00? The variable type in mysql that I am using is decimal
May 8 '09 #4
Markus
6,050 Expert 4TB
@chelf
You will want to use file_exists() to see whether the image already exists. The 'add it to the database' part, I don't understand.

Using DECIMAL requires a little more information. Reading this should help you out (make sure you have the M and D values set in your database).
May 8 '09 #5
AaronL
99
Great! Thank you so much for your help!
May 8 '09 #6
Markus
6,050 Expert 4TB
@chelf
No problem. If you have a more specific question, start a thread and we'll give you a hand again.

Mark.
May 8 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script...
5
by: Ryan | last post by:
I have some software (written in Delphi 5) which has been working for several months without a problem. I have been given a copy of the database on our development server (SQL 7) and have...
1
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much...
2
by: Mark Perona | last post by:
I created an ASP.net form with an editable datagrid on it. I can create new records, and update and delete existing records. The problem I have is that I want a field in the grid to be editible...
12
by: dino d. | last post by:
hi everyone- my subject pretty much says it all- is there a secure way to do this? the non-secure ways are, as i understand it, to populate a listbox with indices as names, or maybe use a hidden...
5
by: sara | last post by:
Hi - I have 2 new questions in a new database I'm trying to develop. The first has 6 fields on a table and allows the user to enter them on a form. The form is bound to the table. All 6...
4
by: helenwheelss | last post by:
Access 2003, using a bound form. I'm seeing rather annoying behaviour when editing data in a control with a default value. It only happens when the form is on a new record. A specific...
0
by: irkahs | last post by:
Hey all, Need some Java help here. This is a code fragment that does a few things. 1) Allows adding to a RAF file. 2) Searches for a match and displays related records. and
4
by: jaz215 | last post by:
hi! how do i add a record in a database without using the datacontrol and adodc. i want to rework my code to using purely codes and not being dependent on the design on vb. so far i have. Set rs...
22
by: paul | last post by:
A crude, unlikely scenario just so I can get my head around this: Split DB; front end back end. Each user has the FE locally the BE is stored on a server. 1. UserA opens customerA's record and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.