Jump to content

zimmo

Members
  • Posts

    171
  • Joined

  • Last visited

Everything posted by zimmo

  1. Hi Muddy... sorry think I might not be clear. Breakdown of how this works. 1: User registers - sent email that activate account and have a user and pass to log in 2: They go through around 5 different forms to fill in and can edit at any time by coming back and logging in 3: Every other form is fine, its just this one with the if else query that has the problem. This form 1: The user fills in the form and clicks submit if no errors it then enters the information into the table in mysql. 2: The user comes back and wants to change their status from agent to dealer (dealer then requires the vat number) 3: If they select dealer and hit submit on the form it prompts them for the vat number (error check) 4: BUT the select option goes back to the default being Agent as that was what they first entered. So the problem is just that, it will not keep the state of dealer. Does that make sense?????? The post submit is from the same form, the page has 2 forms but they are the same and both have the same submit option on them. So when the user hits submit it goes through the error check each time.
  2. Hi Muddy, More about how this system works. First the user registers for an account which is seperate form etc.. and works fine. Then then fill in relevant information with this form being the problem I have. The post submit is where the error check kicks in, pointless otherwise. So when the user clicks the submit button it executes the script, but like I say if you choose agent and try and switch to dealer it does not as agent is already in the database.
  3. Do you mean this as its the same as the first form? <option value="Agent" <?php if($account_type == 'Agent') {echo 'selected="selected"';} ?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') {echo 'selected="selected"';} ?>>Dealer</option>
  4. I tried adding the following as well. But if you have chose agent it will not let you switch to dealer. <?php if ( $account_type =="Dealer") { echo '<p><label for="vat_number">VAT Number</label> <input class="short" value="'.$vat_number.'" name="vat_number" type="text" id="vat_number" /><br>'.$error['vat_number_error'].'</p>'; } ?> Just thought would show that above. Anyway, here is the code almost almost there, its the issue of coming back and trying to change. <?php if ( $_POST['submit'] ) { $account_type = $_POST['account_type']; $vat_number = $_POST['vat_number']; if ( empty($account_type) ) { $error['account_type_error'] = '<div class="formerror">Please select your Account Type.</div>'; } if ( empty($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">In order for Pegbookers to act as a dealer on your behalf you must enter a correct VAT number.</div>'; } elseif (!validVatnumberChars ($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">Please enter your VAT number as 123456789 (9 digits only).</div>'; } elseif (!validVatnumberLength ($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">In order for Pegbookers to act as a dealer on your behalf you must enter a correct VAT number</div>'; } elseif (!is_numeric($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">Please enter numbers only.</div>'; } $sql = 'SELECT * FROM fishery_e_bank WHERE fishery_id = \''.$_SESSION['fishery_id'].'\''; $sql_result = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($sql_result) ==0) { ob_start() ?> <form name="fishery_bank" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Fishery Bank Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') {echo 'selected="selected"';} ?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') {echo 'selected="selected"';} ?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form> <?php echo ob_get_clean(); ?> <?php } else { while ($row = mysql_fetch_array($sql_result)){ $account_type = $row["account_type"]; $vat_number = $row["vat_number"]; ?> <form name="fishery_bank" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Fishery Bank Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') {echo 'selected="selected"';} ?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') {echo 'selected="selected"';} ?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form> <?php } } ?>
  5. Further update on this. I have almost got it working. The code that I was given from muddy does work to a degree. This is the issue I have now. If the user first selects agent it does not require the vat number. If the user changes agent to dealer it tells them it needs the vat number but the drop down select goes back to its original state with agent selected. Now what will happen is they might not realise that it has gone back to agent and just enter the vat number and submit. This is where the major problem lies, we will not know that they are a dealer even though the vat number is there? Is there a way around this?
  6. Sorry I fixed that issue by putting the ; after the ' see below: <option value="Agent" <?php if($account_type == 'Agent') {echo 'selected="selected"';} ?>>Agent</option> I have tested it now and it still keeps defaulting back to the original status.
  7. I am now getting a syntax error using that code. Appreciate your time.
  8. Hi Firstly thanks for the tips, just out of interest why is it best to change to that way with the sql query. I understand about enclosing the php correctly, just missed that one. The form was in the original post. But here is the form again without the selected change on. I have 2 forms one for the first time submit and one for when they return to make a change. I know this may not be the best method, but it works for me and at this stage I just need to get it working, appreciate your time. <form name="details" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') echo "selected"?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') echo "selected"?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form> <? echo ob_get_clean(); ?> <? } else { while ($row = mysql_fetch_array($sql_result)){ $account_type = $row["account_type"]; $vat_number = $row["vat_number"]; ?> <form name="details" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') echo "selected"?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') echo "selected"?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form>
  9. I have just changed that and it is still defaulting back to the original?
  10. I have a form which allows someone to fill in and then come back to make changes should they need to. The problem I have is with the drop down. If you initially select the agent option it does not require the vat number. All fine. Then when they come back to make a change, they need to change the account type to dealer, it will not update as it keeps defaulting back to agent. I am stuck as to what to do to fix it. I want it to allow that option but then require the vat number. Here is my current code not including the connection etc.. as that is standard. <? if ( $_POST['submit'] ) { $account_type = $_POST['account_type']; $vat_number = $_POST['vat_number']; if ( empty($account_type) ) { $error['account_type_error'] = '<div class="formerror">Please select your Account Type.</div>'; } if ( empty($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">In order for Pegbookers to act as a dealer on your behalf you must enter a correct VAT number.</div>'; } elseif (!validVatnumberChars ($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">Please enter your VAT number as 123456789 (9 digits only).</div>'; } elseif (!validVatnumberLength ($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">In order for Pegbookers to act as a dealer on your behalf you must enter a correct VAT number</div>'; } elseif (!is_numeric($vat_number) AND ($account_type=="Dealer")) { $error['vat_number_error'] = '<div class="formerror">Please enter numbers only.</div>'; } $sql = "SELECT * FROM details WHERE fishery_id = '$_SESSION[fishery_id]' "; $sql_result = mysql_query($sql); if (mysql_num_rows($sql_result) ==0) { ob_start() ?> <form name="details" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') echo "selected"?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') echo "selected"?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form> <? echo ob_get_clean(); ?> <? } else { while ($row = mysql_fetch_array($sql_result)){ $account_type = $row["account_type"]; $vat_number = $row["vat_number"]; ?> <form name="details" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Details</legend> <p>Please enter your details below, read the notes carefully.</p> <p><label for="account_type">Account Type</label> <select name="account_type" class="short"> <option value="">Please Choose</option> <option value="Agent" <?php if($account_type == 'Agent') echo "selected"?>>Agent</option> <option value="Dealer" <?php if($account_type == 'Dealer') echo "selected"?>>Dealer</option> </select> <br><?php echo $error['account_type_error']; ?></p> <p><label for="vat_number">VAT Number</label> <input class="short" value="<?php echo $vat_number; ?>" name="vat_number" type="text" id="vat_number" /><br><?php echo $error['vat_number_error']; ?></p> <p class="submit"><input type="submit" name="submit" value="Update" /></p> </fieldset> </form> <? } } ?>
  11. I have slightly changed things, and better explanation at the end. I have created a new table for the terms section so now I want it to query all 5 tables to look for the fishery_id and complete ='YES" it needs to return that all are true, in other words that each of these tables has YES in the complete field. It is not doing that. Example in 4 of the tables they all have complete='YES" the last table does not as it has had no information entered, so it should return as not valid as their is no row in that table, the same can apply for any of the others, there is no particular order that the tables are filled in. It is a form system and they can switch between different tables. hope it makes sense. So here is my new query: $sql = " (SELECT complete FROM table_b_details WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES') UNION (SELECT complete FROM table_c_info WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES') UNION (SELECT complete FROM table_d_tickets WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES') UNION (SELECT complete FROM table_e_bank WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES') UNION (SELECT complete FROM table_f_terms WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES') "; $sql_result = mysql_query($sql) or die(mysql_error().": $sql"); $count = mysql_num_rows($sql_result); { echo ($count); } Based on the above query it is returning the result as 1 but if one of the selects does not have complete ='yes' it still returns as valid??
  12. sorry, I did the following and this is what i get: $sql_result = mysql_query($sql) or die(mysql_error().": $sql"); $count = mysql_num_rows($sql_result); { echo ($count); } The result is 1
  13. I did an echo for the sql result and it say resource id 4?
  14. It is not throwing up any errors, but it is saying that all of the tables have complete = yes when one of them does not?
  15. Column 'complete' in field list is ambiguous: SELECT complete FROM table_b_details, table_c_info, table_d_tickets, table_e_bank, table_f_publish WHERE fishery_id = '1' AND complete = 'YES'
  16. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/file.html on line 67
  17. I have tried the following but it is giving me an error. If anyone can help as never done this before. $sql = "SELECT * FROM table_b_details, table_c_info, table_d_tickets, table_e_bank, table_f_publish WHERE fishery_id = '$_SESSION[fishery_id]' AND complete = 'YES' "; $sql_result = mysql_query($sql); if (mysql_num_rows($sql_result) ==0)
  18. Okay, will check that out, but then how do I still do the query? Basically I need to check all tables to make sure the REQUIRED info is in there and if so allow them to publish from the form.
  19. I have a system which is working well, but I need to do one final check. I have 5 tables with different information in. Each table should have some information entered from a form, now I need to check that all tables have had data entered to return true, if any return false then it does not allow them to publish. Just like a check to make sure all information is filled in. I have never done this so dont know the correct way. $sql = "SELECT * FROM table_b_details, table_c_info, table_d_tickets, table_e_bank, table_f_publish WHERE fishery_id = '$_SESSION[fishery_id]' AND table_b_details.name = 'NOT NULL' etc.. "; I know this is wrong, well I think it is, not sure of the correct way to query different data in each table?
  20. Half asleep, I should go back to bed. Fixed it: if ( empty($monday) ) { $error['monday_error'] = '<div class="formerror">Please enter your price. eg. 7.00</div>'; } elseif (!is_numeric($monday)) { $error['monday_error'] = '<div class="formerror">Please enter numbers only.</div>'; }
  21. Is exactly the same as just using is_numeric($monday) Thanks, did not know that one. I have just tried this then rather than calling a function, and this is not giving me the error, its treating it as if its numbers when I enter letters. if ( empty($monday) ) { $error['monday_error'] = '<div class="formerror">Please enter your price. eg. 7.00</div>'; } elseif (is_numeric($monday)) { $error['monday_error'] = '<div class="formerror">Please enter numbers only.</div>'; }
  22. I have a function that just checks the field is numeric only. I need this function to do the same thing for each day of the week. Rather than duplicating the function and changing the values, I know there must be an easier way to loop through each one and have just one function call. Here is the function: function validNumber($monday) { if(is_numeric($monday)) { $isValid = true; } else { $isValid = false; } return $isValid; } So rather than duplicating the above function and calling it for example function validNumber2 etc.. and then changing the days in the function, is their a way to write this so it covers all days $monday, $tuesday etc..etc.
  23. Hi David, The reason I am doing this, is to stop people from forgetting, as alot of users tend to either put 2 spaces etc.. and then say its not working.. so trying to ease the process. Thanks for that, I can understand how it works etc.. now. Can I extend this to not allow other characters? If I create the function and use that (better idea as you say) and call that function. Also, another note on functions, can you include more than one function on a php file? so I dont have to reference lots of functions on different pages?
  24. My application is gaining speed now and not far from completion. I am just going through the app and finding things wrong that I need to correct, with the first one being NOT allowing spaces when the user creates their username. I have never done this before. I currently have a function that checks to see if the username exists, and return valid or not and echo to the form to tell the user. What I need to do now is not allow them to use white spaces in the username or password. I wonder if someone knows or can help me get this part right. Here is the error check part of the username: if ( empty($username) ) { $error['username_error'] = '<div class="formerror">Please enter your username</div>'; } elseif (!validUsername ($username) ) { $error['username_error'] = '<div class="formerror">Username Taken please choose another.</div>'; } The function in the elseif statement is called via the include at the top of the page. It is a simple function to query the database to see if the username is taken. How could I extend this to not allow white spaces, once I sort this I know I can finish the rest that are the same as this.
  25. I had the isvalid the wrong way around, doh!! just realised and its working great now. Could you tell me oni why changing to that query worked?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.