Jump to content

what is wrong in my code???


deepson2

Recommended Posts

Hello,

 

Can anyone tell me,what wrong in my code. i am getting alert message. and showing the inserting is on.but its not moving further no loading nothing.

 

here is my code

 

profile.php

<?php
echo "<div id='".$blogdata->blogid."'>";
echo "<span id='span".$blogdata->blogid."'>";
echo "<a href='javascript:insert($blogdata->blogid);' title='My favorite'>My Favorite1</a>";
echo "</span>";
echo "</div>";
?>

 

ajax.js

function insert(blogid){
       
document.getElementById(blogid).innerHTML = "<em>inserting...</em>";

alert("hello");
http.open('GET', 'myfav.php?blogid='+document.getElementById('blogid').value);


http.onreadystatechange = insertReply;
http.send(null);
  
}
function insertReply() {
  if(http.readyState == 4){
  var response = http.responseText;
  // else if login is ok show a message: "Site added+ site URL".
  document.getElementById('insert_response').innerHTML = 'Friend'+response;
  }
}

myfav.php

<?php
ob_start();
//ini_set( "display_errors", 0);
include("includes/functions.php");

//include("includes/config.php");


usersess();
$uid         = $userid;
$op = new amd;

$blogid = $_GET['blogid'];
if($blogid){

AddItem($_GET['blogid'],$uid);
}
function AddItem($blogid,$uid)
{

$link = mysql_connect($$$', '$$', '$$')
	  or die('Could not connect: ' . mysql_error());
  mysql_select_db('$$i') or die('Could not select database');

echo  "INSERT INTO favourite(blogid,uid,favourite) VALUES ('".$blogid."', '".$userid."', 'Y')";
$addfavourite = mysql_query("INSERT INTO favourite(blogid,userid,favourite) VALUES ('".$blogid."', '".$userid."', 'Y')");
 if(mysql_affected_rows() > 0){


echo "your favourite is added";
}else
{

echo "your favorite is not added";
}

}
  ?>

 

thanks in advance.

Link to comment
Share on other sites

Looking at your code it seems to be an ajax function. I see that it will always alert "hello" so I don't see how that is a problem. Also i see a global var named http what's the jscode above your function insert? If I am correct it should be something like

var http;
if (window.XMLHttpRequest){
  // code for IE7+, Firefox, Chrome, Opera, Safari
  http=new XMLHttpRequest();
}else if (window.ActiveXObject){
  // code for IE6, IE5
  http=new ActiveXObject("Microsoft.XMLHTTP");
}else{
  alert("Your browser does not support XMLHTTP!");
}

 

Two other things:

1. I don't really see the point for using two functions instead of one here.

2. Can you be a little more descriptive on what your code is suppose to do and what it is that goes wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.