NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page How would I intergrate Javascript with php

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 06-30-2005, 06:19 AM THREAD STARTER               #1 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



How would I intergrate Javascript with php


how would i intergrate javascript into the php brackets, i cant get it to work right, even when i change the "'s to \".

can some one please help me
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
-Ray- is offline  
Old 06-30-2005, 06:40 AM   #2 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,809
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



you just need to use a ' to wrap the javascript and \' to hide markup script. Give me an example and ill take a shot

-Steve
stscac is offline  
Old 06-30-2005, 06:58 AM THREAD STARTER               #3 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



[QUOTE] #connect to MySQL
$conn = @mysql_connect("localhost","---","-----")
or die("Could not connect to MySQL");
#select a database
$db = @mysql_select_db("template_users",$conn)
or die("Could not select database");
????: NamePros.com http://www.namepros.com/programming/103014-how-would-i-intergrate-javascript-php.html

#create the SQL query
$sql = "insert into pm (whoto,whofrom,subject,message)
values (\"$whoto\",\"$username\",\"$sub\",\"$msg\")";
$result = @mysql_query($sql,$conn)
or die("Could not execute query");


if($result)
{

<script type="text/javascript">

<!--
function delayer(){
document.location = "members.php?page=messagebox"
}
-->
</script>


}else{
echo("failed");

?>
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
Last edited by templaterave; 06-30-2005 at 07:13 AM.
-Ray- is offline  
Old 06-30-2005, 07:12 AM   #4 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,809
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



ok, you're problem is simple,you just forgot a couple lines of code - try this

PHP Code:
<?php
#connect to MySQL
$conn = @mysql_connect("localhost","---","-----")
or die(
"Could not connect to MySQL");
#select a database
$db = @mysql_select_db("template_users",$conn)
or die(
"Could not select database");

#create the SQL query
$sql "insert into pm (whoto,whofrom,subject,message)
values (\"
$whoto\",\"$username\",\"$sub\",\"$msg\")";
$result = @mysql_query($sql,$conn)
or die(
"Could not execute query");
????: NamePros.com http://www.namepros.com/showthread.php?t=103014


if(
$result)
{
?>
<script type="text/javascript">

<!--
function delayer(){
document.location = 'members.php?page=messagebox';
}
-->
</script>
<?
}

}else{
echo(
"failed");

?>
let me know if that works

-Steve
stscac is offline  
Old 06-30-2005, 07:46 AM THREAD STARTER               #5 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



ok, this is what i have now, but i get an error. Parse error: parse error, unexpected $ in /home/template/public_html/mb/compose.php on line 69

theres no line 69 in the code... in only goest down to 68

Quote:
#connect to MySQL
$conn = @mysql_connect("localhost","---","----")
or die("Could not connect to MySQL");
#select a database
$db = @mysql_select_db("----",$conn)
or die("Could not select database");

#create the SQL query
$sql = "insert into pm (whoto,whofrom,subject,message)
values (\"$whoto\",\"$username\",\"$sub\",\"$msg\")";
$result = @mysql_query($sql,$conn)
or die("Could not execute query");

if($result)
{
?>
<script type="text/javascript">

<!--
function delayer(){
document.location = 'members.php?page=messagebox';
}
-->
</script>


<?
}else{
echo("failed");
}
?>
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
-Ray- is offline  
Old 06-30-2005, 08:49 AM   #6 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Can you paste the full code?
Porte is offline  
Old 06-30-2005, 12:45 PM THREAD STARTER               #7 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



ok i fixed ther error, the problem was that i had put an else command in wrong. Anyway, did what you told me, except it does the same thing, I included a a screen shot. Also the javascript still dont work

The code im using is below


PHP Code:
 if($result)
{
 ?>
 <script type="text/javascript">

<!--
function delayer(){
document.location = 'members.php?page=messagebox';
}
//-->
</script>
<body onLoad="setTimeout('delayer()', 5000)">
 <?

echo("<font face=\"Verdana\" size=\"2\" color=\"#333333\">Your message has been sent.</font><p><font face=\"Verdana\" size=\"2\" color=\"#333333\">You are now being redirected to your<a href=\"members.php?page=messagebox\"><font color=\"#333333\">message box</font></a>.</font></p>");
????: NamePros.com http://www.namepros.com/showthread.php?t=103014


 }
}
?>

Screen Shot of problem
Attached Images
File Type: jpg problem.JPG (98.4 KB, 8 views)
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
Last edited by templaterave; 06-30-2005 at 12:49 PM.
-Ray- is offline  
Old 06-30-2005, 04:15 PM   #8 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
Join Date: Aug 2004
Posts: 3,809
stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of
 



instead of the javascript, you should use:
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=103014
header
("Location: http://www.address.ext/members.php?page=messagebox");
?>
and keep everything in php - unless you have a valid reason for using js

-Steve
stscac is offline  
Old 06-30-2005, 06:04 PM THREAD STARTER               #9 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



well, the reason i use java for that is that i cant figure out how to have a timed redirection in php. Also my other reason for using java is googles adwords...
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
-Ray- is offline  
Old 06-30-2005, 09:33 PM   #10 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

could use sleep()
axilant is offline  
Old 07-01-2005, 12:01 AM   #11 (permalink)
NamePros Regular
Join Date: Feb 2004
Location: Student @ UConn
Posts: 411
gamex has a spectacular aura aboutgamex has a spectacular aura about
 



if you use the php redirection, you can only use it if there is no output, otherwise you will get an error say the headers have already been sent out.
__________________
Joe
gamex is offline  
Old 07-01-2005, 08:39 AM THREAD STARTER               #12 (permalink)
Senior Member
 
-Ray-'s Avatar
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,839
-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of-Ray- has much to be proud of
 



thats not always true. The ob_start() command will buffer the headers so headers can be sent. Im great with php, just havin issues on things i never did.

more about output buffering
http://us4.php.net/ob_start
__________________
Poker News, articles, discussion
LIKE THIS

Its an iPod, a phone, and an internet communications device.
-Ray- is offline  
Old 07-02-2005, 01:10 AM   #13 (permalink)
New Member
Join Date: Jul 2005
Posts: 8
val539 is an unknown quantity at this point
 



PHP Code:
<?
if($result) { 
?> 
        <script type="text/javascript"> 
        <!-- 
        function delayer(){ 
        document.location = 'members.php?page=messagebox'; 
        } 
        //--> 
        </script> 
        <body onLoad="setTimeout('delayer()', 5000)"> 
        <? 
        
echo ("<font face=\"Verdana\" size=\"2\" color=\"#333333\">Your message has been sent.</font><p><font face=\"Verdana\" size=\"2\" color=\"#333333\">You are now being redirected to your <a href=\"members.php?page=messagebox\"><font color=\"#333333\">message box</font></a>.</font></p>"); 
        
//here print the rest of your html code
        //i suppose :
        
echo ("</body>\n</html>");
        
//these 2 lines help u a lot
        
exit;
????: NamePros.com http://www.namepros.com/showthread.php?t=103014
        die;
    }
//we think that u open a condition before 'if($result) { '
????: NamePros.com http://www.namepros.com/showthread.php?t=103014
?>
or you can write this (it's better for browser don't support javascript and more security)

PHP Code:
<? @session_start();

//---- your code

    
if($result) { 
        
$_SESSION['page']='messagebox';
        print 
"\n<meta http-equiv=\"refresh\" content=\"1; URL=members.php\">\n</head>\n<body>\n<br><br><br><font face=\"Verdana\" size=\"2\" color=\"#333333\">Your message has been sent.</font><p><font face=\"Verdana\" size=\"2\" color=\"#333333\">You are now being redirected to your <a href=\"members.php\"><font color=\"#333333\">message box</font></a>.</font></p><br>If nothing happens, <a href=\"index\">click here</a>.<br><br><br><br><br>";
        
//here print the rest of your html code
        //i suppose :
        
print "</body>\n</html>";
        
//these 2 lines help u a lot
        
exit;
        die;
    }
//we think that u open a condition before 'if($result) { '
?>
and in members.php u can put something like :

PHP Code:
<? @session_start();
    if ( (isset(
$_SESSION['page'])) && ($_SESSION['page']=='messagebox') ) { 
        
//content of members.php?page=messagebox
    
}    
?>
Regards
val539 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 12:35 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
How I fill javascript array with php variables? wiedzim CODE 0 03-31-2004 03:45 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger