Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

Unterminated string constant

Hi everyone hope you can help.

Guys i have another problem with a variable.

===================================
The following works:
===================================
function wz_tooltip_image ($image, $displaynamelink, $title) {
$stuffimage = "<a href=\"#\" $style onmouseover=\"$width; Tip('<img src=\'$image\'>',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
echo $stuffimage;
}

Calling it by:

<?php wz_tooltip_image("cat.jpg","Go there", $title); ?>

===================================
The following I cant get working:
===================================
function wz_tooltip_image ($image, $displaynamelink, $title) {
$stuffimage = "<a href=\"#\" $style onmouseover=\"$width; Tip('<img src=\'$image\'>',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
echo $stuffimage;
}

Calling it by:
wz_tooltip_image($row->image_ent, $row->name_ent, $row->name_ent);      

The problem im having is with the $image parameter above.
In the first example, I hard code an image name, which worked, but in this case, the

$row->image_ent,

is pointing to a blob field in a mysql table.
Im getting unterminated string constants on this and cannot work out why.
I wanted to see if the images were okay in the database, separate from the above code, and I can display them fine, so there is something wrong with the way im escaping in the second example.

Any help guys greatly appreciated.
0
Simon336697
Asked:
Simon336697
  • 18
  • 7
  • 5
  • +1
3 Solutions
 
Roger BaklundCommented:
$image is supposed to contain an URL as a string. Why would you put a blob into it?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
should that not be:
function wz_tooltip_image ($image, $displaynamelink, $title) {
$stuffimage = "<a href=\"#\" $style onmouseover=\"$width; Tip('<img src=\\'$image\\'>',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
echo $stuffimage;
}

Open in new window

0
 
