The onclick='return confirm('Delete this comment?')' seems to be not working at all:
<?php
if($sesType == 'Admin') {
echo "<a href = 'editCom.php?id=$commentID'>Edit</a> ";
echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
} else if($_SESSION["username"] != NULL AND $_SESSION["username"] == $postname) {
echo "<a href = 'editCom.php?id=$commentID'>Edit</a> ";
echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
}
?>
But the confirmation box does not appear.
You're using single quotes inside of single quotes. Use double quotes to wrap your code instead:
Link
Just change this code, and it will work.
echo "Delete";
You have misused the single quote and double quotes. You have to put slash () on quotes to escape. The html should look like this:
Link
Take note that single quote should be inserted inside the double quotes ""
from your code:
echo " <a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
It should be:
echo "Delete";
Related
I am sorry if this is duplicated but I could not find an answer to this situation. I am trying to escape the double quotes from the inline style in the PHP code.
<?php if (isset($ioTitle)){
echo "<div style='background-color: echo $params->get('colorbgt'); ;' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
echo $params->get("ioTitle"); echo "</h3></div>";
}
You can't put echo inside a string and expect it to be executed. You need to use concatenation.
echo "<div style='background-color: " . $params->get('colorbgt') . ";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
You don't need to escape anything in the style for this. Also, you can use single quotes around the classes, to avoid those escapes.
echo "<div style='background-color: " . $params->get('colorbgt') . ";' class='ioTitleBox'><h3 class='ioTitle'>";
<?php if (isset($ioTitle)){
echo "<div style='background-color:". $params->get('colorbgt').";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
echo $params->get("ioTitle"); echo "</h3></div>";
}
Is this how you want it?
You are echo-ing from inside an echo, you just need to concatenate that part into the existing echo statement.
I am a little new to PHP. What I am trying to do is to display the username that is logged in with a link to their home page. This is what I have.
if (loggedin()) {
echo ' $user->get_fullname($uid) ' ;
echo ' Log Out ';
}
But as you can see it will not display the username, it will display what I have in between the link. I do not know where to go from here.
you want:
if(loggedin()){
echo ''. $user->get_fullname($uid) .'' ;
echo ' Log Out ';
}
else {
?>
in php single quotes will not parse a variable. An alternative syntax is:
echo "<a href ='HomePage.php'> $user->get_fullname($uid) </a>" ;
This is because variables are interpreted inside of double quotes, not single quotes. There are many ways to fix this such as bringing the variable outside of the single quotes as in:
echo ''. $user->get_fullname($uid). '';
or to replace the single quotes with double quotes and vice-versa, and because it is a complex variable you will need to use braces:
echo "<a href ='HomePage.php'>{$user->get_fullname($uid)}</a>";
Use double quotes all throughout and escape the inner quotes:
echo "{$user->get_fullname($uid)}";
And lastly, my favourite way if I have a lot of HTML code is to use HEREDOC syntax:
if(loggedin()){
echo <<<HTML
{$user->get_fullname($uid)}
Log Out
HTML;
}
?>
Note: When using HEREDOC notation, you cannot put anything after the HEREDOC opening variable (not even space) and nothing else (not even space) on the closing HEREDOC line. That is why the closing HTML; is not indented here as no space is allowed before it.
You have to end the string with the quote and continue it to the php variable with the . operator. You concatenate strings with php variables using the .
if(loggedin()){
echo ''. $user->get_fullname($uid) .'' ;
echo ' Log Out ';
}
else {
//do something else
}
if(loggedin()){
$userName = $user->get_fullname($uid);
if($userName == NULL) $userName = 'USER';
if(loggedin()){
echo "<a href ='HomePage.php'>".$userName."</a>";
echo " || <a href='logout.php'> Log Out </a>";
}else{
//if any other then you can...
}
If you want to display some variables in php it should not be enclosed in quotes but if you want a string to display you want it to be inside quotes. So in your case you have both so you must use something called concatenation, For which you use dot(.)[ In case of javascript you use plus(+) for concatenation].
So your code must be like
if(loggedin()){
echo ''. $user->get_fullname($uid) .'' ;
echo ' Log Out ';
}
else {
I have a php program which is suppose to alert the links clicked.For example I have a link hello and when I click on that link javascript should alert hello. It works fine without spaces, but when I have a link like hello world it does not alert anything.These words are extracted form a database.
My code is given below
function gmail(val)
{
alert(val);
}
For php
<?php
$name="raj"; //this is just a dummy value
$include "database_connectivity.php";
$conn=odbc_connect($dsn,$database_username,$database_password);
if(!$conn)
{
die('Could not connect to database.'.odbc_error());
}
$select="SELECT WHERE_TO_CHANGE FROM REQUEST_SEND_TABLE WHERE SENT_FROM ='$name'";
$exe=odbc_exec($conn, $select);
if(!$exe)
{
die("Could not execute query".odbc_error());
}
while($row_user=odbc_fetch_array($exe))
{
$show=$row_user['WHERE_TO_CHANGE'];
echo "<input type='hidden' id='".$show."' value='".$show."'>";
echo "<a href='#' id='check' onClick='gmail(".$show.".value)' >".$show." </a>";
echo"<br>";
}
odbc_close($conn);
?>
Can anyone tell me whats wrong here ?
while($row_user=odbc_fetch_array($exe))
{
$show=$row_user['WHERE_TO_CHANGE'];
$show_nospace = str_replace(' ', '_', $show);
echo "<input type='hidden' id='".$show_nospace."' value='".$show."'>";
echo "<a href='#' id='check' onClick='gmail(".$show_nospace.".value)' >".$show." </a>";
echo"<br>";
}
And if $show can contain other characters that aren't allowed in IDs, you'll need to replace them as well. You'll also need to escape any quotes when using it in the value attribute.
in your onclick event, change it to this:
gmail(document.getElementById($show).value)
it might be better to do that in your function though and just pass in the id:
gmail($show)
That way you can check the existence of the element first before trying to call .value on it.
Use quotes when ever there is a space
onClick="gmail('".$show_nospace.".value');"
see the single quotes ('test test')
Try this:
echo "<input type='hidden' id='".$show."' value='".$show."'>";
echo "<a href='#' id='check' onClick='gmail(".$show.")' >".$show."</a>";
instead of:
echo "<input type='hidden' id='".$show."' value='".$show."'>";
echo "<a href='#' id='check' onClick='gmail(".$show.".value)' >".$show."</a>";
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 am building some html in a php script in order to send it back to a page via Ajax.
$other_content = Model_Db::dbSelect($query);
$div_center .= "<table>";
for($i = 0;$i<sizeof($other_content);$i++) {
$div_center .= "<tr>";
$div_center .= "<td><a href='#' onclick='changediv('test','0')'>".$other_content[$i]->content_name."</a></td>";
$temp = "<td><a href='#' onclick='changediv('test','0')'>".$other_content[$i]->content_name."</a></td>";
die($temp);
$div_center .= "</tr>";
}
$div_center .= "</table>";
As you can see I am doing a die() to see the created string.
My ouput should be something like: <a href="#" onclick="changediv(" test','0')'>Content Name</a>
But instead I get: Content Name
I do not understand where this ="" comes from after my onclick declaration...
Can anybody see what's wrong here? I am a bit puzzled as I really don't see where it could come from!
Cheers
I would suggest you to escape the quote characters
$temp = "<td><a href=\"#\" onclick=\"changediv('test', '0')\">" .
$other_content[$i]->content_name. "</a></td>";
The \" escapes the double quoute in a string
You messed up the function interpretation of single-quote marks as double-quotes:
yours <a href='#' onclick='changediv('test','0')'>
func <a href="#" onclick="changediv(" test','0')'="">
It assumes this (between % signs) %test','0')'=""% is a parameter of your tag, try substituting single-quotes with double-quotes and make it html/xhtml compliant:
<a href="#" onclick="changediv('test','0')">
So single-quotes and double-quotes will be correctly set.
You have to change PHP quotes too