Can anyone see why this line in PHP doesn't work. The game card is deleted, but the confirm box does not appear for the user to okay or cancel.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . " onclick='return confirm('Delete game card?');'>Delete</a>";
Thank you.
You have single quotes inside of single quotes, you need to escape 'em. You also forgot the closing quote on the href attribute.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . "' onclick='return confirm(\"Delete game card?\");'>Delete</a>";
echo "Delete";
codepad example
echo "Delete";
will do it. HTML attributes, as a general practice, should be double quoted. JS strings should be single quoted.
You have some issues with missing quotes and using double quotes when you should be using singles (and vice/versa). This should do the trick.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . "' onclick='return confirm(\"Delete game card?\");'>Delete</a>";
Related
I want to add custom link that is stored in a value inside a php button. How do I do it?
I am trying to get this sorted how ever its not doing it, it just returns nothing or sometimes returns the current page link instead. I am looking towards adding my $lnk to this code in href section.
This is what I have:
echo '<input class="btnnn-class" type=btnnn-class onClick=location.href="" .$lnk value="Contact Buyer">';
Where $lnk is my link inside of it.
Al Fonce told correct answer and described wel
He forget one double quotes after $lnk . '\'
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $lnk . '\'" value="Contact Buyer">' ;
There is several typos in your code : you did not open and/or close quotes when needed. You have too surround your classes with double quotes and your onClick value too. Inside it, the location href is a string too that should be inside quotes.
Both php and javascript allow single and double quotes to delimitate a string, but you should use only double quotes for html attributes.
So:
Use single quotes ' for the whole echo statement (but varaiables are not interpreted inside single quotes),
Use double quotes " for the html attributes.
Use single quotes ' for the javascript value, and escape it (becasue they are inside another php single quoted string).
The code:
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $url . '\'" value="Contact Buyer">' ;
Or use double quotes for php and espace the html attributes ones, the variable will be interpreted:
echo "<input class=\"btnnn-class\" type=\"btnnn-class\" onClick=\"window.location.href=$url\" value=\"Contact Buyer\">" ;
Try this:
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'$lnk\'" value="Contact Buyer">' ;
Because of the quotes, you are facing the problem.
I have this php line which works fine:
echo "<p>" . $post['message']. "</p>";
But I want to change it so it will link to my page (not to a single post). So it should look like that.
echo "<p>" . $post['message']. "</p>";
I have tried a lot many proposition gathered on different website, but each time I am getting an error.
Any idea ?
Thanks a lot!
Using single and double quotes, you avoid escaping issues. Try this:
echo '<p>'. $post['message']. '</p>';
i see that you didn't escaped from double quote that closes href attribute:
echo "<p><a href=\"https://www.facebook.com/rscmovement\" target=\"_blank\">"
I guess You have missed the back slash () before " after www.facebook.com/rscmovement.
"https://www.facebook.com/rscmovement\" "\"target=\"_blank\">" will
I have been using this code for deleting data from database. What i wan is whenever a user clicks an image link to delete data from the confirm function prompts up and ask for action, i am getting error in this code.
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
echo "<a href=".$delurl.";
echo "onclick='return confirm('Are you sure you want to delete.')'>".$img."</a>";
Maybe the error is in double quotes or single quotes, Any help
Thanks in advance
change
echo "<a href=".$delurl.";
to
echo "<a href=\"".$delurl."\" ";
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
$confirm_box <<<CONFIRM
<a href="$delurl"
onclick="return confirm('Are you sure you want to delete?')">$img</a>
CONFIRM;
// then elsewhere ...
echo $confirm_box
Always tend towards using the HEREDOC syntax to construct HTML/JS output, it will save you a lot of heartache. Just watch out for the major gotcha, DO NOT INDENT THE FIRST/LAST lines of the heredoc declaration.
EDIT The benefit being that you can mix single and double quotes as much as you like, you only have to worry about the JS quoting - PHP variables are interpolated without the quotes. You can further wrap curly quotes around your PHP variables like {$this} to make it easier to read, but also to delineate $this and {$this}tle.
I would us the following instead of escaping, this is more readable to me:
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
?>
<?=$img?>
You can, may and should escape when handling stuff like this:
echo "<a href=\".$delurl.\"";
echo " onclick=\"return confirm('Are you sure you want to delete.')\">".$img."</a>";
lg,
flo
I have following PHP echo statement:
echo "<td><a href='delete-news.php?deleteID=".$id." onclick='return confirm('Really delete?');'>Delete</a></td>";
which is convert to html as:
<td class="last-td nth-8"><a delete?');'="" confirm('really="" return="" href="delete-news.php?deleteID=5 onclick=">Delete</a></td>
As you can see something has gone wrong?
What is the problem? I have already tried swaping " " for single ' '.
Your have double single quotes in the onclick statement, try confirm(\'Really delete?\') instead.
You have forgot ' after href. Use it like
Double quotes:
echo "<td>Delete</td>";
Single quotes:
echo '<td>Delete</td>';
You have href not closed. Also, your 'Really delete' cause trouble too. Try this
echo "<td><a href='delete-news.php?deleteID=$id' onclick='return confirm(\"Really delete?\");'>Delete</a></td>";
I have this PHP code
echo 'Link 1';
which generates a link like this:
Link 1<li>Link 2</li>
Causing the javascript to not be called. How would I make it generate single quotes around the result of $query, in this case ed hardy?
You should html encode it:
echo 'Link 1';
You could also use htmlspecialchars
echo "<a href='#' onclick='updateByQuery(\"Layer3\", \"" . json_encode($query) . "\");'>Link 1</a>";
This produces:
<a href='#' onclick='updateByQuery("Layer3", "Ed Hardy");'>Link 1</a>
Try to do the reverse... use single quotes for html, and double quotes for javascript. That's how we do that in fact.
echo "<a href='#' onclick='updateByQuery(\"Layer3\", " . json_encode($query) . ");'>Link 1</a>";
Quotes are a problem with inline handlers. As RoBerg says, you need to use htmlentities in the text.
Another way around it is to use hook methods and anonymous functions, rather than inline handlers.
echo '
Link 1
<script>document.getElementById("link_1").onclick =
function() { updateByQuery("Layer3", '.json_encode($query).'); }
</script>
';