Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Posts posted by jimfog

  1. I have made a table with a primary key that is set to auto increment every time. As I am doing various test in the particular table, many times, I delete rows. I notice though, that the auto increment value never starts from 1(after I have deleted all the rows of the table),it just continuesfrom where it was left last time.If the row I deleted had the value of 10, then the newly created row will have the value of 11, even if this is going to be the first row created, after deletion of previous rows. I use PHPMyAdminWhat can I do to fix this? I fixed it, the only thing that needed was to use the "empty table" command.

  2. For what it's worth, the registration code for my major application is 390 lines, and that doesn't even include any output or other include files. It reads or writes data in 12 database tables.
    When you say registration code...I assume you mean the registration process, and it reads/writes 12 DB tables.I never though that things can go so complicated. It seems that coming up with a DB design is more of an art. regarding my issue now: So, you are suggesting I gather all the business users in one table...
  3. Since the table structure is OK now I have to face another problem now.The logic is that the user fill in a forms where he says there if he is a regular user or a business user-depending on what he says in the form theuser_type column in the user table will get the corresponding value-as stated in a post above. The problem begins when we consider that the business users are divided into other categories, doctors, salons etc...and as such tables must be created foreach of these that will hold relevant data. As I see it, when a user declares being a doctor, we must enter a value in the user type column of the user table and add a record in thedoctor;s table-2 queries.What worries me, is that each time a user says he is a doctor or other business category, I must use If statements to check that and and inserta record in the corresponding table plus the original user table. If we have 7 business categories, that means around 7 if statements(if doctor then(insert in doctor's table) else if salon then(insert in salon's table)). I am trying to think if there is a more practical way to do this. what do you think? Am i clear, or do I have to clarify better, what I am trying to achieve here.

  4. The differences between the two forms are not big.In the business form, the user just fills also the type of business(carshop, hairdresser...etc). Of course all the other fields are common-name, username, password...etc.I think is is better to have one registration form and 1 function to handle it. An when the user who is going to register is a business I will just use javascript to reveal(the otherwise hidden) the corresponding fields. That is the plan I have come.

  5. I finally created the 2 tables, from the one(users) a foreign key goes to the other(usertype). This means the user_type column in the user table contains numeric values 0,1,2,3 etc. This, though, is bad if someone attempts to read the table-a human I mean.So, am I right to assume that a human readable database comes in contrast with a db that aims to be well organised-meaning that these are two conflicting goals.

  6. Suppose you have 2 types of users for your app, business and regulars, and these, fill in a different type of registration form, with different fields each. The question is, do you write one function for the registration, for both type of users, or 2 functions, each called depending on the user type. From your experience what you would do. I think of writing one, but complexity worries me.

  7. Yes, this where I should be looking into.There is something though that has caught my attention. AS I said I have created a foreign key between two tables-in the one table, and in the relation view, indeed a relation is shown between a columnwith the column in the other table. IN the second table though, in the relation view again, and in the column from which values are taken(as the foreign key points here), no relation is seen, the specific drop down menu field is empty. Is this the way foreign keys work, going from a table column to another table column in one way only, NOT bidirectional i mean? Or do you think there is an error somewhere? Probably this is the case, no errors, father-child table relationship.

  8. If you're looking at the table structure page, information about keys and indexes is given in the Indexes table below the column table.
    yes, I know what are you talking about but it does not mention which is the foreign key.It does mention the keyname and the column but it DOES NOT mention anything about foreign key.
  9. I use phpmyadmin to handle the db. I wrote a query to add a foreign key in an existing table, despite getting a success message that the query was completed, I cannot find an indication that a foreign key was indeed created. I mean, phpmyadmin seems not provide info saying for example "this column is the foreign key" as the case is when a column is the primary key. It does not say of course "this column is the primary key", but instead it highlights the word primary. I do not see an similar indication about foreign keys. The only thing maybe that gives the info i want is this "Relation view" option-I am not sure though.

  10. I assume that the enum_type column will be the user_type column in the user table. What about the the column in the user_type table where it will hold the value from the user_type column-the foreign key in other words. I do not know much about foreign keys.If we mark the the column in the user_type table-that will hold the value of the user_type column of the user table- as beingforeign, does that mean that this column will be of the same type as the column from where it gets the foreign key? And I assume it will be InnoDB tables

  11. SO, I should go for 2 tables.I did not quite understood your argument though...about changing text. Are you suggesting with this scheme, that in the user table, in the user type column(in addition with the user type table) I will have only numeric values where these will point/connect to this user_type table?

  12. I am constructing a table where the registered users of the site will be listed.These though are divided into 2 categories:

    • Regular Users
    • Business Users

    As such I am considering adding a column to the users table where it say if this specific user is business one or a regular. I am not sure though if this is the most optimal way to go.In other words I am creating a column which is value will be either "Business" or "Regular". And since the users will be many(either type) the above values will be appearing multiple times. Do you think there is a flaw in such a design,that I am storing redundant info? An maybe I should create a separate table?

  13. It doesn't have anything to do with a submit button, or a form, or $_POST specifically. It has to do with looping through an array using foreach. When you do this: foreach ($post as $key => $value) You are telling PHP to loop through the array and for each item to set the $key and $value variables to certain values in the array. You're telling it to set those variables. So obviously those variables are going to be set, there's no reason to check for that. There is no situation where you would tell PHP to set the variables and they would end up not getting set.
    You mean that with the foreach statement you cite(and which I also cite in the first post), the key and value variables take their value from the array create?This value assignment does not take-if I got it correct-does not take place upon hitting the submit button but when we use the foreach loop. Am I saying it now correctly? The variables named key and value could have other names of course.
  14. SO. in other words, no need to check for isset, since by definition, these array members will be set anyway upon hitting the submit button.Is that what you mean?Thanks for the help-I forgot to tell that.Developing needs patience, and it requires even more if you are trying to explain to someone else.

  15. It is only redundant in this specific context because you are already iterating through an array. You cannot iterate through members that aren't there, so by virtue of it being POST and a submitted form, but default they will already be "isset". So really checking for empty is only necessary, since an empty string will return true for empty(), as you would want in a validation conditional.
    You are mentioning that the "members aren't there" yet. Yes, but if someone hits the submit button then they start to exist. What I Understand, is that the reason that I must not check for the keys being set, is that this IS NOT an indication that the fields are filled, in contrast what holds with the values. That said, keys are set, even if the field is empty-so no checking must be made for these. Am I saying it correctly?
  16. perhaps from the beginning it would be better if you outlined the key components of your application beforehand. It's hard to help when every new answer brings about a new inclusion of application functionality, which would fundamentally change the just given answer. I know you're tired, and I'm not attacking you, but it saves a lot of time, rather than finding out the bigger picture 9 posts into the thread.
    You are not wrong, it was not in my intention to that the topic goes like this.I though that maybe it would be better to narrow the issue and focus on a part of the problem, solve that, and then from there continuemyself.I thought that if I asked from the beginning about the session issue, that would require an extensive answer and in addition posting the wholescript...anyway.
    So, what you need to do is set a control flow, of precedence, in your application. It seems like the first order of business is to check for $_SESSION, then check if a form was submitted, then default to showing the form. Assuming there are no other requirements to your application, here is an approach.
    I tried another approach-it works too, but if you think it has a flaw(which I cannot detect) say it: if(isset($_SESSION['valid_user'])){//member related functions} For the flag, I have some questions, but I am going to make in the other post, as you proposed. Regarding the key,(isset(key)),if I understood correctly, from the moment the user clicks,even if the fields of the form are empty, the keys of the array will be set.So, I must not use it when when checking if a user has filled a form. Not only for this example here in the topic, but in general.
  17. Well, the problem is this-sorry If I am not clear,I am hours in front of the PC:Here is the code, the complete, which includes your function. Id the user fills in the form and logins he will be shown member related content:

    if (isset($_POST['submit']))		 		  {if(filled_out($_POST))				 {			 $username = $_POST['username'];			 $passwd = $_POST['password'];			 if (login($username, $passwd)) {				 $_SESSION['valid_user'] = $username;				 output_header('output_header_list', $username);	             ....member related functions			 }		 }		 else		 echo   'you did not filled....';		 exit;	 }      output_login_form();

    The above works as I wanted. Here is the tricky part for which I started reconsidering the fill_out function.As you see above, a session is created. The problem is that when the user comes to the above page(AFTER THE SESSION IS CREATED)by simply opening a second tab,instead of seeing member content he sees the form. I am trying to build an IF statement that will detects the session and the user will get to see his member section. In the course I realized that maybe I must change filled_out for this to work, but it turned out to be a mess as you saw. So the problem is this, integrating an if (session==true) statement in the above code effectively. Sorry again, but I am tired.

  18. Certainly you got a point in what you say. let me explain why I ended up with such code.Suppose the user comes for the 1st time in index.php-then the login form should be displayed.But in the same page I need code where it will display output in case the user has filled the form. All of these in one page.The above logic is depicted by this:

    if(filled_out){//proceed with output}else{output_form()}

    The form action of the form is index.php itself.After the user fills the form/logs is=n he will be transferred to the code block which satisfies the if statement above. With your code I do not think I can do that.Of course you could argue that maybe the above logic is not the best-the fact is I am still trying to implement the best code here. And as the coding progresses I see sometimes that I need adjust my code.

  19. Here is the explanation as to why your code from the other topic does not do what I want in this specific scenario:Your code(the function, when it starts running) it outputs true.This has as a result that the following code will run:

    if(filled_out){//proceed with output}output_form

    The output contained in the block above, I do not wanted it to run when the user comes in the page in the first place.I wanted to run ONLY if has filled the form. With your code it gets run ANYWAY. Cause your function, outputs true.When the user comes in the page for the first time, I want him to go straight to the form. This can be done if the function outputs false(which your version does not in the first place). This is the logic-that is why a tweaked your function in the first place. Furthermore I am just trying to understand the overall logic here(and yours)-I have not reached a solid understanding yet.And the worst part is that when the conditions of the application change, code must be reworked again-not easy to do, Comments are welcome.

  20. I am trying to construct a function that will check if a form is filled, and if the form is indeed filled, then proceed and output some code. Despite I have made a similar question in the past, this one, is based on a different context. First of all, and before writing the function code, here is the underlying logic of the script, not unusual for a script that contains forms. if(filled_out){//proceed with output}else{output_form()} Here is filled_out:

    function filled_out($post){    $wasFilledOutCompletely = false;foreach ($post as $key => $value) {    if ((isset($key)) &&(empty($value)))  {	 $wasFilledOutCompletely =  true;	 echo'You did not fill the form entirely ';	 exit;  }	 else	    {$wasFilledOutCompletely =  true;	    echo 'Thanks';	 }    return $wasFilledOutCompletely;}}

    The code works OK if the both the fields of the form are empty-in which case "You did not fill the form entirely" is echoed.But if one field is filled and the other not, a "thanks" is echoed. It does not make sense, since the other field is still empty I should again get message that the form is not filled entirely. What complicates things, is that the code works as expected if I remove the else block-I cannot understand how this causes problems. Any ideas?

  21. yes...but if I do not set a name using CONSTRAINT, the indexes still get name, the name of the column. What it the point of giving them a name of our choice-such as tb_pk in the example above?That is one thing,the other, what is the reason giving name to a primary key(again look at the example above). The name that the primary key will take...will be PRIMARY.

  22. And how you can enforce to do that, without leaving that to the database...I am curious to hear how do you do it. And more important, are there any advantage if you do it yourself instead the db?

×
×
  • Create New...