473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why can't I send an email address via a param in a function?

Any help is appreciated

Here's the php code that writes a simple string that can be interpreted as a simple href

Expand|Select|Wrap|Line Numbers
  1.  
  2.     $someNameVar = $row["name"]; 
  3.     $someEmailVar = $row["email"]; 
  4.     $someLikeVar = $row["what_u_liked"];
  5.  
  6.     addslashes($someNameVar);
  7.     addslashes($someEmailVar);
  8.     addslashes($someLikeVar); 
  9.  
  10.  
  11.     echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');  style=cursor:pointer;cursor:hand;>Click here</a>"; 
  12.  
  13.  
No matter what I have tried to do, the browser gives back an error of unterminated string literal.

Thanks in advance
Jun 17 '07 #1
7 1426
ak1dnar
1,584 Expert 1GB
PHP is not giving that kind of Errors.Problem is with your JavaScript code,because with some sample values for all these three variables its calling for myresume_dom.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. function myresume_dom(para1,para2,para3)
  3. {
  4. alert(para1+"\n"+para2+"\n"+para3);
  5. }
  6. </script>
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. //$someNameVar = $row["name"];
  3. $someNameVar = 'someNameVar';
  4. //$someEmailVar = $row["email"];
  5. $someEmailVar = 'someEmailVar@somewhere.com';
  6. //$someLikeVar = $row["what_u_liked"];
  7. $someLikeVar = 'someLikeVar';
  8.  
  9. addslashes($someNameVar);
  10.  
  11. addslashes($someEmailVar);
  12.  
  13. addslashes($someLikeVar);
  14.  
  15. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');  style=cursor:pointer;cursor:hand;>Click here</a>";
  16. ?>
  17.  
Jun 17 '07 #2
PHP is not giving that kind of Errors.Problem is with your JavaScript code,because with some sample values for all these three variables its calling for myresume_dom.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. function myresume_dom(para1,para2,para3)
  3. {
  4. alert(para1+"\n"+para2+"\n"+para3);
  5. }
  6. </script>
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. //$someNameVar = $row["name"];
  3. $someNameVar = 'someNameVar';
  4. //$someEmailVar = $row["email"];
  5. $someEmailVar = 'someEmailVar@somewhere.com';
  6. //$someLikeVar = $row["what_u_liked"];
  7. $someLikeVar = 'someLikeVar';
  8.  
  9. addslashes($someNameVar);
  10.  
  11. addslashes($someEmailVar);
  12.  
  13. addslashes($someLikeVar);
  14.  
  15. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');  style=cursor:pointer;cursor:hand;>Click here</a>";
  16. ?>
  17.  
First, thank you for your help.

And you are absolutely correct. I believe the problem is that the value of "$someLikeVar" has spaces within the string. For example, say the value is "AJAX DOM PHP MYSQL" which this is the actual example where I receive the error mentioned above.

So, then if you placed your cursor over the link generated, then it would look something like this in the status bar at the bottom of the browser -- "myresume_dom('Bob','bob@yahoo.com','AJAX"

and that's all it shows -- it doesn't terminate the string literal.

I have tried

Expand|Select|Wrap|Line Numbers
  1.  
  2. addslashes() and htmlentities() before generating the string.
  3.  
  4.     $someNameVar = $row["name"]; 
  5.     $someEmailVar = $row["email"]; 
  6.     $someLikeVar = $row["what_u_liked"];
  7.  
  8. addslashes($someNameVar);
  9. addslashes($someEmailVar);
  10. addslashes($someLikeVar);
  11.  
  12. htmlentities($someNameVar);
  13. htmlentities($someEmailVar);
  14. htmlentities($someLikeVar);
  15.  
  16. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar." You chose ".$someLikeVar."<br><a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');  style=cursor:pointer;cursor:hand;>Click here</a>";
  17.  
  18.  
What's strange is that it inserts the value into the MySql table with the complete string. I even made sure that I was receiving the complete string by doing a select and displaying it properly, as you can see in the code above, but for some reason the spaces between the words of the third variable just will not pass properly.

Thanks once more for your help and any thoughts would be appreciated
Jun 17 '07 #3
PHP is not giving that kind of Errors.Problem is with your JavaScript code,because with some sample values for all these three variables its calling for myresume_dom.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. function myresume_dom(para1,para2,para3)
  3. {
  4. alert(para1+"\n"+para2+"\n"+para3);
  5. }
  6. </script>
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. //$someNameVar = $row["name"];
  3. $someNameVar = 'someNameVar';
  4. //$someEmailVar = $row["email"];
  5. $someEmailVar = 'someEmailVar@somewhere.com';
  6. //$someLikeVar = $row["what_u_liked"];
  7. $someLikeVar = 'someLikeVar';
  8.  
  9. addslashes($someNameVar);
  10.  
  11. addslashes($someEmailVar);
  12.  
  13. addslashes($someLikeVar);
  14.  
  15. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');  style=cursor:pointer;cursor:hand;>Click here</a>";
  16. ?>
  17.  

