Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Everything posted by jimfog

  1. What is the alternative to globals in object definitions? What you suspect is wrong...the code which defines the variable is directly above from the code that uses it. This code is in lines 6-16...in this jsbin http://jsbin.com/silajo/74/ ....(and is being used in line 25)I do not understand where is the problem.... Anyway I asked the question cause I think we are dealing here with javascript principles and not principles specific to backbone.
  2. the only part that is missing in the code above is the fetch() part... a while loop specifically that will fetch the data from the database... the question is where the while loop should be placed. Just take a look here http://php.net/manual/en/mysqli-stmt.fetch.php in the first example.
  3. I need to stress one more thing... if there are no rows at all...then fetch() will return NULL. The above check though must be done and if indeed NULL is returned, exit from the function using return....the code will look like something like this: if($stmt->fetch()==NULL) {return;} else{ while($stmt->fetch()) { echo $staffID.','.$Bookfrom.','.$startDate;//these refer to data coming from the database } } As you might expect though...the above returns nothing(when we have one row)...cause fetch() is used twice. How I could write the code such a check for NULL is done and at the same time results for 1 row are returned.
  4. there is another slight problem...I do not want to create a separate topic about it. This condition must contain the presence of global variable. Take a look at this http://jsbin.com/silajo/74/ at line 25...the variable is package...and it is produced by parse function at line 9(all of this of course is Backbone code) at a backbone collection. The problem is that I get a message package is not defined....which means I cannot make package available to the User model. How I could overcome this?
  5. Why I would want to inform the hacker? To let him know if he succeeded or not? And as a result try more to achieve his goals.
  6. Ι cannot believe it...you are right...there is only one row and it had not crossed my mind that var_dump(stmt->fetch()) was considered a second call to fetch
  7. Take a look at this prepared statement...: if($stmt=$connection->prepare('SELECT Bookfrom FROM appointments,users WHERE users.email=(?) AND appointments.bookedfor=users.user_ID AND not deleted')) { $stmt->bind_param('s',$email); $stmt->execute(); if($stmt->errno!==0) {printf("Error-execution failed-GET appt_failed: %s.n", $stmt->error); return false; } $stmt->bind_result($Bookfrom); $stmt->fetch(); var_dump( $stmt->fetch()); $stmt->close(); return; } if(!$result) { printf("Errormessage for result: %sn", $connection->error); return false; } I get no error messages. The query is correct...I have checked it many times...it does produce a result/row. Despite the above though....var_dump($stmt->fetch() gives NULL. I am running out of ideas...
  8. Take a look at this fiddle https://jsfiddle.net/fiddlehunt/andwu6Lf/ from lines 2 to 10...in tha JS pane. You see an object which contains two objects. I want the second object(e-mail) to be there if a specific condition is met-depending the value of a variable. So..can a conditional be placed inside an object. The result must be another object or none.
  9. With what you say above you you shed light to a very important aspect. I would say it this way also...if a point has reached where server validation errors appear that might indicate hacker activity...there is no point in informing the hacker about this or that error...I would just log the errors somewhere...and agree with your suggestion that I could terminate the session if there are many errors. I will consider it. I understand now what are you talking about and as you say...it is a decision I will take.
  10. In the end...what do you propose after all.cause as you said the error might indicate a hacker.... showing nothing to the user(which might be a hacker) and report it to a log?
  11. No...I do not want to support users that have JS off. Secondly..the error messages I am talking about here have nothing to do with login...they are related with validation. For example....it is a booking app...and the user is called to select from a drop menu some services...in this case I want to validate in the server if the services chosen are indeed contained in the database...if not send a message in the client informing them
  12. I do not understand... If errors appear in server-side validation should I inform the user about it or not(by sending messages to the client)?
  13. Of course it is optional...but I think server side validation is needed nowadays...and the errors that might arise from it I think they should go to the client and inform the user cause front-end checks might be bypassed.
  14. I am in the process of writing server validation code in which errors(if found) are sent back to the client with json_encode. My problem has to do with how these errors are going to be displayed in the HTML... take a look at this HTML: <div class="form-group"> <label>Name:</label><br> <input id='name' name="nameinfo" type="text"> <p class="fillname"></p> <input type="hidden" id="origin" value="backend"> </div> Here is the server code related with the above-if the user has not filled the above field: if($name=='') { $noname='you have to put a name'; echo json_encode($noname); return; } How am I going to display the the above message inside <p class="fillname"></p>-my intention as to where the error message I want it to appear?
  15. I did my job with in_array after all..thanks
  16. No...the check must be performed either way...let me explain it better. Suppose the first array has two names in it,james and john... I want to check if in the second array these names or one of them(if the array has only one member) are present in it. The first array will always have 2 members in it...the second might have one or two in it. .If the second array has one member than it must be checked if this member are james or john...and output true if yes If the second array has two members it must be checked that both of these are james and john...if one of them is not then output false. To say it differently I want to check the choices the user made with the ones found in the database...as a validation algorithm.
  17. yes...I want to check for example the first member of the first array with the first member of the second array and so on...I want to focus on the above approach first...
  18. I am trying to use a while loop to compare 2 arrays...something like this: $i=0; while($i<count($serviceslist)) { if(($serviceslist[$i]["serviceID"])!==($content['services'][$i])) { echo 'hi';} $i++; } There is a problem though....there are time where the 2 arrays are not equal in size. The service list array might have 2 members and the content array might have 1 member. At such a case when $i=1 then I get an undefined offset warning...something to be expected of course since the second array has only one member(in this example). How I could compare the 2 arrays and still take into consideration that these may not be of equal size? Some code adjustment is needed here.
  19. jimfog

    is_numeric error

    custom error messages...in this case: This is not a number.
  20. You are right in what you say...the way the loop is now it is rather useless... So...take a look at this: while (i < col.models.length) { var s=new Date(col.models[i].attributes.start); var e=new Date(col.models[i].attributes.end); var st=s.getTime()/1000,en=e.getTime()/1000; if((st==tfrom)&&(en==ttill)) { $('.pack_check').html('bla blah').css( "color", "red" ); return false; } i++; } Τell me what you think now..as I said before...the logic is that the loop searches through an array and when something is found(if condition) the loop stops. If nothing is found then the loop ends-after it has searched through all the array.
  21. Yes you are right...I misled you...my app cannot work without JS. I do not intend to make the app work with PHP
  22. That loop goes through an array.This array might have 3 elements(for example)...each element is an object and 2 of the object's attributes are start and end. The logic is this: If some of these attributes meet a condition(see the if statement) then the loop must stop. There may be a case where the condition is not met,in such a scenario the loop will just end. So why do you say that there is no reason in repeating the instructions. The loop is there to find something(that is why is there the if condition) in the array.
  23. Οκ...Ι understand but I need to say that maybe this question is in vein. My app cannot work with javascript...and the submissions which are made by ajax..are made by pressing the submit button on a dialog box created by jquery UI. So on this case,js is the only alternative. The way the app is made I cannot make it to run with PHP only.
  24. I am using a loop to iterate through an array and break from it when an IF statement is satisfied... In the code you will see...when the IF statement is satisfied I use return to exit from the function and from the loop...and after that I use break. I think break though is redundant...you tell me for sure: compare_dts:function(col){ var tfrom=$('#timesfrom').val(),ttill=$('#timestill').val(); var i=0; var s=new Date(col.models[i].attributes.start); var e=new Date(col.models[i].attributes.end); while (i < col.models.length) { i++; var st=s.getTime()/1000,en=e.getTime()/1000; if((st==tfrom)&&(en==ttill)) { $('.pack_check').html('blabla...').css( "color", "red" ); return false; break;//does this have to go away? } else {$('.pack_check').html(''); return} } }, As the code currently is...there is no problem,I want to be sure anyway though. The purpose(anyway) is that when this IF condition is met the functions returns false.
×
×
  • Create New...