hi guys...i have this prooblem which i like to acho a window pop up...but i cannot do so...the link does not seem to work and i cannot find any error in it.

I wonder if anyone can find any error here:

$ancpopup = "<div id=\"anctrigger\"><a href=\"#\" onclick=\"window.open(\'m_ancpopup.php?page=\'$eid\',\'ancpopup\',\'width=670px,height=470px,left=0px,top=100px,screenX=0,screenY=100\')\">Accident &amp; Conviction EXIST!</a></div>";

if(mysql_num_rows($result)<>0)
        {
            echo $ancpopup;
        }

Thanks in advance.

Dani AI

Generated

Nice follow-up: 's change fixed the immediate quoting/concatenation issue, and correctly reminded that pop-up blockers are a real concern. For a more robust, secure and modern solution, avoid building inline onclick strings from PHP. Put the PHP value into a safe data attribute (use json_encode() or explicit casting), attach an unobtrusive event handler in JavaScript, and build the URL there. That removes the common quote-escaping problems and makes the HTML easier to inspect and debug.

Example pattern (server -> HTML -> JS):

<?php
// server side: ensure $eid is safe for output
$eid_js = json_encode($eid);
?>
<a href="#" class="anc-link" data-eid=<?php echo $eid_js; ?>>Accident &amp; Conviction EXIST!</a>

<script>
document.addEventListener('click', function (e) {
  var a = e.target.closest('.anc-link');
  if (!a) return;
  e.preventDefault();
  var eid = a.dataset.eid;
  window.open('m_ancpopup.php?page=' + encodeURIComponent(eid),
              'ancpopup',
              'width=670,height=470,left=0,top=100');
});
</script>

Quick troubleshooting checklist:

  • View the generated HTML source to confirm the attribute contains the expected value.
  • Open the browser console and try calling window.open(...) directly to see if the features string is accepted.
  • Use numeric values (no "px") in the features string per the window.open spec — see Window.open - MDN.
  • Make sure the call is a direct user click; many blockers stop programmatic opens triggered asynchronously.

Security and maintenance notes:

  • If $eid should be numeric, cast it with (int)$eid or validate explicitly before output.
  • The old mysql_* extension is deprecated/removed; migrate to mysqli or PDO with prepared statements to avoid SQL injection (see PHP manual on the mysql extension deprecation).

These changes make the popup behavior easier to debug, more resistant to quoting errors, and better aligned with modern security practices.

Recommended Answers

All 4 Replies

try

<?php
    $ancpopup = "<div id=\"anctrigger\"><a href=\"#\" onclick=\"window.open('m_ancpopup.php?page=".$eid."','ancpopup','width=670px,height=470px,left=0px,top=100px,screenX=0,screenY=100')\">Accident &amp; Conviction EXIST!</a></div>";
if(mysql_num_rows($result)<>0)
{
echo $ancpopup;
}
?>

Don't forget to define your $eid, and then your mysql query.. You don't have to escape single quote if you use double quotes to define your echo. The same is true if single quote is used.. e.g. echo ""; and echo''. However, the echo " $someVariable"; the $someVariable is evaluated by the php parser, but not in sigle quote as in echo '$someVariable'; this will give you $someVariable printed out on the screen.. Alternatively, you can echo $someVariable; without the need of double quote if there is no other text string, html tags, javascript need to be printed or evaluated.

Single quote sample...

$someName = "myName";

echo 'My Name is '.$someName.'<br/>';

This above $someName will get evaluated.., but this one will not

echo 'My Name is $someName <br/>';

Thanks CHeers...It work!!!

If 'something' echos to screen from the code,
and the popup does not popup, are you running, popup blockers.
99% of your potential users are also running some popup blocker, just by default browser install,
show/hide layers containing the information that m_ancpopup.php would display, in the current page may be better, than trying to defeat everyone's security settings
something like

<?php if(mysql_num_rows($result)<>0){
echo "<div id=\"anctrigger\" name=\"anctrigger\"><a href=\"#anctrigger\" onclick=\"document.getelementbyid(\'showme\').display.block);\">Accident &amp; Conviction EXIST!</a></div>
<div id=\'showme\' style=\'display:none;width:670px;height:470px;left:0;top:100px;\'>";

//output of m_ancpopup.php?page=$eid perhaps as include(m_ancpopup.php)

echo "<a href=\"#\" onclick=\"document.getelementbyid(\'showme\').display.none);\"> Close! </a></div>";
} ?>

the alteration in the href and name in anctrigger element should prevent the browser jumping to the top of the page, by keeping focus to the named element onclick href='#' defaults to the top of the age

lousy code, not certain its correct, idea without completion, its not my projuect, just trying to help

You're welcome. Just make sure to mark this as solved.... good thing it all worked out for you..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.