Pr0digy Posted January 31, 2010 Share Posted January 31, 2010 Hi! I am new to PHP but learning the basics. With the help of samples online i have managed to build a registration form that adds all the filled out info to the database and reads it back when a search field is used. People can register their computers based on the serial number. The database is made up like this: id serial 1firstname 1lastname 1emailaddress 2firstname 2lastname 2emailaddress etc. I can not figure out how to do the following: When a serialnumber is already registered but a new owner wants to add his/her information to the database, how can the form see if all the fields starting with '1' have already been filled out, then automatically put all the new information in the fields starting with '2' ? This is the code i use: $query = " INSERT INTO `records` ( `id`, `serial`, `1firstname`, `1lastname`, `1emailaddress`, ) VALUES ( '', '".$_POST['Serial']."', '".$_POST['Name']."', '".$_POST['LastName']."', '".$_POST['Email']."' ); Any help would be greatly appreciated Jay Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/ Share on other sites More sharing options...
RussellReal Posted January 31, 2010 Share Posted January 31, 2010 what? You mean if a current user sells his PC to someone lets say, and they want to register the PC on your site, she will not be able to because the serial number will already be taken? How exactly do you plan on handling such a situation? I really can't understand you, could you please reiterate the scenario in a more understandable way? Thanks! We'd love to help you, its just hard to understand you.. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004693 Share on other sites More sharing options...
Pr0digy Posted January 31, 2010 Author Share Posted January 31, 2010 I'm sorry, let me try again People can register anything with a serial number really. This is so that when an item is purchased, someone can see the history of that product (if previous owners have registered it on the site that is). It will show in what years it was previously owned and in what country etc (down the road) and if it has ever been reported stolen. You are correct, right now if a second owner wants to add their information to a serial number that's already in the database... it doesn't work because it has already been registered. So i want it to 'see' that and then move on to the next set of empty fields (2firstname, 2lastname etc) and put the information in there. I hope this helps Jay. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004694 Share on other sites More sharing options...
jl5501 Posted January 31, 2010 Share Posted January 31, 2010 I would assume that you are not planning to have fields in the same row for multiple registrations. If you are, you would be designing a maintenance nightmare. Yo need 1 row per registration with one set of fields in it. you can then link the rows as necessary to get a history, by searching on serial number Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004696 Share on other sites More sharing options...
Pr0digy Posted January 31, 2010 Author Share Posted January 31, 2010 "I would assume that you are not planning to have fields in the same row for multiple registrations. If you are, you would be designing a maintenance nightmare." That is exactly how it's currently setup "Yo need 1 row per registration with one set of fields in it. you can then link the rows as necessary to get a history, by searching on serial number" Sounds much better but that is way above and beyond my capabilities i'm afraid. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004698 Share on other sites More sharing options...
RussellReal Posted January 31, 2010 Share Posted January 31, 2010 do not do this, just insert new rows, and a date registered.. and then when a user PULLS UP the information, just do SELECT * FROM products WHERE serial = '$serial' ORDER BY register_date DESC ^^ that will show the most recent registration FIRST and then reverse-chronologically thereafter. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004699 Share on other sites More sharing options...
jl5501 Posted January 31, 2010 Share Posted January 31, 2010 Yes, that is the only sensible way to proceed. In addition to showing the history in the way RussellReal suggested, you would check for a serial number already existing by a select * from products where serial = $_POST['serial'] and see if you get any rows. but that is not strictly necessary as you will be inserting a new record in any case. I would add that in my view it is easier to store the registration dates as unix timestamps, but how you do it is optional. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004702 Share on other sites More sharing options...
Pr0digy Posted February 1, 2010 Author Share Posted February 1, 2010 "SELECT * FROM products WHERE serial = '$serial' ORDER BY register_date DESC" This worked but it only shows me the last record of that serial number. (i made 3) I use this to call up the information after a search: <?php displayColumn('firstname'); ?> <?php displayColumn('lastname'); ?> etc. I deleted all the 2firstname, 2lastname etc. with "<?php displayColumn('firstname'); ?>" should it call up all 3 records from that serial number and display them or am i missing something? Jay Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004808 Share on other sites More sharing options...
jl5501 Posted February 1, 2010 Share Posted February 1, 2010 How are you extracting the records? You will need to have a loop like while($record = mysql_fetch_assoc($results)) { your code here } the $results will be the results of your query Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004874 Share on other sites More sharing options...
Pr0digy Posted February 1, 2010 Author Share Posted February 1, 2010 While i appreciate the feedback i have decided to hire someone and have it all done for me. Every question i ask generates more questions in return and i can't wrap my head around it lol. Any code i have so far is copy/pasted together from another friend's website so using second-hand-code, while amazingly i got this far, is not helping. I need it built from scratch for me and of course i do not expect this to be done for free on a forum Thanks Jay. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004877 Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 Just to reiterate, when you do a query you get a result SET. A set is 0 or more rows. When the result set is prepared in the sql server, it still has to be FETCHED. You do this in a loop because you don't know how many rows you might have in your result set --- it could be 0 or it could be a million or more, so you need to do the type of loop that jl5501 describes. In a nutshell, the reason you only see one row is that you are only fetching one row. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004878 Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 While i appreciate the feedback i have decided to hire someone and have it all done for me. Every question i ask generates more questions in return and i can't wrap my head around it lol. Any code i have so far is copy/pasted together from another friend's website so using second-hand-code, while amazingly i got this far, is not helping. I need it built from scratch for me and of course i do not expect this to be done for free on a forum Thanks Jay. Understandable, and a good choice. Far too often people come in and get in over their head. If you're not a programmer or a student who wants to be a programmer, it's far better to get someone who knows what they are doing. Best of luck with your project. Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004879 Share on other sites More sharing options...
Pr0digy Posted February 1, 2010 Author Share Posted February 1, 2010 Thank you I will be back Quote Link to comment https://forums.phpfreaks.com/topic/190469-check-if-a-field-is-filled-out-then-move-to-the-next-phpmysql/#findComment-1004880 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.