hi,
this is my first post.

I am a php coder and know very little javascript. I have nearly finished a dating site for a client. Thing is he wants private chat in it. I have found some opensource chatroom code that I am trying to hack to make work privately.

I have nearly cracked it but I am struggling to get php to run within javascript.

I have an confirm popup when someone request a chat with a user and depending on whether the user clicks yes or no then the mysql_query enters either yes or no into the request field.

but I find that on page load both mysql queries run before the popu p confirm box has even had a chance to load.

I know that this is not written in ajax at the moment, but I think thats why it isnt working...because it should be.

My problem is that i have no knowledge of ajax at the mo and the site needs to be signed off asap, so don't have the time to learn ajax to sort it out myself.

any help would be hugely appreciated

heres the code

var answer = confirm ("wants to chat privatley with you")
			
if (answer)
{
	popitup_chat('<? echo $url; ?>');		
	<?
	mysql_query("INSERT INTO chat_pms(target,name,time,timestamp,request)VALUES('$from','$c_id','$time_stamp','$time_stamp','yes')"); 
	?>
}
else
{
	<?
		mysql_query("INSERT INTO chat_pms(target,name,time,timestamp,request)VALUES('$from','$c_id','$time_stamp','$time_stamp','no')"); 
	?>
}

Recommended Answers

All 3 Replies

Yeah, Javascript and PHP don't work like that. PHP is run before the page gets to the user. Javascript is run after it gets to the user so those inserts are happening every single time someone visits the page, not based on that confirm popup.

so don't have the time to learn ajax to sort it out myself.

You might want to go ahead and make time, this is pretty much an essential skill for web developers.

Shawn I agree , it is on my list of things to do, but since i have to get the site signed off by the end of the week, I don't think I have time to learn the required code and get it working in that time.

Shawn I agree , it is on my list of things to do, but since i have to get the site signed off by the end of the week, I don't think I have time to learn the required code and get it working in that time.

Learning entry-level AJAX takes all of 2 or 3 hours. Clicky

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.