Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,183 members, 7,822,004 topics. Date: Thursday, 09 May 2024 at 12:43 AM

Where Is This Error Coming From Please - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Where Is This Error Coming From Please (1248 Views)

How Do I Stop This Error On My Wordpress Site ? / Where Is Your TRAFFIC Coming From. / How Do I Fix This Error (2) (3) (4)

(1) (Reply) (Go Down)

Where Is This Error Coming From Please by cbrass(m): 10:14am On Jul 13, 2015
This is the html link <li><a href="#" class="btn btn-info btn-sm" id="edit" data-toggle="modal" data-target="#modal-form" data-owner="<?php echo $op; ?>" data-edit="<?php echo $postID; ?> ">Edit Page</a></li>
This is the Jquery code $(function(){
$("#edit"wink.click(function(e) {
e.preventDefault();
var id = $(this).attr("data-edit"wink;
var usern = $(this).attr("data-owner"wink;
var dataString = 'id=' + id + '&user=' + usern;
$.ajax({
type: "POST",
url: "../config/edit.php",
data : dataString,
cache: false,
success: function(html){
alert(html);
}
});
});
});


<?php
$id = $_POST['id'];
$usern = $_POST['user'];
$sel = "SELECT * FROM page_timeline WHERE timelineID = '$id' AND user ='$usern' ";
$selt = $db->query($sel);
while($row = $selt->fetch_array())
{
echo $row = ['post'];
}

?>

from the php end am getting id,user undefined. of course i know what could have caused that but what i think is the ajax is not passing the values to the php but i dont know how that could have happened. angry

adewasco2k onyengbu, guru01 etc
Re: Where Is This Error Coming From Please by onyengbu: 12:42pm On Jul 13, 2015
cbrass:



By mere looking, i cant pin point anything specifically but i have my suspicions.
If it were me, i will troubleshoot by first assigning values to the variables directly to id and usern. That is, i will just say var id = "2"; var usern = "3"; then run it again and see what gets posted to php.
If I still get undefined, I will rename the attributes in the <a> element to something like dataowner and dataedit; that is get rid of the dashes.
Another place to look into is the assignment of usern varibale in the datastring. Why not say usern=' + usern and then catch is as $usern = $_POST['usern']; in your php.
Lastly, i noticed your click event is tied to an ID. As you well know, ids are meant to be unique on a page so make sure you dont have another <a id="edit" on that page. If the <li> is returned in a loop, there is definitely more than one of it on the page and that is trouble! To avoid that tie the click event to a class.

I am almost certain one of these will.solve the problem.
Re: Where Is This Error Coming From Please by cbrass(m): 3:06pm On Jul 13, 2015
onyengbu:

By mere looking, i cant pin point anything specifically but i have my suspicions.
If it were me, i will troubleshoot by first assigning values to the variables directly to id and usern. That is, i will just say var id = "2"; var usern = "3"; then run it again and see what gets posted to php.
If I still get undefined, I will rename the attributes in the <a> element to something like dataowner and dataedit; that is get rid of the dashes.
Another place to look into is the assignment of usern varibale in the datastring. Why not say usern=' + usern and then catch is as $usern = $_POST['usern']; in your php.
Lastly, i noticed your click event is tied to an ID. As you well know, ids are meant to be unique on a page so make sure you dont have another <a id="edit" on that page. If the <li> is returned in a loop, there is definitely more than one of it on the page and that is trouble! To avoid that tie the click event to a class.

I am almost certain one of these will.solve the problem.

Thanks alot for your concern, one thing I noticed it I removed that modal link so it doesn't have to pop up, and I.used alert() to know what's wrong I discovered that the PHP indeed recieved those information from the Ajax and I can see the id and the owner of post but when I switch back to the modal and the window pops up onclick it shows that undefined index thing again. So is that the popup is not waiting for Ajax to send the information before firing?
Re: Where Is This Error Coming From Please by onyengbu: 5:14pm On Jul 13, 2015
cbrass:


Thanks alot for your concern, one thing I noticed it I removed that modal link so it doesn't have to pop up, and I.used alert() to know what's wrong I discovered that the PHP indeed recieved those information from the Ajax and I can see the id and the owner of post but when I switch back to the modal and the window pops up onclick it shows that undefined index thing again. So is that the popup is not waiting for Ajax to send the information before firing?
I dont understand.
Does the click on the linl both launch modal as well as POST the variables all at the same time?
Re: Where Is This Error Coming From Please by cbrass(m): 6:07pm On Jul 13, 2015
onyengbu:
I dont understand.
Does the click on the linl both launch modal as well as POST the variables all at the same time?

yes
Re: Where Is This Error Coming From Please by onyengbu: 1:15am On Jul 14, 2015
cbrass:


yes
I dont know why you may want to do that but I am not sure it is the right thing to do. If the modal launch is to confirm the click even, you can just implement it in such a way that the click POSTs the variables and the executes your php and if the query is successful, you echo the js that will launch the modal from php.
Re: Where Is This Error Coming From Please by cbrass(m): 8:59pm On Jul 14, 2015
onyengbu:

I dont know why you may want to do that but I am not sure it is the right thing to do. If the modal launch is to confirm the click even, you can just implement it in such a way that the click POSTs the variables and the executes your php and if the query is successful, you echo the js that will launch the modal from php.

I thought of this too but the issue I have is the modal only fires when clicked so Which means that method may not work. I didn't write the modal script I saw it some where.if I can get one that fires on page load that your method will work
Re: Where Is This Error Coming From Please by onyengbu: 3:13am On Jul 15, 2015
cbrass:


I thought of this too but the issue I have is the modal only fires when clicked so Which means that method may not work. I didn't write the modal script I saw it some where.if I can get one that fires on page load that your method will work

Again I dont fully understand the context but assuming you are just aiming to load the the details returned from your page_timeline table into that modal box heres how I will do it.
1. Launch the modals and
2. Load a page with the attributes as query strings into it (i named the page db-stuff.php).

I made my own modal here as you can see.

main-page.php

<html>
<head>
<style>
#shade
{
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
z-index:100;
background:#000;
opacity:0.5;
display:none;
}
#modal-container
{
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
z-index:101;
background:none;
display:none;
}
.modal
{
background:#fff;
border:1px solid #000;
width: 40%;
height: 35%;
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
</style>
</head>
<body>
<div id="shade"></div>
<div id="modal-container"></div>

<li><a href="#" class="btn btn-info btn-sm" id="edit" data-toggle="modal" data-target="#modal-form" data-owner="<?php echo $op; ?>" data-edit="<?php echo $postID; ?> ">Edit Page</a></li>


<script>
$(document).ready(function() {
$(document).on("click", "#edit", function(e) {
var id = $(this).attr("data-edit"wink;
var user = $(this).attr("data-owner"wink;
$("#shade"wink.fadeIn();
$("#modal-container"wink.fadeIn();
$("#modal-container"wink.load("db-stuff.php?id="+id+"&user="+user);
return false;
});
});
</script>
</body>
</html>


db-stuff.php

<?php
$id = $_POST['id'];
$usern = $_POST['user'];
$sel = "SELECT * FROM page_timeline WHERE timelineID = '$id' AND user ='$usern' ";
$selt = $db->query($sel);
echo '<div class="modal">';
while($row = $selt->fetch_array())
{
echo $row['post'];
}
echo '</div>';
?>



Remeber to add jquery library
Re: Where Is This Error Coming From Please by cbrass(m): 12:14am On Jul 17, 2015
Thanks alot bro, will try it out
Re: Where Is This Error Coming From Please by onyengbu: 3:40am On Jul 17, 2015
cbrass:
Thanks alot bro, will try it out
Good. Let me know how it turns out.
Re: Where Is This Error Coming From Please by cbrass(m): 11:02pm On Jul 17, 2015
onyengbu:

Good. Let me know how it turns out.

Please did you test the code? Cos Nothing is popin up
Re: Where Is This Error Coming From Please by onyengbu: 1:22am On Jul 18, 2015
cbrass:


Please did you test the code? Cos Nothing is popin up
Yea, tested it ok.
Hope you added your jquery library and removed all the nairaland injected "wink"

Heres the fiddle : http://jsfiddle.net/fa6rosps

I commented out the .load(db-stuff.php) part and loaded the modal directly into the page with .html() since I cant load external file there
Re: Where Is This Error Coming From Please by cbrass(m): 8:44pm On Jul 20, 2015
onyengbu:

Yea, tested it ok.
Hope you added your jquery library and removed all the nairaland injected "wink"

Heres the fiddle : http://jsfiddle.net/fa6rosps

I commented out the .load(db-stuff.php) part and loaded the modal directly into the page with .html() since I cant load external file there

Thanks alot bro, I impletmented your example and some stuffs to it and it worked but I have another issue here. The edit link only picks one post-id ( posts and their ids are looped through the db and echoed on the page with the edit link right beside them) I have almost 10 posts Soviet should have 10 ids, I can't understand why the edit link only is picking one id in the loop
Re: Where Is This Error Coming From Please by cbrass(m): 10:17pm On Jul 20, 2015
Don't worry bro, have fixed it. Thanks a billion times
Re: Where Is This Error Coming From Please by onyengbu: 2:08am On Jul 21, 2015
cbrass:


Thanks alot bro, I impletmented your example and some stuffs to it and it worked but I have another issue here. The edit link only picks one post-id ( posts and their ids are looped through the db and echoed on the page with the edit link right beside them) I have almost 10 posts Soviet should have 10 ids, I can't understand why the edit link only is picking one id in the loop
Glad you did it. I was going to tell you not to get rid of IDs on a loop but I believe you figured it out on your own.

(1) (Reply)

How To Implement E-transact Payment On Wordpress Site / Let Me Create A Ponzi Site For You / Youtube Has A Secret ‘dark Mode’ You Didn’t Know Existed - See How To Activate

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 48
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.