You were correct. It has nothing to do with the PHP code. It was the spaces in the string that I was trying to pass.

Expand|Select|Wrap|Line Numbers
  1.  
  2.     $var = str_replace(" ", "", $someLikeVar);
  3.  
  4. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar." You chose ".$someLikeVar."<br>";
  5. echo "<a href=javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$var."');"; 
  6. echo " style=cursor:pointer;cursor:hand;>Click here</a>";
  7.  
  8.  
Once I removed the spaces between the words in the string being passed by the variable, then it sent the information just fine, but why can't I send a string with spaces?

I don't think that I've ever had to do it before, but I can not imagine why this would be an issue when the string is surrounded by single quotes. Shouldn't Javascript be able to interpret this as one complete string?

Should I send the string as an array with the spaces, but how would a php array be sent to js?
Jun 17 '07 #4
ak1dnar
1,584 Expert 1GB
You were correct. It has nothing to do with the PHP code. It was the spaces in the string that I was trying to pass.

Expand|Select|Wrap|Line Numbers
  1. //REMOVED
  2.  
Once I removed the spaces between the words in the string being passed by the variable, then it sent the information just fine, but why can't I send a string with spaces?

I don't think that I've ever had to do it before, but I can not imagine why this would be an issue when the string is surrounded by single quotes. Shouldn't Javascript be able to interpret this as one complete string?

Should I send the string as an array with the spaces, but how would a php array be sent to js?
No need to Use Arrays here just a simple changes. we'll try to enclose your href value with double quotes.and since you are echoing it through php i have to use the escape ( \") .

And here we go.Try this way.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript" type="text/javascript">
  4. function myresume_dom(para1,para2,para3)
  5. {
  6. alert(para1+"\n"+para2+"\n"+para3);
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <?php 
  13. //$someNameVar = $row["name"];
  14. $someNameVar = 'some Name Var';
  15. //$someEmailVar = $row["email"];
  16. $someEmailVar = 'someEmailVar@somewhere.com';
  17. //$someLikeVar = $row["what_u_liked"];
  18. $someLikeVar = 'some Like Var';
  19. addslashes($someNameVar);
  20. addslashes($someEmailVar);
  21. addslashes($someLikeVar);
  22. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=\"javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');\" style=cursor:pointer;cursor:hand;>Click here</a>";?>
  23.  
  24. </body>
  25. </html>
  26.  
Jun 18 '07 #5
No need to Use Arrays here just a simple changes. we'll try to enclose your href value with double quotes.and since you are echoing it through php i have to use the escape ( \") .

And here we go.Try this way.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript" type="text/javascript">
  4. function myresume_dom(para1,para2,para3)
  5. {
  6. alert(para1+"\n"+para2+"\n"+para3);
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <?php 
  13. //$someNameVar = $row["name"];
  14. $someNameVar = 'some Name Var';
  15. //$someEmailVar = $row["email"];
  16. $someEmailVar = 'someEmailVar@somewhere.com';
  17. //$someLikeVar = $row["what_u_liked"];
  18. $someLikeVar = 'some Like Var';
  19. addslashes($someNameVar);
  20. addslashes($someEmailVar);
  21. addslashes($someLikeVar);
  22. echo "Welcome, ".$someNameVar." with the email of ".$someEmailVar."<br><a href=\"javascript:myresume_dom('".$someNameVar."','".$someEmailVar."','".$someLikeVar."');\" style=cursor:pointer;cursor:hand;>Click here</a>";?>
  23.  
  24. </body>
  25. </html>
  26.  

Hey, it worked -- OK! Explain to me why this worked, because I know that I had to have tried this combination of single and double quotes, without the escape sequence, so why does the escape sequence make such a difference?
Jun 21 '07 #6
ak1dnar
1,584 Expert 1GB
Hope this might be answer for your question.
Passing variables to JavaScript

Thanks,
-Ajaxrand
Jun 21 '07 #7
Hope this might be answer for your question.
Passing variables to JavaScript

Thanks,
-Ajaxrand
Excellent. Thank you once again :-)
Jun 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
0
by: Frank | last post by:
Any suggestions on how I should handle this? I was asked to convert a small web application that was written in classic ASP into ASP.NET. The original site uses some VBScript to interface with...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
10
by: sufian | last post by:
I am new to the world of PHP. Below is my simple PHP file "invite.php" with a form having an image send button (I have to use the image send button because it is the requirement, may be this is...
1
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
0
by: varnie | last post by:
hell-o !~ i faced weird problem during usage boost::pool_allocator. after i've changed: typedef boost::shared_ptr< param > ParamPtr; typedef std::vector< ParamPtr > ParamPtrVector; with:
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.