Roger BaklundCommented:
Tip('<img src=\'$image\'>'

should be

('<img src=\"$image\" alt=\"\" />'

Allways double quotes for html attributes, allways use an alt attribute for image elements, and the ' />' ending is to make it xhtml compliant while at the same time beeing backward compatible with html.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Roger BaklundCommented:
You must of course keep "Tip":

Tip('<img src=\"$image\" alt=\"\" />'
0
 
Simon336697Author Commented:
Hi cxr,
Mate thank you for responding.
Im trying to display the images cxr.
What am i doing wrong bud?

What the function does is when im just hard coding the image name, i have a link, that when I hover over it, it displays that image.

With the other one im having issues with, im trying to do the same thing, except this time, all links are rows to records in a mysql table.
function wz_tooltip_image ($image, $displaynamelink, $title) {
Im going through a

while ($row = mysql_fetch_object($rs)) {
wz_tooltip_image($row->image_ent, $row->name_ent, $row->name_ent);
}

to do this..




0
 
hieloCommented:
>>is pointing to a blob field in a mysql table.
That's the problem. You can't point to the actual image binary data. Here's an experiment for you. Save some image (any image) to your desktop and then open it with notepad. What do you see?

Now when you code an HTML image tag you do so like this:
<img src="theImage.gif"...> 
You do NOT provide the "raw image" in the src attribute. You provide the url to the image. The browser then submits another request to get the actual "raw image". So, your problem is that you are actually providing the "raw image". Instead what you need is provide a url to that image. In this case, create a php page (imageFetcher.php) that will retrieve the desired image if you provide the corresponding id. So in you case instead of:
wz_tooltip_image($row->image_ent, $row->name_ent, $row->name_ent);   
use:
wz_tooltip_image("http://www.yoursite.com/imageFetcher.php?id=" . $row->image_id, $row->name_ent, $row->name_ent);   
you would of course need to code imageFetcher.php:
<?php
//send appropriate header:
header("Content-type: image/jpg"); 
//connect to db here
//then query db for desired image:
$result = mysql_query("SELECT image_ent FROM images where id=" . $_GET['id']); 
$image=mysql_fetch_assoc($result);
echo $image['image_ent'];
?>

Open in new window

0
 
Simon336697Author Commented:
The wz_tooltip_image is a function that displays tooltips, and you can put images inside the tooltip, so im trying to get the blob image into it.
I can successfully get other text fields into the tooltip, but having issues with the blob image.
When i hard code the image, i can see that in the tooltip, so i dont know what is wrong when im using
$row->image_ent,
0
 
hieloCommented:
>>so im trying to get the blob image into it.
It's not going to work. Read my previous comment. Use the imageFetcher.php I provided. Make sure you connect to the db first.

NOTE: for it to work, on the code you posted you need to retrieve a unique per image
0
 
Simon336697Author Commented:
Thanks so much hielo....I will give it a try now mate youre the best :>)
0
 
Simon336697Author Commented:
Hielo bud,

Ive changed the function to be like this...

=========================================================== index2.php
function wz_tooltip_image ($image) {
$wz_tooltip_config_image = "
STICKY, true,
FIX, [740,235],
WIDTH, 870,  
HEIGHT, 565,
BGCOLOR, 'black',
TITLE, 'df',
TITLEFONTCOLOR, '#FFC',
TITLEBGCOLOR, '#664',  
EXCLUSIVE, false,
CLICKSTICKY, true,
CLICKCLOSE, false,
CLOSEBTN, true
";
$styleimage = "style=\"font-family:arial; font-size:xx-small; padding:0; margin:0; border:none;\"";
$stuffimage = "<a href=\"#\" $styleimage onmouseover=\"Tip($image,$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">displaynamelink</a>";
echo $stuffimage;
}
==============================================

and in the while loop, calling it like:

wz_tooltip_image("http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent=" . $row->id_ent);

In the imagefetcher.php file, i have the following...

<?php
//send appropriate header:
header("Content-type: image/jpg");
//connect to db here
$host = "localhost";
$user = "root";
$pass = "password";
$data = "pagination";
$conn =       mysql_connect($host, $user, $pass) or die (mysql_error());
                  mysql_select_db ($data, $conn) or die (mysql_error());
//then query db for desired image:
$getme = $_GET['id_ent'];
$result = mysql_query("SELECT image_ent FROM entries_ent where id_ent='$getme'");
$image=mysql_fetch_assoc($result);
echo $image['image_ent'];
?>


====================

If i open up image_fetcher.php on its own, and just change the $getme to a valid id, I get the image displayed.

But when I run index2.php, Im getting
Error: Expected ')'
For every row.




0
 
Simon336697Author Commented:
hielo mate,

where you have...

wz_tooltip_image("http://www.yoursite.com/imageFetcher.php?id=" . $row->image_id, $row->name_ent, $row->name_ent);  

the wz_tooltip_image wants each parameter in single quotes.
Im only using the ?id=" . $row->image_id bit and not $row->name_ent, $row->name_ent
but how would i encapsulate

wz_tooltip_image("http://www.yoursite.com/imageFetcher.php?id=" . $row->image_id)

the above so it would be:
wz_tooltip_image(' above url ');

0
 
hieloCommented:
try:
function wz_tooltip_image ($image) {
$wz_tooltip_config_image = "STICKY, true, FIX, [740,235], WIDTH, 870, HEIGHT, 565, BGCOLOR, 'black', TITLE, 'df', TITLEFONTCOLOR, '#FFC', TITLEBGCOLOR, '#664', EXCLUSIVE, false, CLICKSTICKY, true, CLICKCLOSE, false, CLOSEBTN, true"; 
$styleimage = "font-family:arial; font-size:xx-small; padding:0; margin:0; border:none;";
 
printf('<a href="#" style="%s" onmouseover="Tip(\'%s\',%s)" onmouseout="UnTip()">displaynamelink</a>'
	,$styleimage
	,$image
	,$wz_tooltip_config_image
	);
}

Open in new window

0
 
Simon336697Author Commented:
Thanks hielo mate. will do right now :>) you are so helpful
0
 
Simon336697Author Commented:
Hielo, I tested yours mate and here are the results...

=========================================== index2.php

Your function...

wz_tooltip_image("http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent=" . $row->id_ent);


===================================== in image_fetcher.php

//send appropriate header:
header("Content-type: image/jpg");
//connect to db here
$host = "localhost";
$user = "root";
$pass = "password";
$data = "pagination";
$conn =       mysql_connect($host, $user, $pass) or die (mysql_error());
                  mysql_select_db ($data, $conn) or die (mysql_error());
//then query db for desired image:
$getme = $_GET['id_ent'];
$result = mysql_query("SELECT image_ent FROM entries_ent where id_ent='$getme'");
$image=mysql_fetch_assoc($result);
echo $image['image_ent'];
?>

=================================================

Hielo, for each record displayed, it is just printing out:

http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent=5387

in the tooltip and not the image.

It does not error either if i totally change the name of the URL above.
The ids are being returned right, but the url looks like it is being ignored.

If I hard code an image where the
http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent=5387
is, and do this outside a while loop, it works.



0
 
Simon336697Author Commented:
Hielo,
Ill upload an example with all files that work with a hard coded image.
0
 
Roger BaklundCommented:
You are not outputting an html img now, so this behaviour is correct.

$image now contains  "http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent=" . $row->id_ent

It should contain '<img src="http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent.'" alt="" />'

Because this will be used within a " quoted html attribute, there must be an \ before each ", and because PHP will 'eat' a single backslash, you must double them:

'<img src=\\"http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent.'\\" alt=\\"\\" />'

So, try this call to wz_tooltip_image():
wz_tooltip_image('<img src=\\"http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent.'\\" alt=\\"\\" />');

Open in new window

0
 
Simon336697Author Commented:
Hielo mate.

Here is a working example of what im trying to do mate.

In the code snippet, is the php file for it.
=========================================== hielo.php
 
<?php
 
function wz_tooltip_image ($image, $displaynamelink, $title) {
 
$wz_tooltip_config_text = "
STICKY, true, 
FIX, [240,210], 
WIDTH, 300,  
HEIGHT, 100, 
BGCOLOR, '#ffff80', 
TITLE, '$title', 
TITLEFONTCOLOR, '#FFC', 
TITLEBGCOLOR, '#664',  
EXCLUSIVE, false, 
CLICKSTICKY, true, 
CLOSEBTN, true
";   
 
$style = "style=\"font-size:xx-small;\"";
$stuff = "<a href=\"#\" $style onmouseover=\"$width; Tip('<img src=\'$image\'>',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
echo $stuff;
}
 
$title = "Hi Champion Hielo";
?>
 
 
<?php // wz_tooltip_text($text,"Go there", $title); ?><br>
 
<?php wz_tooltip_image("cat.jpg","Go there", $title); ?><br>
 
</body>
	
	
</html>
============================================================

Open in new window

cat.jpg
tip-centerwindow.txt
tip-followscroll.txt
wz-tooltip.txt
hielo.jpg
0
 
Simon336697Author Commented:
Thanks so much as well cxr.....pls see above.......im reading your post now...you guys are brilliant.
0
 
hieloCommented:
Simon, on the code I provided here (ID: 22763196) I was "fixing" what you supplied here (ID: 22762966). Upon closer inspection, that code you supplied is different from what you posted originally in the problem description. Why did you you remove the img tag from the Tip() argument?
0
 
hieloCommented:

function wz_tooltip_image ($image) {
$wz_tooltip_config_image = "STICKY, true, FIX, [740,235], WIDTH, 870, HEIGHT, 565, BGCOLOR, 'black', TITLE, 'df', TITLEFONTCOLOR, '#FFC', TITLEBGCOLOR, '#664', EXCLUSIVE, false, CLICKSTICKY, true, CLICKCLOSE, false, CLOSEBTN, true"; 
$styleimage = "font-family:arial; font-size:xx-small; padding:0; margin:0; border:none;";
 
printf('<a href="#" style="%s" onmouseover="Tip(\'<img src=\"%s\">\',%s)" onmouseout="UnTip()">displaynamelink</a>'
	,$styleimage
	,$image
	,$wz_tooltip_config_image
	);
}

Open in new window

0
 
Simon336697Author Commented:
Hi cx, with the following config, i get an unterminated string constant..
======================================= index2.php
 
function wz_tooltip_image ($image) {
 
$wz_tooltip_config_image = "
STICKY, true, 
FIX, [740,235], 
WIDTH, 870,  
HEIGHT, 565, 
BGCOLOR, 'black', 
TITLE, 'df', 
TITLEFONTCOLOR, '#FFC', 
TITLEBGCOLOR, '#664',  
EXCLUSIVE, false, 
CLICKSTICKY, true, 
CLICKCLOSE, false,
CLOSEBTN, true
";   
 
$styleimage = "style=\"font-family:arial; font-size:xx-small; padding:0; margin:0; border:none;\"";
$stuffimage = "<a href=\"#\" $styleimage onmouseover=\"Tip('$image',$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">displaynamelink</a>";
echo $stuffimage;
}
 
=======================================================
wz_tooltip_image('<img src=\\"http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent.'\\" alt=\\"\\" />');

Open in new window

0
 
Simon336697Author Commented:
Sorry hielo....im testing so much stuff here (and i know you great person and cxr are as well).
Bear with me im all over the place..
0
 
Simon336697Author Commented:
Hielo mate...

im going to try again with your post from 22763436.

Mate im sorry but how do i call the function?
0
 
Simon336697Author Commented:
If I call it like:

wz_tooltip_image(http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent);

I get unexpected :   (after the http)

I must be getting tired sorry guys u are so patient
0
 
Simon336697Author Commented:
With this..

wz_tooltip_image('http://localhost/dropdowndbpilot/pagination/imagefetcher.php?id_ent='.$row->id_ent');

I get:

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\wamp\www\dropdowndbpilot\pagination\index2.php on line 496
0
 
Roger BaklundCommented:
Yes, sorry Simon, my suggestion was wrong. I have done some tests, and I can't find a way to do this correctly. With 'this', I mean to output correct html with attribute values enclosed in double quotes, from within a html attribute.

One possible workaround is to drop the quotes, it will work in most browsers, but it is not standards compliant. Same goes for using single quotes. Will work in most browsers, but it is not standards compliant.

I think the best way is to use a wrapper function. Define this in head, within <script> tags:

function MyTip(img,conf) {
  Tip('<img src="'+img+'" alt="" />',conf);
}

...and call MyTip() in place of Tip() in your existing code. This way we move the double quotes in the img element attributes out of the onclick attribute, and it is no longer a problem.
0
 
Simon336697Author Commented:
Hi cxr, thanks for that..
Im embarrassed.....what version of my code would i use this with....sorry...im overtired.
0
 
Roger BaklundCommented:
To show the image in the tooltip, you need to include a html img element, i.e. a string like this:

<img src="image-URL-here" alt="" />

You had this in earlier versions of the wz_tooltip_image() PHP function.

The Tip() function is a javascript function, and you call it within the onclick attribute of the <a href="#" within the wz_tooltip_image() PHP function. Since you are allready within double quotes in the onclick attribute, you can not use double quotes in the Tip() function call:

onclick="Tip('double quotes not allowed here');"

In one of the above posts (ID: 22763257) you had the code working, it did not output any images because there was no html img element. If you changed Tip() to MyTip() in that version, and included the MyTip() function within <script> tags in the head part of the document, it should show the images.
0
 
Roger BaklundCommented:
Sorry, it's not onclick, it's onmouseover. I'm getting tired too. :)
0
 
Simon336697Author Commented:
Hi cxr,
Thank you so much for your great help mate.
And hielo..you guys are awesome.
Ill post another one on this and revisit it...i still cant get it working, but so much want to.
Mate thanks again...
Im going to try again in a few hours and post back my findings :>)
0
 
Simon336697Author Commented:
Guys, firstly...A HUGE HUGE THANK YOU to you..
Hielo,
Angellll
Cxr

You are so very patient with me.
Because this is so long, Im going to give you the points now and post another more cleaner up to date question on this.
I thank you so much.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 18
  • 7
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now