Jump to content


  • Posts

  • Joined

  • Last visited

Abel1416's Achievements


Member (2/5)




Community Answers

  1. @Barand I have looked at my table and there are multiple courses for the particular user. @gw1500se error reporting is on. From print_r($r2); all was fetched.
  2. I have only one result being displayed in a select query result whereas I'm expecting 4 results in an array. This is my code below. $sq2="SELECT course FROM course_reg WHERE userid=?"; $stm =$conn->prepare($sq2); $stm->bind_param("s",$logged); $stm->execute (); $return2= $stm->get_result(); $r2 = $return2->fetch_all(); //print_r($r2); foreach($r2 as $course){ foreach($course as $courses){ echo $courses; } } If I do print_r($r2); it comes out with array containing all the possible results. I.e Array ( [0] => Array ( [0] => CME211 ) [1] => Array ( [0] => CME511 ) [2] => Array ( [0] => CME311 ) [3] => Array ( [0] => CME411 ) ) When i loop through the array to get individual result, it only comes out with a single result. I.e CME211 I would be glad if you can help me figure where the issue is. Thanks!!!
  3. Thanks to you all!! I would have saved myself from posting this question if I took a second to check my responses from the backend. I did $attempted = implode(" ,",$arr); Which made the response had a space [1 ,2 ,3 ,4]; thanks once again
  4. @Barand I commented out my code and replaced it with urs still the same. It's been listed but the class is not added. When I tried to get the value of the id of the li's in function func2{....}, it shows undefined whereas it's being displayed at function func{}. Like the id of the listed items is not accessible when adding the class.
  5. If I do var test=$("li").attr("id"); alert(test); Inside the func loop, it is displaying same id for each iteration. I.e 1
  6. Good day!! My issue is this... I sent an ajax request to get some details at the backend. After splitting the response i have 2 different arrays set to a variable. I.e **allQst** [1,2,3,4,5,6] and **attempted** [1,2,3,4]. I now looped allQst with foreach and created an li element to list each at the frontend which works fine. The issue now is trying to add a different id for each li that would be listed. I tried to add .attr() to the li as in, <li>bla bla...</li>.html(item).attr("id","listing"+item); This gives it the same id. I.e listing1 for all li I also tried to make it <li>bla bla...</li>.html(item).attr('id', function(i) { return 'listing'+(i+1); }); Doesn't work. This is my code in full... $(document).ready(function() { $("#next,#prev").one('click', function() { $.ajax({ url: 'done.php', method: 'post', dataType: "JSON", success: function(response) { var rsp = response.r2; var rspB = response.r1; var allQst = rsp.split(","); var attempted = rspB.split(","); attempted.forEach(func2); allQst.forEach(func); function func(item, index) { var ul = $("#list"); var li = $('<li class="pagination-link"></li>').html(item).attr('id', function(i) { return 'listing' + (i + 1); }); ul.append(li); } function func2(item, index) { $("#" + item).addClass("is-current"); } } //succes func end }); //ajax end }); //click func end }); //doc end What I want to achieve lastly is to get the id and add a class to each of them. I would be glad if you can assist me!! Thanks in advance.
  7. I am trying to pass a php variable to javascript but it's not working. This is the "sketch" of my code. <?php $url="asset/go/"; ?> <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <script> var user="mayor"; var url ='<?php echo json_encode($url); ?>'; if(user=="mayor"){ alert(url); } </script> </body> </html> As it is now, it comes with the output below: <?php echo json_encode($url); ?> If I remove the quotation around the php in d jQuery, it throws an error in syntax. Also both codes are located in the same file named test.php Thanks in advance.
  8. I am making a simple login with jQuery ajax but I have a little problem. I get no response from my loginizer.php . My login page (index.php) contains the following code. <form action="loginizer.php" onsubmit="return submitForm();" method="post" class="box"> <div id="error" ></div> <input id="matNo" name="matNo" class="input is-link is-rounded" type="text" placeholder="e.g. 2015/1/55852EE"> <input id="password" name="password" class="input is-link is-rounded" type="password" placeholder="********"> <button type="submit" id="submit" name="submit" class="button is-link is-small">Login</button></form> My loginizer php contains the code: <?php if(isset($_POST['submit'])){ require("db.php"); $table="Students"; $pUser=$_POST['matNo']; $pPass=$_POST['password']; $sql= $conn->prepare("SELECT * FROM $table WHERE Email=?"); $sql->bind_param("s",$pUser); $sql->execute(); $result = $sql->get_result(); $row = $result->fetch_assoc(); $user= $row['Email']; $pass = $row['Password']; $errMsg="Invalid Credentials"; $errMsg1="username doesn't exist"; $successMsg = "successLogin"; if($result->num_rows < 1) { echo json_encode($errMsg1); exit; } elseif($pUser == $user && $pPass !== $pass) { echo json_encode($errMsg); exit; } else{ echo json_encode($successMsg); exit; } } ?> Ans lastly myJquery.js file which contains: function submitForm() { var userid=$("#matNo").val(); var pass=$("#password").val(); if(userid!="" && pass!="") { $("#submit").html("Please Wait..."); $.ajax ({ type:'post', url:'loginizer.php', data:{ matNo:userid, password:pass }, dataType:'json', success:function(response) { if(response=="successLogin") { window.location.href="dash/home/"; } else { $("#error").html(response); //alert("Wrong Details"); } } }); } else { alert("All details are required"); } return false; } The issue is that I get blank response . If I also change the url in the jQuery/Ajax code to index.php, it comes back with a response consisting of the html of the index.php. If I remove the dataType: 'json', it's still no response. Thanks for your help in advance!!!
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.