Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Everything posted by jimfog

  1. I decide to use something like this-take from the stackOverflow post mentioned above: $(array1).not(array).get(); I have the following problem now....the above code gives us an array element or more. If is PUSH this/these to another array I will have a multidimensional array...here is the code: var array1=['5','6']; var array2=['5'] var remove=['remove']; var remserv=$(array1).not(array2).get();//this will give us an array containing 6 remove.push(remserv); How am I going prevent creating a multidimensional array. I want 6 PUSHED in the remove array as an element and not as another array containing 6.
  2. Ι Have 2 last question...the first is towards igolme. Why not use return also here if($stmt->errno!==0) {printf("Error-execution failed appoint_servi_chosen table: %s.n", $stmt->error);} I suppose when going into production this error must be written into a log.I know the issue is huge but can give me some jumpstart by telling me what the first step could be achieving this.
  3. That is PHP method...I am looking for something in javascript.
  4. First of all...you were right about $stmt->close() ...it had to be outside the loop. Regarding the error message. If for example there is a mismatch between type definition string and bind variables I get this: <b>Warning</b>: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in <b>C:Apache24htdocsAppointmentsAdministratoradmin_db_code.php</b> on line <b>91</b><br /> Error-execution failed appoint_servi_chosen table: No data supplied for parameters in prepared statement
  5. Suppose we have two arrays... The one has 2 elements the other 1. They also have one common element...they might both contain 5 for example. My problem is that I want to find the identity of the element that is not common....that 2nd element in the array that has 2 elements. How I could possibly achieve this?
  6. regarding the curly braces...you are right...they are not needed. Regarding the code you gave that addresses the efficiency problem...I get many warnings with this content: Couldn't fetch mysqli_stmt... The above warning is displayed both on the line that has the bind_param command both and also the line that has the execute command...probably this has to do with the fact that the prepared statement is outside the loop,so there may be a problem with the code you gave. The error I am getting is an error I am causing deliberately...and this depends on what I want to test. As such...I cannot understand how is this going to help our discussion.
  7. Yes...you are right program execution continues...and in this case since the 2nd prepared statement is depended on the 1st then I should use return. The question of course is where should I use it?I do not think of course this is something to difficult to implement. I just wanted your comment though...thanks.
  8. What is interesting to note here is that when the prepare statement fails(and thus producing an error) the function execution stops anyway....so a return statement might not needed anyway....of course I do not know why this happens...here is the function: function insert_appnt($connection,$name,$start,$end,$origin,$staff,$services,$email) { //μηπως στα παρακάτω queries να γίνει χρήση transaction $connection->set_charset("utf8"); $result2=$connection->query('select crID from business_users,users where users.user_ID=business_users.crID and users.email="'.$email.'"'); if(!$result2) {echo 'Aδυναμία σύνδεσης με την βάση.'; return false;} elseif($result2->num_rows>0) { $crID=$result2->fetch_object(); $bookedfor= $crID->crID; } $staf=(is_array($staff)==true)?$staff[0]:$staff; //WHEN THE BELOW STATEMENT FAILS..THE FUNCTION DOES NOT PROGRESS. if ($stmt = $connection->prepare('INSERT into appointments (Bookfrom,startDate,endDate,apps_origin,staffID,bookedfor) VALUES( ?, ?, ?, ?, ?, ? )')) { $stmt->bind_param('siisii',$name,$start,$end,$origin,$staf,$bookedfor); $stmt->execute(); if($stmt->errno!==0) {printf("Error-execution failed : %s.n", $stmt->error);} $stmt->close(); } else {printf("Error-prepare statement failed: %s.n", $connection->error);} $lastid=$connection->insert_id; if (is_array($services)==true) { //2ND PREPARED STATEMENT foreach ($services as $value) { if ($stmt = $connection->prepare('INSERT into appoint_servi_chosen (app_ID,service_ID) VALUES( ?, ? )')) { $stmt->bind_param('ii',$lastid,$value); $stmt->execute(); if($stmt->errno!==0) {printf("Error-execution failed appoint_servi_chosen table: %s.n", $stmt->error);} $stmt->close(); } else {printf("Error-prepare statement failed appoint_servi_chosen table: %s.n", $connection->error);} } } else { $result1=$connection->query('insert into appoint_servi_chosen(app_ID,service_ID) values("'.$lastid.'","'.$services.'")'); } {return $lastid;} } I have made a comment about which prepared statement I make it to deliberately to fail.... If you look at the code the second prepared statement depends on the first but as I said execution is halted anyway when the first prepare statement produces an error.
  9. I checked everything you mentioned above....and it is OK. There is one small detail though. The prepare statement you see is located inside a function. If an error is produced should I use RETURN to exit the function?
  10. It is working of course... My question is if the code,the way it is right now,if there is a chance that some errors might missed? I do not know what errors these might be...it is strictly a logic issue here.
  11. I think this should be OK now... if ($stmt = $connection->prepare('INSERT into appointments (Bookfrom,startDate,endDate,apps_origin,staffID,bookedfor) VALUES( ?, ?, ?, ?, ?, ? )')) { $stmt->bind_param('siisii',$name,$start,$end,$origin,$staf,$bookedfor); $stmt->execute(); if($stmt->errno!==0) {printf("Error: %s.n", $stmt->error);} $stmt->close(); } else {printf("Error: %s.n", $connection->error);}
  12. But why $stmt does not exist? If the prepare statement fails it will have a value of FALSE. You are saying it is better to use an if....but it is obvious I am using an if statement. Unless you are referring to the ternary operator I am using to check the execute command
  13. Here is what you describe above in code...tell me please if this is what you mean. if ($stmt = $connection->prepare('INSERT into appointments (Bookfrom,startDate,endDate,apps_origin,staffID,bookedfor) VALUES( ?, ?, ?, ?, ?, ? )')) { $stmt->bind_param('siisii',$name,$start,$end,$origin,$staf,$bookedfor); $stmt->execute(); ($stmt->errno===0)?'':printf("Error: %s.n", $stmt->error); $stmt->close(); } else {printf("Error: %s.n", $stmt->error);}
  14. There is one last thing though that needs to be addressed for which I do not want to create a separate topic and that is error handling of a prepared statement. When not using prepared statement error handling was going like this: $result = $connection->query('INSERT into appointments(Bookfrom,startDate,endDate,apps_origin,staffID,bookedfor) values("'.$name.'","'.$start.'","'.$end.'","'.$origin.'","'.$staf.'","'.$bookedfor.'")'); if (!$result){ printf("Errormessage for result insert into appointments query: %sn", $connection->error); return false; } So the question is how am I going to handle errors when using prepared statements? The PHP manual does not help a lot. It just uses a conditional to test if the prepare statement return TRUE and then proceed with the rest of the statements(http://php.net/manual/en/mysqli.prepare.php). I am not sure though this the optimal error handling.
  15. I fixed it...thanks. I just had to modify the INSERT statement accordingly.
  16. it seems the problem is what is described in post 4. A problem arises with prepared statements...at least for me which I have not used them before. The prepare statements "require" that the number of values entered in the db matches the number of columns of the specific table. If not....then the statement fails. Yes...but I want to fill a specific number of columns of the table. By not using prepare statements I could specifically set which columns will be chosen for entering data(in an INSERT statement). How can I do that with prepared statements?
  17. What's next then...any ideas?
  18. I fixed that but the problem remains... Here is the code: $stmt=$connection->prepare('INSERT into appointments VALUES( ?, ?, ?, ?, ?, ? )'); $stmt->bind_param('siiisi',$name,$bookedfor,$start,$end,$origin,$staf); $stmt->execute(); Look at the code to see what error printing code I used. $stmt=$connection->prepare('INSERT into appointments VALUES( ?, ?, ?, ?, ?, ? )'); printf("Error: %s.n", $stmt->error);//this here is at line 152 $stmt->bind_param('siiisi',$name,$bookedfor,$start,$end,$origin,$staf); $stmt->execute(); here is what I got: Notice: Trying to get property of non-object in C:Apache24htdocsAppointmentsAdministratoradmin_db_code.php on line 152Error: . Again... $stmt is considered a non-object. The prepare statement never gets executed... I can understand that from the fact that var_dump(ing) $stmt gives false.
  19. well...I get FALSE. So the prepare statement is not executed. I cannot understand why.
  20. I am having difficulty implementing prepared statement...I am getting the following error: Call to a member function bind_param() on a non-object... The code is this: $stmt=$connection->prepare('INSERT into appointments VALUES( ?, ?, ?, ?, ?, ?, ? )'); $stmt->bind_param('siisii',$name,$start,$end,$origin,$staf,$bookedfor); $stmt->execute(); $stmt->close(); The above is enclosed in a function...for now I will not post the rest code of the function as I do not think it is necessary plus I would like to keep things simple. The error message appears when bind_param is called. So...what I did is var_dump $connection...the result is this: object(mysqli)#1 (19) { ["affected_rows"]=> int(-1) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: 1514feb3700aa52d513182fcdc87f2c66f06d152 $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(1136) ["error"]=> string(47) "Column count doesn't match value count at row 1" ["error_list"]=> array(0) { } ["field_count"]=> int(1) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.15" ["server_version"]=> int(50615) ["stat"]=> string(134) "Uptime: 47970 Threads: 3 Questions: 955 Slow queries: 0 Opens: 77 Flush tables: 1 Open tables: 67 Queries per second avg: 0.019" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(128) ["warning_count"]=> int(0) } meaning...$connection is indeed an object...which is then assigned to $stmt... If my logic above is correct...then why am I getting this error?
  21. The variable I am referring to is called this.changefrommonth. Regarding the comments you make about global variables....lead me to make some more testing. I will post again if it is required.
  22. Despite I am using the term "lifetime" here I am not sure this such a problem. I am going to present code that is part of a bigger one...for simplicity reasons an hopefully you will get I meaning out of it. select: function(start, end) { monthclick=true; this.changefrommonth; this.eventView.collection = this.collection;//ternary expressions follow var starter=(this.changefrommonth===true)?console.log('jogh'):start.add(7,'h').format('YYYY-MM-DD HH:mm:ss'); var ender=(this.changetillmonth===true)?end.format('YYYY-MM-DD HH:mm:ss'):start.add(30,'m').format('YYYY-MM-DD HH:mm:ss'); var unx=this.unixconvert(starter,ender); this.eventView.model = new Event({start:unx[0]/1000 , end: unx[1]/1000,allDay:false,color: '#0072C6'});//Model inmstance created.. this.eventView.dropfrom(starter); this.eventView.droptill(ender); this.eventView.render(); } }, changefrom:function(){ this.selestrt; $("#timesfrom option:selected").each(function () { var selstart=$('#timesfrom').val(); var selectedtill=$('#timestill').val(); if(selstart>=selectedtill) { alert('Ουπς...η ώρα που ξεκινάει ένα ραντεβού δεν μπορεί να είναι πιο μπροστά από την ώρω που λήγει'); this.dropfrom(this.selestrt,'true'); return false; } var unixstartmili=selstart*1000,unixendmili=selectedtill*1000; var start=new Date(unixstartmili),end=new Date(unixendmili);// var allDay = false; if(monthclick===true)//focus in this conditional here { this.changefrommonth=true; $('#calendar').fullCalendar('select',start,end,allDay); var test; } else { $('#calendar').fullCalendar('select',start,end,allDay);//το σφλαμα ειναι με το end εδώ selectmonth=false; } }.bind(this)); }, Above you see 2 functions,in the second one,changefrom(),and in the conditional I have commented, a variable named this.changefrommonth has been set to true. The purpose is that this assignment becomes available(in the ternary operators you see) in the select function which is depicted above. When the conditional runs(and as I see in the chrome dev tools sources panel by placing various breakpoints) the assignment indeed takes place but when select is called with this line here: $('#calendar').fullCalendar('select',start,end,allDay); the value of the variable is unset...not being true anymore. You could say that I could use it as an argument in the above method...I want to try and avoid this for now as this method is provided by a plugin and I do not want to mesh with it's code for now. I hope I was clear
  23. I have the following code: '<div class="fc-time"' +' data-start="' + htmlEscape(startTimeText) + '"' + ' data-full="' + htmlEscape(fullTimeText) + '"' + '>' +'<span>' + htmlEscape(timeText) + '</span>' + '</div>' :'') + (event.title ?'<div class="fc-title">'+ htmlEscape(event.title) + '</div>' : '' ) + '</div>' + Above you see ternary operators used along with the string concatenation symbol to print to the browser. My issue is that I want to use if statements instead to print to the browser....for example in the code relevant to event title. </div>' :'') +//if statement here + The problem is that the if statement along with the string concatenation operator seem not to work...it is syntax problem. How am I going to tackle it? One thought is to write the if statement outside any div etc strings and then move whatever variable needed inside the div block.
  24. Take a look here: http://backbonejs.org/#Events-on
×
×
  • Create New...