Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PHP to load Javascript
    primarykey
    data
    text
    <p><strong>EDIT: My function was broken, with the <code>/n</code> in it. Thanks woofmeow for leading me to question my function!</strong></p> <p>I am new to programming. I have been trying my best and I have learned a lot the past few months (a bunch here!) but I am stumped. </p> <p>I have a PHP script that calls from another PHP script and I cannot get the code to actually run. It used to run, then I changed some things and didn't save the changes, I'm not sure what I did. I know, I know, rookie mistake(I learned from it!). The Javascript shows up fine on view page source but doesn't run anymore.</p> <p>Here is the page source, maybe it is that simple:</p> <pre><code>&lt;script type="text/javascript"&gt; function delete_user(user_id) {if (confirm("Are you sure you want to delete this user?" + "\nThere's really no going back!")) {window.location = "delete_user.php?user_id=" + user_id;}}&lt;/script&gt; </code></pre> <p>Here is the PHP: The show_users script sends this into the viewer:</p> <pre><code>$delete_user_script = &lt;&lt;&lt;EOD function delete_user(user_id) { if (confirm("Are you sure you want to delete this user?" + "\nThere's really no going back!")) { window.location = "delete_user.php?user_id=" + user_id; } } EOD; </code></pre> <p>The PHP in the HTML was NOT changed from when it was working:</p> <pre><code>&lt;?php while ($user = mysql_fetch_array($result)) { $user_row = sprintf("&lt;li&gt;&lt;a href='show_user.php?user_id=%d'&gt;%s %s&lt;/a&gt;(&lt;a href='mailto:%s'&gt;%s&lt;/a&gt;)&lt;a href='javascript:delete_user(%d);'&gt;&lt;img class='delete_user' src='../images/delete.png' width='15' /&gt;&lt;/a&gt;&lt;/li&gt;", $user['user_id'], $user['first_name'], $user['last_name'], $user['email'], $user['email'], $user['user_id']); echo $user_row; } ?&gt; </code></pre> <p>And finally, the viewing script that gives us our page source (Note: $embedded_javascript is $delete_user_script):</p> <pre><code>if (!is_null($embedded_javascript)) { echo '&lt;script type="text/javascript"&gt;' . $embedded_javascript . '&lt;/script&gt;'; } </code></pre> <p>When I mouse over the image to delete the user, it still shows the correct script link ("Javascript:delete_user(%d)", where %d is the user_id) but it's like the function isn't defined anymore, nothing happens. Any ideas are greatly appreciated! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload