Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Posts posted by jimfog

  1. If the fields are in the same table then you only need 1.
    Yes...but what if the user wants to edit only one field from the form.Suppose the form has name, lastname and age. Again it will be 1 query... But what if he wants to edit 2 fields-name and last name for example. My opinion is that I must prepare 3 queries and use conditionals to choose when to use each one of them-depending what the user wantsto edit/change. I am just as wondering if there is a shortcut here. WHat do you think?
  2. suppose we have a 3 field form which the user wants to edit-in other words, updating the corresponding records in the database. AM i right to assume that the max queries that the above action might require is three and the minimum is one? Just I want to see if my assumptions are correct here.

  3. I will be more specific.The problem is that if I click the edit button in the first section BOTH sections will open, something undesirable of course.Take a look at the image with the problem:https://skydrive.live.com/redir?resid=BE27434B2AAC8130!251&authkey=!ABoKLygksdiKYSc If I do what you propose:isset(editpersonal) the problem is the same in addition that when I click to edit the second section the first section closes(something which must not happen if it is open from before)-image:https://skydrive.live.com/redir?resid=BE27434B2AAC8130!252&authkey=!AM2dsUfpwx6cUqs

  4. Then...why do you think the "edit profile" in facebook does not work with js disabled? Why they have not provisioned for PHP fallback? I do not expect from you to know how facebook people decided to do it like this but only ti listen some thoughts.

  5. I have a page where is s form divided on separate sections depending on the data required(name data, address data etc.) Each section can be edited individually(by clicking the appropriate icon)-like the "edit profile" page of facebook. The problem is that I cannot make the logic work correctly. For example: When one section is opened for editing and another one is already open, and I co to close the former, the second also closes something I do not want of course. Here is some code, with 2 sections(name and address):

    <fieldset class="basics">       <h2>Name</h2>    $personal = get_personal_db($_SESSION['valid_user']);				  if(isset($_GET['form'])&&(isset($personal))||(isset($_GET['cancelpersonal'])))//$cancelpersonal is when the cance button is clicked and GET['form'] is the URL that leads to the form ....profile?form.php				  {  echo $personal['name'] . '<br>' .					  $personal['lastname'] . '<br>' .//here data already in the db are echoed to the browser, 					  $personal['btype'] . '<br>';					 				  }				  elseif ((isset($_GET['editpersonal'])) || (!isset($_GET['cancelpersonal'])))					  {					  ?> <label  class="label" for="name">*</label>					  <input id="name" size="40" placeholder="Όνομα" type="text" name="name"><br>					  <label class="label" for="lastname">*</label>					  <input id="lastname" size="40" placeholder="Επώνυμο" type="text" name="lastname"><br>					  <label class="label" for="businesstype">*</label>					  <input id="lastname" size="40" placeholder="Τύπος Επιχείρησης" type="text" name="businesstype"><br>					  <input value="Save" name="save" type="submit" id="savebutton">					  <a href="http://localhost/Appointments/Administrator/profile.php?cancelpersonal"  class="cancelbton">Aκύρωση</a>					  <?php;}</fieldset>      <fieldset class="basics">                 <h2>Address</h2>                 <a href="http://localhost/Appointments/Administrator/profile.php?editaddress" ><div class="edit"> <img  src="Images/editpen.png"></a>                 </div>                 <?php  $address=get_address($_SESSION['valid_user']);                 if((isset($_GET['form']))&&($address)||(isset($_GET['canceladress'])))                 {   echo $address['address'].'<br>'.//εδω τυπώνονται τα στοιχεία που βρέθηκαν στην βάση                          $address['city'].'<br>'.                          $address['municipality'].'<br>';                                  }                  elseif((isset($_GET['editaddress']))||(!isset($_GET['canceladress'])))                 {?> <label  class="label" for="address">*</label><input id="address" size="40" placeholder="Διεύθυνση" type="text" name="address"><br>                    <label  class="label" for="city">*</label><input size="40" placeholder="Πόλη" type="text" name="city"><br>                    <label  class="label" for="municipality">*</label><input size="40" placeholder="Νομός" type="text" name="municipality"><br>                    <h3>Web address</h3>        <!--            <label class="label" for="wwwaddress">*</label>-->                    <input size="40" id="<?php if(isset($errorclass['wwwaddress'])){if($errorclass['wwwaddress']==true){echo 'wwwaddress_error';}else{echo 'wwwaddress';}}?>" placeholder="wwwaddress" type="text" name="wwwaddress"><br>                     <a href="http://localhost/Appointments/Administrator/profile.php?canceladress"  class="cancelbton">Aκύρωση</a>                                       <?php }

    If you need more code I will post.The aim is to close or open the sections individually and not the opening/closing of one affects the other

  6. Just in case you get to the file without having used the form, which can happen.
    How can that happen?You mean the user submitting data without using the form?Or the user going to the page directly where form data is processed? Can you clarify if is something from the above that you mean or something completely different?
  7. I do not understand.Variable initialization is the procedure to see if a variable exists and nothing else? When a POST form is submitted, by definition POST variables are created-why need checking that?

  8. I have heard that we must initialize variables when when we are dealing with user input. Consider the example where a name is passed with the POST method:

    $_POST['name'];$name=$_POST['name'];

    Is the second line an example of variable initialization?

  9. yes. but i am not sure what is the exact question?
    You answered my question.
    there is no reason your form can't work with JS disabled. forms will still submit without JS. .
    Facebook "edit profile" page DOES NOT work without javascript. Yes it needs PHP code as birbal mentioned but js is a must. And to conclude.I want the user to be able to add services. I am going to use js to achieve that, it offer better UX experience. The question is that do i ALSO do that with PHP or just say to the user the usual "you have to enable javascript" message.So we are dealing here with a specific type of form submitting. Not just entering a name, password etc.Imagine the user entering 20 or so services.
  10. Yes...you are right, (I did not say it correctly)but if the user disables js in his computer he will not be able to fill the data. Anyway...from you answer, as I understand it. I must also make the PHP code AND the js/AJAX code. Am I correct?

  11. I am constructing a form where the user will have to put some data-service specifically. Would you bother doing that with server code or just use only javascript and forget server code? I am not talking here about form validation although we are dealing also here form inputs. My thoughts are that accomplishing this with server code will be a bad user experience. All these requests going between the server and the client... And I should stick only with javascript. I am motivated also by the fact that similar pages--were much data must be entered-such as facebook "edit profile" page work only with js. What do you think?

  12. Till now, upon the user submitting a form, validation checks were performed, and if passed a registration function was called.In the latter function where a connection to a db was made, a check was taking place is the submitted username is the same with another in the db. The above scheme though, I think is wrong. Because when the form is submitted all the relevant errors must be submitted at the same time-with the above logic this does not happen. So, I think it is flawed.What do you think? probably a check if there is a similar username(which means connecting to the db) must be made before the registration function gets called. Here is the registration function:

    function register_enduser($post)	   	    { global $errorclass;	    $name=mysql_real_escape_string($_POST['name']);    $lastname=mysql_real_escape_string($_POST['lastname']);    $email= mysql_real_escape_string($_POST['e-mail']);    $passwd= mysql_real_escape_string($_POST['password']);        $conn = db_connect();    $conn->set_charset("utf8");	    $result = $conn->query("select * from credentials where email='" . $email . "'");		 if (!$result) {			 throw new Exception('Αδυναμία εκτέλεσης εντολής');		    return false;		 }	   if($result->num_rows>0) {		   $errorclass['existentemail']='there is a similar e-mail registered already.';			 return  false;		   		  }else		 {$result = $conn->query("insert into credentials values							 (NULL,'" .  $email . "','" .  $passwd . "')") or die(mysqli_error($conn));	   }				 if (!$result) {			 throw new Exception(something went wrong.');			 return false;		 }	    else{$result = $conn->query("insert into end_users values							 ('".$conn->insert_id."','" .  $name. "','" .  $lastname. "')") or die(mysqli_error($conn));}		   			 return true;			   }

    The above functions inserts data into 2 tables, as you can see, just focus on the e-mail check.

  13. I'd use exceptions if I'm programming a library that somebody else is going to use. When the programmer catches the exceptions they can choose how to respond to them.
    So...in this case-as far as I understand from your answer-where a check is made if there is a similar username in the db with the one that the user submitted in the form, I SHOULD not use exception, but just print an error message. Am i correct?
  14. Have an array of messages related to each field input, if not filled, take the related message from message array, and do what you want with it.
    probably this is the way to go, which means also that I have to throw away filled_out(). Here is an example where first is checked if a form field is empty and if not proceed with filtering operations-more or less, I think this is what you are suggesting:
     		    if(trim($_POST['name'])=='')		    {$empty.= 'you have to enter a name';		    $emptyclass['name']=true;		    }		    elseif (checkname($_POST['name']) == false) {				 $errors.= 'You have to enter a name';				 $errorclass['name'] = true;			 }    if($empty || $errors){echo .....}			

    checkname() is just a filtering function where sanitization and validation takes place.

  15. I have made a function which loops through a form and if these are left empty then return false.Here is the function:

    function filled_out_biz_user($post){	 global $services,$pricelist,$wwwaddress;	  $services=array();  $pricelist=array();  $required=array();   $required['name']=$_POST['name'];  $required['lastname']=$_POST['lastname'];  $required['password']=$_POST['password'];  $required['phone']=$_POST['phone'];  $required['e-mail']=$_POST['e-mail'];  $required['address']=$_POST['address'];  $required['city']=$_POST['city'];  $required['municipality']=$_POST['municipality'];    $services['service1']=$_POST['service1'];   $pricelist['price1']=$_POST['price1'];  $wwwaddress==$_POST['wwwaddress'];   $wasFilledOutCompletely = true;  foreach ($required as $value) {		 if ($value == '') {			    $wasFilledOutCompletely =  false;		 }  }  return $wasFilledOutCompletely;}

    Just concentrate on the required fields(for now) The problem with the above logic though is that it does not return false if empty for each individually-which is my goal in this case.I mean if half the fields are non-empty it will say "You have not entered all the fields". What I want to achieve is...:"You have not entered the following fields"...I mean being more specific about it.I do not know if this can be done by modifying more or less the above function or change drastically.

  16. Sure, why not? It can be the primary keys for the other tables too, you wouldn't need multiple records per user I assume. If it's a 1-to-1 relationship then make it the primary key in every table.
    If the relationship you describe is one -to -one, the primary key of one table is used as foreign key in other tables(more than 2 in my case).Then...which relationship is called one-to-many?
  17. I have a form where if an input does not satisfy validation checks an error message is displayed-here is an example for the password:

      $checkpass = check_passwd($_POST['password']);			    if ($checkpass== false) {				    $errors.= 'The password must be at least 6 characters long';				    $errorclass['passwsmall'] = true;			    }

    The question is if for cases like the above is better using the exception class or just use the above. In another function that insert the user's credentials into the db(after the checks are done, as part of the registration)-I check if the e-mail in the db is the same with one the new user has supplied, and if this is the case then throw an exception:

    $result = $conn->query("select * from credentials where email='" . $email . "'");		 if (!$result) {			 throw new Exception('problrm.....');		    return false;		 }	   if($result->num_rows>0) {			 throw new Exception('There is another user with same e-mail.');			 return false;

    SO I have to make a decision for the error mechanism. What do you propose?The reason that I use an exception in the registration is because the above code is not mine-it is copied from a book. The convenience with the first method(in my case) is that error variable is echo straight to the form indicating which input requires attention.

×
×
  • Create New...