G
|
Grdimitris 1/5/2020 |
Check this |
M
|
Mr Foxx author 1/6/2020 |
Thanks for the response. I am pulling my hair out on this one but I just can't get it to work. |
A
|
acpan 1/6/2020 |
Your SQL insert with WHERE NOT EXIST is wrong. You try to insert data to marks table where the id does not exist in the mark table, this has no logic.
|
M
|
Mr Foxx author 1/6/2020 |
Thanks for responding. |
A
|
acpan 1/6/2020 |
Your codes can definitely be simplified and values printed to debug when facing problem like this.
|
M
|
Mr Foxx author 1/6/2020 |
Your codes can definitely be simplified and values printed to debug when facing problem like this. You are posting a chunk of codes without output values, which is hard to comment unless physically try out on our own PC. Anyway, this will work (recreated and verified on my PC): In Server Event:
|
A
|
acpan 1/6/2020 |
The codes are verified working on my PC. |
A
|
acpan 1/6/2020 |
Other things to check: check if there is error from Chrome developer console, may be you miss a ; or some cut and paste wrongly issue. |
M
|
Mr Foxx author 1/6/2020 |
The codes are verified working on my PC. You can put this in the app init: if ($_REQUEST["debug"]=="true") $dDebug=true; Then: add debug=true to your URL in the address bar: your_url.php?debug=true you may see some debug message on your screen, may help to see if there is other error. ACP
|
A
|
acpan 1/6/2020 |
A
|
acpan 1/6/2020 |
This shows you have SQL error.
|
M
|
Mr Foxx author 1/6/2020 |
Where exactly do I place these codes? if ($_REQUEST["debug"]=="true") $dDebug=true;
|
A
|
acpan 1/6/2020 |
Lastly, just give you another way to see what SQL command is executed: SQL Check: ".$_SESSION["sql1"]; SQL Insert: ".$_SESSION["sql2"]; |
A
|
acpan 1/6/2020 |
I already spotted one error by a casual glance: There is no error displayed. I even tried inserting a new button but still doesn't work. if i try this simple codes it works flawlessly global $dal; while ( $data = $button->getNextSelectedRecord() ) { $sql = "INSERT IGNORE INTO Subject_Marks (studentid, first_name, last_name, Sex, Form, Repeater, school_yr, Subject) values ('".$data["studentid"]."', '".$data["first_name"]."', '".$data["last_name"]."','".$data["Sex"]."', '".$data["present_form"]."', '".$data["Repeater"]."', '".$data["Current_Year"]."', '".$data["Subject"]."')"; CustomQuery($sql); } $result["txt"] = "Records Added"; |
M
|
Mr Foxx author 1/6/2020 |
Lastly, just give you another way to see what SQL command is executed: Save the two SQL commands to a session name and show it in the list page: in your Server Event: // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; In before display event: echo " SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2'];
|
A
|
acpan 1/6/2020 |
You give another command: |
A
|
acpan 1/6/2020 |
>I get this error when attempting to load the pages: |
M
|
Mr Foxx author 1/6/2020 |
>I get this error when attempting to load the pages: >Parse error: syntax error, unexpected '>' in C:\Users\Walkie\Documents\SAASS Final\SAASS_Finalv2\output\include\Student_Reg_events.php >on line 124 >
|
A
|
acpan 1/6/2020 |
error is in Student_Reg_events.php line 124, but you are giving events.php? The error and line is shown, go get the bug. That's all i can help, you should look through carefully all your casual mistakes.
|
M
|
Mr Foxx author 1/6/2020 |
Your codes can definitely be simplified and values printed to debug when facing problem like this. You are posting a chunk of codes without output values, which is hard to comment unless physically try out on our own PC. Anyway, this will work (recreated and verified on my PC): In Server Event:
|
A
|
acpan 1/6/2020 |
Check all your database field names with the SQL commands, because you gave different upper and lower cases in different messages and i created based on one of your messages. it could be not matching your actual database, it must be exact and your naming convention is not consistent, try to use all lowercase for php and database table names and fields in future. I think there's a little misunderstanding. This is the exact code i'm using. |
A
|
acpan 1/6/2020 |
My tables created based on one of your messages: |
M
|
Mr Foxx author 1/6/2020 |
My tables created based on one of your message: Subject_Marks record_number int(11) studentid int(11) first_name char(50) last_name char(50) Sex char(5) School_Yr char(10) Subject char(50) Form char(10) Repeater char(10) Student_Reg studentid int(11) first_name char(100) last_name char(100) Sex char(5) present_form char(10) Repeater char(10) Current_Year char(10) Subject char(50) Check through your own tables. If you want to use my codes, your tables names and field names must match exactly my tables field names.
|
A
|
acpan 1/6/2020 |
Tables looks matched with the fields name. your Subject_Marks table, record_number, i hope you have set auto-increment because it is set as NOT NULL, without auto-increment, insert to the Subject_Marks table will give errors. |
M
|
Mr Foxx author 1/6/2020 |
Tables looks matched with the fields name. your Subject_Marks table, record_number, i hope you have set auto-increment because it is set as NOT NULL, without auto-increment, insert to the Subject_Marks table will give errors.
|
A
|
acpan 1/6/2020 |
You need to print out the sql commands and run manually and see the errors. |
M
|
Mr Foxx author 1/6/2020 |
Lastly, just give you another way to see what SQL command is executed: Save the two SQL commands to a session name and show it in the list page: in your Server Event: // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; In before display event: echo " SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2'];
|
A
|
acpan 1/6/2020 |
By the way, which phprunner version are yiu using? |
M
|
Mr Foxx author 1/6/2020 |
By the way, which phprunner version are yiu using?
|
![]() |
lefty 1/6/2020 |
Lastly, just give you another way to see what SQL command is executed: Save the two SQL commands to a session name and show it in the list page: in your Server Event: // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; In before display event: echo " SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2'];
|
M
|
Mr Foxx author 1/6/2020 |
Thanks for responding. The codes posted last was modified based on suggestions by Grdimitris. My original codes are listed below. They work fine but only if I check if the records exist on a single field. Once I try testing on the three fields studentid, School_Yr and Subject then they don't work. I just need some help adjusting the code below to make them work. Thanks again! //ResultTable Header $ResultHead = "<table border='1' cellpadding='4' cellspacing='0' width='100%'><tbody> <tr> <td> StudentID</td> <td> First Name</td> <td> Last Name</td> <td> Result</td> </tr>"; //ResultTable Footer $ResultFooter = "</tbody></table>"; //ResultTable Detail $ResultDetail = ""; //Loop trough all selected records while($CustRecord = $button->getNextSelectedRecord()) { // See if record exists. $rsEx = DB::Query("select record_number from Subject_Marks where studentid = ".$CustRecord["studentid"]." AND School_Yr = ".$CustRecord["Current_Year"]." AND Subject = ".$CustRecord["Subject"]."");$CustData = $rsEx->fetchNumeric(); IF(IsSet($CustData[0])){ //record already exists. $ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> ".$CustRecord["last_name"]."</td> <td> Record already exists.</td> </tr>"; }ELSE{ //record does not exists. Add it. DB_Exec("insert into Subject_Marks(studentid, first_name, last_name, Sex, Form, Repeater,School_Yr, Subject) values (".$CustRecord["studentid"].", '".$CustRecord["first_name"]."', '".$CustRecord["last_name"]."','".$CustRecord["Sex"]."','".$CustRecord["present_form"]."','".$CustRecord["Repeater"]."', '".$CustRecord["Current_Year"]."','".$CustRecord["Subject"]."')"); $ResultDetail .= "<tr> <td> ".$CustRecord["studentid"]."</td> <td> ".$CustRecord["first_name"]."</td> <td> ".$CustRecord["last_name"]."</td> <td> Record Added.</td> </tr>"; } } $result["result"] = $ResultHead.$ResultDetail.$ResultFooter;
|
![]() |
lefty 1/6/2020 |
Lastly, just give you another way to see what SQL command is executed: Save the two SQL commands to a session name and show it in the list page: in your Server Event: // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; In before display event: echo " SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2'];
|
![]() |
lefty 1/6/2020 |
You are trying to reference a unique ID or a field that is not available yet , that may have many to many relationships, or more than one or One of Those fields is NULL or not yet known .This not really a PHPrunner problem and does not support this type of query . You need either to use a Complex Stored Procedure in MYSQL or MSSQL or use $_SESSION values on the record or third field you are working on to get your values by selecting the master record and saving the sessions . I just had this problem with a client and spent many hours of what you are trying to do . Don't work . Ended up using SESSION on all fields. And then unset them after server event in button. Hope this saves you some time. |
![]() |
lefty 1/6/2020 |
M
|
Mr Foxx author 1/7/2020 |
Complex Stored Procedures
|
A
|
acpan 1/7/2020 |
Don't do a stored procedure or any other method to complicate further, when my codes with a simple SQL query already works here. I will try to avoid store procedure at all cost unless no choice for example transactional processes or batch processing in the Database Server. |
M
|
Mr Foxx author 1/7/2020 |
Don't do a stored procedure or any other method to complicate further, when my codes with a simple SQL query already works here. I will try to avoid store procedure at all cost unless no choice for example transactional processes or batch processing in the Database Server. It is already proven working with animated picture given, in the most simplest form of SQL commands in my earlier post. Please read it. Read my working codes For button codes, you need to echo out the SQL/commands and errors as suggested in this thread. You must be able to dump out values to see. That is a must when you face problem. The codes i gave you even has debug variables for display in the after client events prepared for you, you can try it. Those are the variables i used to verify the output before i posted in this thread. If you can't debug at all, at least, you can try to incrementally change your codes with the working codes. You cut a bit from working code and swap a bit into your old codes and see the difference bit by bit. ACP
|
A
|
acpan 1/7/2020 |
First, one is Select Query, to pull data out, one is insert data. You are asking why i read is okay but insert not okay. They are 2 different SQL operations. U sure you dnt know the difference? it is dangerous to mess with database with this understanding. |
M
|
Mr Foxx author 1/7/2020 |
First, one is Select Query, to pull data out, one is insert data. You are asking why i read is okay but insert not okay. They are 2 different SQL operations. U sure you dnt know the difference? it is dangerous to mess with database with this understanding. 2nd, you can simplify your codes effortlessly by follow my example. Eg. you can replace the variables in your query.
|
A
|
acpan 1/7/2020 |
At this point, and this kind of error, it is exactly that you need to print out what SQL command is formed by you and executed, and run it manually from SQL editor. I have advised you many times. There is error in your SQL commands formed and you need to print it out. You just can't print out. Sorry I pasted the wrong code. Yes I know the difference between the two <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=89858&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> I meant if I use this it doesn't work: $rsEx = DB::Query("select record_number from Subject_Marks where studentid = ".$CustRecord["studentid"]." AND School_Yr = ".$CustRecord["Current_Year"]." AND Subject = ".$CustRecord["Subject"]."");$CustData = $rsEx->fetchNumeric(); IF(IsSet($CustData[0])){ If I use this it works fine: $rsEx = DB::Query("select record_number from Subject_Marks where studentid = ".$CustRecord["studentid"]."");$CustData = $rsEx->fetchNumeric(); IF(IsSet($CustData[0])){ |
A
|
acpan 1/7/2020 |
and there could be missing quotes for $CustRecord["Current_Year"] or some other string fields. |
M
|
Mr Foxx author 1/7/2020 |
At this point, and this kind of error, it is exactly that you need to print out what SQL command is formed by you and executed, and run it manually from SQL editor. I have advised you many times. There is error in your SQL commands formed and you need to print it out. You just can't print out. Just to give you a quick one, there could be no space in your " AND " when you join them in your string. ACP
SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2']; SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2'];* |
A
|
acpan 1/7/2020 |
the error says >, |
A
|
acpan 1/7/2020 |
There is error here: SQL Check: ".$_SESSION["sql1']; SQL Insert: ".$_SESSION["sql2']; |
M
|
Mr Foxx author 1/7/2020 |
the error says >, could cause error, remove them or replace with | and i hope you put your session values for $strSQL at the right place and not insert anywhere. I dnt see you have $strSQL defined in your codes.
|
A
|
acpan 1/7/2020 |
Sorry, can tell what is in that line that causes error, without seeing the lines: |
A
|
acpan 1/7/2020 |
yes, you place below all Sql, but do you have $strSQL = "...." before that? Can't show me if you have that statement ? cut and paste to show? I placed this right below all sql codes on the server event code on the button // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; And this in before display even $_SESSION["sql1"] $_SESSION["sql2"] Still error: Parse error: syntax error, unexpected 'Insert' (T_STRING), expecting ']' in C:\Users\Walkie\Documents\SAASS Final\SAASS_Finalv2\output\include\Student_Reg_events.php on line 124 |
A
|
acpan 1/7/2020 |
wait, Omg, you just pasted: I placed this right below all sql codes on the server event code on the button // Save the check SQL command $_SESSION["sql1"] = $strSQL; // SAve the Insert SQL $_SESSION["sql2"] = $strSQL; And this in before display even $_SESSION["sql1"] $_SESSION["sql2"] Still error: Parse error: syntax error, unexpected 'Insert' (T_STRING), expecting ']' in C:\Users\Walkie\Documents\SAASS Final\SAASS_Finalv2\output\include\Student_Reg_events.php on line 124 |
M
|
Mr Foxx author 1/7/2020 |
wait, Omg, you just pasted: $_SESSION["sql1"] $_SESSION["sql2"] i asked you to correct the quotes from single quotes to double quotes, not literally paste that. $_SESSION["sql1'] => $_SESSION["sql1"] $_SESSION["sql2'] => $_SESSION["sql2"]
|
A
|
acpan 1/7/2020 |
Good, that's what we want to see. Run in your SQL editor, and show the errors. Sorry!! I got this error: SQL Check: insert into Subject_Marks (studentid, first_name, last_name, Sex, Form, Repeater,School_Yr, Subject) VALUES (4, 'Chuck', 'Norris', 'M', '1N', 'Yes','2017-2018', 'TD') SQL Insert: insert into Subject_Marks (studentid, first_name, last_name, Sex, Form, Repeater,School_Yr, Subject) VALUES (4, 'Chuck', 'Norris', 'M', '1N', 'Yes','2017-2018', 'TD') |
A
|
acpan 1/7/2020 |
Show the Select Query, it must have missing quotes somewhere. |
M
|
Mr Foxx author 1/7/2020 |
Show the Select Query, it must have missing quotes somewhere.
|
A
|
acpan 1/7/2020 |
magic, it works suddenly. |
M
|
Mr Foxx author 1/7/2020 |
magic, it works suddenly.
|
A
|
acpan 1/7/2020 |
I suggest you read again the codes i posted again, where after client event shows various messages to be displayed, the assistant was given there with animated screencast. I think the records were being inserted before but because I was looking for onscreen messages indicating success or failure I wasn't aware. your codes work fine for the insert I just need some assistance with the onscreen messages now. |
![]() |
lefty 1/7/2020 |
I suggest you read again the codes i posted again, where after client event shows various messages to be displayed, the assistant was given there with animated screencast.
|
M
|
Mr Foxx author 1/7/2020 |
I suggest you read again the codes i posted again, where after client event shows various messages to be displayed, the assistant was given there with animated screencast.
|
A
|
acpan 1/7/2020 |
the above code is direct copy from phprunner example without any changes. |
M
|
Mr Foxx author 1/7/2020 |
the above code is direct copy from phprunner example without any changes. try insert a new button and practise until you can pass message to after client events. do until you can then understand the example given by phprunner, pass different message until you understand. Then you try again on this.
|
A
|
acpan 1/7/2020 |
Glad u did it! |
M
|
Mr Foxx author 1/7/2020 |
Glad u did it! Suggested you to try the example because through trying a simple and working case, will give u confident and trigger you to fix it. ACP
|
A
|
acpan 1/7/2020 |
There u go <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=89882&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> |
M
|
Mr Foxx author 1/8/2020 |
There u go <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=89888&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> Hopefully, u name all your field names, table names to lowercase in future and remember how to dump out the values with the session variables and tips u picked up here. Good luck!
|