Jump to content

php


gaurav.iit

Recommended Posts

You are likely getting an error that would help pin point the cause of the problem. Add the following three lines of code, immediately after your first opening <?php tag, before any session_start statement, and see what if any errors are reported -

 

ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(-1);

Link to comment
Share on other sites

If you search the forum for the phrase - 'isn't working', you will find that means absolutely nothing to us, because we are not standing right next to you and don't know what you saw or what you expected to see. For any specific code or even one changed line in some code, there can be a dozen different symptoms, and for any symptom there can be a dozen different things that might causing that symptom. In programming, there's not a magical one to one relationship between 'isn't working' and what is causing the problem.

 

To get help with your code, you must post enough of your code the duplicates the problem, a statement (or picture) of the actual symptoms you saw in front of you that leads you to believe that your code isn't working, and a statement of what the actual expected result should have been. If you are getting a blank page in your browser, you also need to do a 'view source' of the page and post information about what you saw in the view source.

Link to comment
Share on other sites

ok..so i have database which contains a table girls with fields Serial(int)  hits(int) name(text) ...following is code for homepage

<?php
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(-1);
session_start();
$con = mysql_connect("localhost","gaurav","");
mysql_selectdb("website",$con);
$sql = "Select COUNT(*) from girls";
$var =  mysql_query($sql,$con);
$count=mysql_result($var, 0);
$index1 = rand(1,$count);
$index2;
while(1)
{
$index2 = rand(1,$count);
if($index1 != $index2)
break;
}
$_SESSION['index1'] = $index1;
$_SESSION['index2'] = $index2;


$sql = mysql_query("SELECT * FROM girls WHERE Serial=$index1");
$row = mysql_fetch_array($sql);
$name1 =  $row['name'];
$hits1 =  $row['hits'];
$sql = mysql_query("SELECT * FROM girls WHERE Serial=$index2");
$row = mysql_fetch_array($sql);
$name2 =  $row['name'];
$hits2 =  $row['hits'];
echo <<<ECO

<html>
<head>
<script src="jquery.js"></script>
<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function in1(){

var ajaxRequest;  

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}




ajaxRequest.open("GET", "girls.php", true);
ajaxRequest.send(null); }

function in2(){
var ajaxRequest;  

try{
	// Opera 8.0+, Firefox, Safari
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}


       ajaxRequest.open("GET", "girls1.php", true);
ajaxRequest.send(null); }


//-->
</script>
</head>
<body > 
//some html code
                           <a href="index.php" onclick="in2();"><img src="t1.png" id="t1" /></a>
                           <a href="index.php" onclick="in1();"><img src="t2.png" id="t2" /></a>
</body>
</html>
                           
ECO;
?>

 

and girls.php is

<?php
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(-1);
session_start();
$con = mysql_connect("localhost","gaurav","");
mysql_selectdb("website",$con);
$myvar = $_SESSION['index1'];
$sql = "UPDATE girls SET hits = hits + 1 WHERE Serial = $myvar";
mysql_query($sql,$con);
?>

 

similarly is girls1.php ..when i click t1.png or t2.png the hits are supposed to be incremented...but its not happening so when i hosted it...

Link to comment
Share on other sites

<a href="index.php" onclick="in2();"><img src="t1.png" id="t1" /></a>
<a href="index.php" onclick="in1();"><img src="t2.png" id="t2" /></a>

Should be

<a href="javascript:in1();"><img src="t1.png" id="t1" /></a>
<a href="javascript:in2();"><img src="t2.png" id="t2" /></a>

 

 

Actually it should be something like:

<a href="girl.php?id=t1&action=increment" onclick="in1();"><img src="t1.png" id="t1" /></a>
<a href="girl.php?id=t2&action=increment" onclick="in2();"><img src="t2.png" id="t2" /></a>

 

That way it works for people without Javascript.

Link to comment
Share on other sites

@scootstah This is an AJAX site. It depends on javascript being turned on. ;D

 

Just because AJAX is used doesn't mean it depends on Javascript being turned on.

 

Um, indeed it does. You cannot create Ajax without JavaScript.

Link to comment
Share on other sites

@scootstah This is an AJAX site. It depends on javascript being turned on. ;D

 

Just because AJAX is used doesn't mean it depends on Javascript being turned on.

 

Um, indeed it does. You cannot create Ajax without JavaScript.

 

I think scootstah was just trying to say that in order to use AJAX, you don't need to leave non-JS users in the lurch.

 

still not working guys..

 

If you're using a shared host it's possible that they have purposefully prevented you from showing the errors. Is there an error log somewhere in the directories you have access to? It will probably be called "error_log", or postfixed with that.

Link to comment
Share on other sites

You really have no way to know if your getting to girls.php. Set up your responseText. Try something like alert(ajaxRequest.responseText);

 

put an echo as your first line in girls.php just to see if your getting into it. Then use echos to trace what your doing especially check your variables.

Link to comment
Share on other sites

@scootstah This is an AJAX site. It depends on javascript being turned on. ;D

 

Just because AJAX is used doesn't mean it depends on Javascript being turned on.

 

Um, indeed it does. You cannot create Ajax without JavaScript.

 

I think scootstah was just trying to say that in order to use AJAX, you don't need to leave non-JS users in the lurch.

 

Indeed. AJAX is mostly used for user convenience. There's no reason you can't add regular request functionality, which my example did just that. If the Javascript didn't run they were simply linked to a page which would increase the hit.

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.