
amirelgohary1990
Members-
Posts
25 -
Joined
-
Last visited
amirelgohary1990's Achievements

Member (2/5)
0
Reputation
-
I am retrieving data via Ajax into Choices.js select options My scenario is when I select date, getting the available restaurant tables The retrieving data is 100% working, but it reflects in the select options only in the first request, then when I try to reselect another date I receive the below console error, and choices still keep the initial retrieved data choices.min.js:11 Trying to initialise Choices on element already initialised Choices setValue Function var el = document.getElementsByClassName("table_number")[0]; if (el) { function setChoices(values) { const tableNumbers = new Choices(el, { removeItemButton: true, }).setValue(values); } setChoices(values); } Ajax Code let shiftDate = document.getElementById('reservation_shift_date'); shiftDate.addEventListener("change", function(){ let request = new XMLHttpRequest(); request.open("POST","get_tables.php",true); request.setRequestHeader("content-type","application/x-www-form-urlencoded"); request.onreadystatechange = function(){ if(request.readyState == 4 && request.status == 200){ setChoices(JSON.parse(request.responseText)); } } request.send("date="+shiftDate.value); }); get_tables.php if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['date'])){ $stmt = $conn->prepare("SELECT table_id FROM reservation WHERE shift_date = ?"); $stmt->execute([$_POST['date']]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($rows as $row){ $reserved_tables_id[] = $row['table_id']; } $in = implode(',',$reserved_tables_id); $execute_query = mysqli_query($dbConnection,"SELECT id, table_name FROM tables WHERE id NOT IN ($in)"); while($row = mysqli_fetch_assoc($execute_query)){ $tbl_id = $row['id']; $tbl_name = $row['table_name']; $arr[] = ["value"=>$tbl_id,"label"=>$tbl_name]; } echo json_encode($arr); }
- 1 reply
-
- javascrip
- choices.js
-
(and 2 more)
Tagged with:
-
Google Recaptcha v3 Not working
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
Hello This secret code will not be published into the live site, just a test copy The below code worked with me if(isset($_POST['submitContact']) && $_SERVER['REQUEST_METHOD'] == 'POST'){ $postdata = http_build_query(["secret"=>"6LfyPF0pAAAAAEsS5lfN_WL3wKHh1XfGo0oE_PYU","response"=>$recaptcha_response]); $opts = ['http' => [ 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ] ]; $context = stream_context_create($opts); $result = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context); $recaptcha = json_decode($result); if($recaptcha->success ==true){ if($recaptcha->score >= 0.5){ echo "Recaptcha Success"; }else{ echo"<pre>"; print_r("Recaptcha Not Verified"); echo"</pre>"; } }else{ echo"<pre>"; print_r($recaptcha); echo"</pre>"; }- 2 replies
-
- php
- recaptcha php error
-
(and 3 more)
Tagged with:
-
Hello I am receiving a huge amount of spam emails, now I am trying to implement Google Recaptcha V3 in my custom PHP From, I implemented all the steps for G-Recaptcha, but I receive error invalid-input-secret And I am sure that the secret code shout be copied right I added the below to the head tag <script src="https://www.google.com/recaptcha/api.js?render=6LfyPF0pAAAAAHLxp3315RTN7jrRvBe6kLdHGAiT"></script> <script> grecaptcha.ready(function() { grecaptcha.execute('6LfyPF0pAAAAAHLxp3315RTN7jrRvBe6kLdHGAiT', {action: 'submit'}).then(function(token) { let recaptchaResponse = document.getElementById("recaptchaResponse"); console.log(recaptchaResponse); recaptchaResponse.value = token; }); }); </script> Then added hidden input before the submit button in the Form <input type="hidden" name="recaptcha_response" id="recaptchaResponse"> <input class="contactInput no-border cursorPointer buttonStyle" name="submitContact" value="Submit" type="submit"> And finally, I implemented the PHP code if(isset($_POST['submitContact']) && $_SERVER['REQUEST_METHOD'] == 'POST'){ $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; $recaptcha_secret = '6LfyPF0pAAAAAEsS5lfN_WL3wKHh1XfGo0oE_PYU'; $recaptcha_response = $_POST['recaptcha_response']; $recaptcha = file_get_contents($recaptcha_url."?secret=".$recaptcha_secret."?response=".$recaptcha_response); $recaptcha = json_decode($recaptcha); if($recaptcha->success ==true){ if($recaptcha->score >= 0.5){ echo "Recaptcha Success"; }else{ echo"<pre>"; print_r("Recaptcha Not Verified"); echo"</pre>"; } }else{ echo"<pre>"; print_r($recaptcha); echo"</pre>"; } } But receiving the below error stdClass Object ( [success] => [error-codes] => Array ( [0] => invalid-input-secret ) )
- 2 replies
-
- php
- recaptcha php error
-
(and 3 more)
Tagged with:
-
unset from array using array_search
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
It was inside the () just I wrote here by wrong- 7 replies
-
- php
- array_search
-
(and 1 more)
Tagged with:
-
unset from array using array_search
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
I tried this also, but same problem $bloodType_list = ['a+','a-','b+','b-','o+','o-','ab+','ab-']; if($key = array_search('a+',$bloodType_list)){ if($key !== false){ unset($bloodType_list[$key]); } } foreach($bloodType_list as $bloodType_lists){ echo $bloodType_lists."<br>"; }- 7 replies
-
- php
- array_search
-
(and 1 more)
Tagged with:
-
unset from array using array_search
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
You mean like below code ? $bloodType_list = ['a+','a-','b+','b-','o+','o-','ab+','ab-']; if($key = array_search('a+',$bloodType_list)) !== false { unset($bloodType_list[$key]); } foreach($bloodType_list as $bloodType_lists){ echo $bloodType_lists."<br>"; } I tried that not working too- 7 replies
-
- php
- array_search
-
(and 1 more)
Tagged with:
-
Hello, I am trying to unset from array using array_search, it's working, except the first array value "a+" is not working $bloodType_list = ['a+','a-','b+','b-','o+','o-','ab+','ab-']; if($key = array_search('a+',$bloodType_list)){ unset($bloodType_list[$key]); } foreach($bloodType_list as $bloodType_lists){ echo $bloodType_lists."<br>"; }
- 7 replies
-
- php
- array_search
-
(and 1 more)
Tagged with:
-
Hello, photos do not appear in the following cases 1- inserting photo inside <picture> tag (In Server Side Only), Working normally in local 2- Not Working when site domain only www.mysite.com ,, Working when site domain = www.mysite.com/index.php <picture class="hover1 runHover2"> <img src="assets/img/central-business-district-singapore.jpg"> </picture> Note: -The path is right, and when opening inspect to check the photo, I find it - Tried to change the path to /assets/img/central-business-district-singapore.jpg or www.mysite.com/assets/img/central-business-district-singapore.jpg , but not solved
-
1- Noted, and edited 2- I think this is the last point I need, I added the imploded ids inside mysqli_stmt_bind_param, is this right, or I have to put somewhere else,I tried even to put my integers manually inside the FIND_IN_SET('id',77,181), but did not work gives me error Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, bool given 3- Actually $the_array = [77,181]; I wrote here as static, but in my project this array comes from another dynamic query, that comes from the website when user search for specific country, Regarding
- 8 replies
-
- php
- prepared statement
-
(and 1 more)
Tagged with:
-
Code not returning anything Yes, I enabled errors, also no errors, but I am sure something wrong, when I switch to normal query everything works normally with IN() ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
- 8 replies
-
- php
- prepared statement
-
(and 1 more)
Tagged with:
-
I tried to use FIND_IN_SET() with prepared statement, but did work, do not return any result, or even errors if(escape($_POST['jobCategory']) != "all-categories" && escape($_POST['countryId']) == "all-countries" && escape($_POST['careerLevel']) == "all-career-levels"): $the_array = [77,181]; $job_id_imploded = implode(',',$the_array); $query = mysqli_prepare($dbConnection,"SELECT jobs.id, jobs.job_title, jobs.country_id, employers.employer_name FROM jobs LEFT JOIN employers ON jobs.employer_id = employers.employer_id WHERE job_status = ? AND FIND_IN_SET('id',?)"); mysqli_stmt_bind_param($query,'si',$job_status,$job_id_imploded); endif; mysqli_stmt_execute($query); mysqli_stmt_bind_result($query,$job_id,$job_title,$countryId,$employer_name); while(mysqli_stmt_fetch($query)){ ?> <div class="job-title"> <a href="job_post.php?job_id=<?php echo htmlspecialchars($job_id) ?>" class="job-title-link"><?php echo htmlspecialchars($job_title); ?></a> </div> <?php } // End While ?>
- 8 replies
-
- php
- prepared statement
-
(and 1 more)
Tagged with:
-
PHP close loop outside if function
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
I tried to use FIND_IN_SET() with prepared statement, but did work, do not return any result, or even errors, that's why I used normal query until study PDO then switch this query into PDO, I will open new case with my code with FIND_IN_SET() may be something wrong in my code -
Hello I need to find a way to close loop outside if condition like below example if(escape($_POST['jobCategory']) != "all-categories" && escape($_POST['countryId']) == "all-countries"): $query = mysqli_query($dbConnection,"SELECT jobs.id, jobs.job_title, jobs.salary, jobs.employer_id, employers.employer_name, employers.employer_logo FROM jobs LEFT JOIN employers ON jobs.employer_id = employers.employer_id WHERE job_status = '".mysqli_real_escape_string($dbConnection,'Active')."' AND id IN (".mysqli_real_escape_string($dbConnection,$job_id_imploded).") "); while($row = mysqli_fetch_assoc($query)){ // Start Loop $job_id = $row['id']; $job_title = $row['job_title']; endif; <div class="job-title"> <a href="job_post.php?job_id=<?php echo htmlspecialchars($job_id) ?>" class="job-title-link"><?php echo htmlspecialchars($job_title); ?></a> </div> } // End Of Loop Gives me error HTTP ERROR 500
-
php array format from the mysqli_fetch_assoc rows
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
Yes, I will do this, should be better, thanks -
php array format from the mysqli_fetch_assoc rows
amirelgohary1990 replied to amirelgohary1990's topic in PHP Coding Help
I started using serialize because I wanted to store multiple steps of values to create dynamic taxes for a HRM system I searched for a way I found that serialize can be used if these data will not be used for analytics, just will sore it, then later I retrieve data as array normally