Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP problem...


  • Please log in to reply
4 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:10:41 AM

Posted 08 September 2009 - 12:34 AM

Posted Image
EDIT: Picture may take a while to load...

I have a table that looks like the above, if the user enters data on two or more lines of the table, how would i get PHP to add the data to the database without giving all the feilds different names? I'm guessing it's going to have a while command in there, checking to see if the number of rows is bigger than number of rows of data entered insert it in, but i don't know where to start coding it. I know how to enter single variables into the database.

I'm also aiming to have any records already in the database display in the table then the line under have input fields so the customer can input new information still.

My other problem is that this site is going to be access by 3 or more people adding information, i figured i could have the results in an iframe that refreshes every 5 seconds? Or is there a better way of doing this?

Thanks in advance,

~Kam

Edited by KamakaZ, 08 September 2009 - 12:36 AM.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:41 PM

Posted 08 September 2009 - 01:17 PM

INSERT INTO mytable VALUES (1,2,3,4,5,6);

Providing that the table has 6 columns, then each value in the sql statement has a value for each column. If you want to add to multiple rows, it is like this:
INSERT INTO mytable VALUES (1,2,3,4,5,6), (7,8,9,10,11,12);

The easy solution would be to restrict the users to one row at a time anyway.

So what happens when someone is entering data into the form and it reloads? Page requests are not asynchronous, so the user is not going to be able to do anything while the frame is reloading. And if it is happening every 5 seconds, people are going to get irritated. It is better to use some javascript. When the page that dispays the form loads, store the time the database was last updated. Use Ajax to query the database. If the updated time on the server is newer than the time stored on the page, and nobody is entering information into the form, then update the page. Otherwise, wait until the user submits the information, and just refresh then.

#3 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:10:41 AM

Posted 08 September 2009 - 05:04 PM

i was thinking of using a variable like $i, querying to see how many rows of the table they entered data in, and have while ($i < $numberOfRows) { INSERT.... ++$i}

I was only going to display the results in an iframe, the inputs would not be inside this and would not be getting refreshed with the iframe - i have an example here http://202.45.110.174/guestbook-new.php

I would love to restrict them to only one row at a time, but they want to be able to add multiple jobs at any one time...

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:41 PM

Posted 08 September 2009 - 06:06 PM

They can only enter information one field at a time anyway. Unless they are an octopus. So no matter what, they can only physically enter information sequentially. And anyway, the database is only going to handle one transaction at a time. The sample I showed you above will enter multiple records, but it still can only do one record at a time.

There is a reason that UI conventions are used; users are stupid, prone to making mistakes, have no idea what they really want, and will do things that are completely unexpected. If they do something stupid on one set of data, no big deal. What if they use an unsupported date format on multiple jobs? How are you going to handle the form validation for that? You will have to cache all of the data, and then write a mechanism to step through each record and correct it, re-saving each record as you go. Or you trust that your users are going to enter information perfectly (they never do), and do no error checking. Then face the wrath of your users when they have to keep re-entering data.

So before anybody gets bent out of shape thinking "I'm not stupid, I know how to use software," that is generally because the designers took the time to make things as fool-proof as possible.

#5 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:10:41 AM

Posted 08 September 2009 - 11:46 PM

ok, so i am going to have to have INSERT (column1, column2, column3) VALUES (field1, field2, field3),(field4,field5,field6);

i have started on the error checking side of things already, what i was mean above was, when they fill in multiple rows of the table above, i want PHP to check the number of rows they've filled in, then insert the values accordingly...

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users