[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 06-30-2005, 05:19 AM   #1 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


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
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"
-Ray- is offline  
Old 06-30-2005, 05:40 AM   #2 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

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, 05:58 AM   #3 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


[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");

#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");

?>
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"

Last edited by templaterave; 06-30-2005 at 06:13 AM.
-Ray- is offline  
Old 06-30-2005, 06:12 AM   #4 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

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");


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, 06:46 AM   #5 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


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");
}
?>
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"
-Ray- is offline  
Old 06-30-2005, 07:49 AM   #6 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

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, 11:45 AM   #7 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


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>");


}
}
?>

Screen Shot of problem
Attached Images
File Type: jpg problem.JPG (98.4 KB, 8 views)
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"

Last edited by templaterave; 06-30-2005 at 11:49 AM.
-Ray- is offline  
Old 06-30-2005, 03:15 PM   #8 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

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
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, 05:04 PM   #9 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


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...
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"
-Ray- is offline  
Old 06-30-2005, 08:33 PM   #10 (permalink)
Account Closed
 
axilant's Avatar
 
Join Date: May 2004
Location: /etc/passwd
Posts: 2,194
0.00 NP$ (Donate)

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


could use sleep()
axilant is offline  
Old 06-30-2005, 11:01 PM   #11 (permalink)
NamePros Regular
 
gamex's Avatar
 
Join Date: Feb 2004
Location: Student @ UConn
Posts: 408
73.95 NP$ (Donate)

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
CarrotCash.com
gamex is offline  
Old 07-01-2005, 07:39 AM   #12 (permalink)
An American Soldier
 
-Ray-'s Avatar
 
Join Date: Jun 2005
Location: Pennsylvania
Posts: 1,630
2.53 NP$ (Donate)

-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold-Ray- is a splendid one to behold


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
__________________
Completely Free cPanel Hosting
-- Deployed to Afghanistan --
"There is no such thing as rich over-night unless you owned Google stock in 2006"
-Ray- is offline  
Old 07-02-2005, 12:10 AM   #13 (permalink)
New Member
 
Join Date: Jul 2005
Posts: 8
12.00 NP$ (Donate)

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;
        die;
    }
}
//we think that u open a condition before 'if($result) { '
?>
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:39 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85