Solved

Unterminated string constant

Posted on 2008-10-20
31
446 Views
Last Modified: 2012-08-13
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
Comment
Question by:Simon336697
  • 18
  • 7
  • 5
  • +1
31 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22762508
$image is supposed to contain an URL as a string. Why would you put a blob into it?
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 60 total points
ID: 22762539
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22762550
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
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 210 total points
ID: 22762558
You must of course keep "Tip":

Tip('<img src=\"$image\" alt=\"\" />'
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22762562
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
 
LVL 82

Accepted Solution

by:
hielo earned 230 total points
ID: 22762566
>>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
 
LVL 1

Author Comment

by:Simon336697
ID: 22762573
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
 
LVL 82

Expert Comment

by:hielo
ID: 22762590
>>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
 
LVL 1

Author Comment

by:Simon336697
ID: 22762615
Thanks so much hielo....I will give it a try now mate youre the best :>)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22762966
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763078
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
 
LVL 82

Expert Comment

by:hielo
ID: 22763196
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763239
Thanks hielo mate. will do right now :>) you are so helpful
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22763257
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763318
Hielo,
Ill upload an example with all files that work with a hard coded image.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22763385
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763393
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763396
Thanks so much as well cxr.....pls see above.......im reading your post now...you guys are brilliant.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22763410
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
 
LVL 82

Expert Comment

by:hielo
ID: 22763436

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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763442
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763463
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763496
Hielo mate...

im going to try again with your post from 22763436.

Mate im sorry but how do i call the function?
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22763504
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763508
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22763521
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22763543
Hi cxr, thanks for that..
Im embarrassed.....what version of my code would i use this with....sorry...im overtired.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22763601
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22763616
Sorry, it's not onclick, it's onmouseover. I'm getting tired too. :)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22763642
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22765514
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now