I am having an issue when I try to post the Join Date on my web page:
Fatal error: Class 'getJoinDate' not found in ********
$newDate = getJoinDate::createFromFormat("l dS F Y", $dateFromDB);
$posts = PostQuery::create()->findPk(1);
echo "<p>", "ID:".$posts->getUserID().", ".$posts->getContent().", ".$posts->getJoinDate()." </p>";'
Please let me know what I must do to display the format.
It's this code:
echo "<p>", "ID:".$posts->getUserID().", ".$posts->getContent().", ".$posts->getJoinDate()." </p>";'
I'm not sure what your commas were supposed to be, but I guess not actual commas and so you have commas where stops should be: echo "<p>", <--
And an apostrophe at the end of the line: </p>";'<--
You should grab a decent IDE that will show errors like this immediately, saves a lot of time. And read your error log as it tells you such errors.
Using double quotes variable names will be expanded, try this:
echo "<p>ID: {$posts->getUserID()} {$posts->getContent()} {$posts->getJoinDate()}</p>";
Or this way:
echo '<p>ID: ' . $posts->getUserID() . ' ' . $posts->getContent() . ' ' . $posts->getJoinDate() . '</p>';
Related
I'm using the echo command in PHP, but I want to enter PHP code like <?php echo $variable [id_login]?>, while echoing something else out, but this does not work.
Is this possible to do, and if so, how would I do it?
echo "<script>location='member.php?&id=<?php echo $taruh[id_login] ?></script>";
You cannot use echo or open/cloce php twice like you did, you might want to try something like the line below,
echo '<script>location=member.php?id=' . $taruh[id_login] . '</script>';
after echo you can write enything you'd like, even if it's a php variable, just use single quote and dot where you need it (like I do here), as you can see, echo is only used once..
For example:
<?php
$your_variable = 'some text';
$other_variable = 'some PHP code';
echo 'I wrote: ' . $your_variable . ' and ' . $other_variable . '!';
?>
Output will be:
I wrote: some text and some PHP code!
I hope this will bring you into the right direction..
EDIT
Also important: if you use query string in URLs, the first 1 can be a ? every other part after should be a & for example see the url below
http://www.example.com/index.php?id=12345&coder=yes&country=usa
before id I used a quest sign, for all others I didn't use the quest sign...
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'm using fwrite() to write a file, however, every time it runs, it prints all of the information to the webpage it's on and writes to the file, too. I'd rather it not echo it to the page.
Alright, I've retrieved the code. Here it is:
fwrite($data_file, "Confirmation Data: \r\n\r\n Song: " . $input_song . "\r\nFile1: " . $file_var1 . "\r\nFile2: " . $file_var2 . "\r\nFile3: " . $file_var3 . "\r\nFile4: " . $file_var4 . "\r\nExplanation Text: " . $input_explanation);
Whenever I run this, it outputs everything in the second place of fwrite() onto the page, so it outputs the follow onto the page, except with the variables replaced for their values:
Confirmation Data: \r\n\r\n Song: " . $input_song . "\r\nFile1: " . $file_var1 . "\r\nFile2: " . $file_var2 . "\r\nFile3: " . $file_var3 . "\r\nFile4: " . $file_var4 . "\r\nExplanation Text: " . $input_explanation
You should post your code, so we can follow it but most probably you are also echoing out the code as HTML in your PHP file and this is why it prints out on the screen.
You said your information is being echoed and not written to file. Perhaps you are using echo instead of using file related functions. However, without access to your code, I can only post how to write information to a file in PHP:
<?php
error_reporting(E_ALL);//display all errors
ini_set('display_errors', true);
$filename = "testfile.txt";//the name of your output file
$fh = fopen($myFile, 'w');//create a filehandler - fh) and open the file in write mode
$string = "ABCDEFGH\n";//test string to write to the file
$myvar = fwrite($fh, $string);
$string = "IJKLMNO\n";//update the string variable with new data
fwrite($fh, $string);//write more data - can be repeated ad -infinitum
fclose($fh);//finally, close the file
But, if you truly want definitive answers, post your code so that we may be able to help you.
I have a php code where I am generating javascript using php
function FunJavaScriptRedirection($url)
{
echo "<script>";
echo "var x = ";
echo $url';';
echo "window.open(x)";
echo "</script>";
}
My problem is I want semicolon after storing value to variable x .I dont know how to do that I am getting javascript error please help me out .
Even when you get the concatenation right, your code will still not do what you want as you are outputting "x" I stead of the value of the variable.
So after fixing the concatenation
echo $url . ';';
You need to change the following line:
echo 'window.open(' . x . ');';
And I suspect you should declare the language used inside the script tag...
Change
echo $url';';
to
echo $url . ';';
See Contactenation.
You are missing a point between $url and ';'.
I'm trying to get the caption part of my slider to link to the respective article url on my wordpress site. I'm pretty sure I found the section in the plugin code I think needs to be edited, but when I try to do the following:
<?php
echo "<div id='" . $sl_caption . "' class='nivo-html-caption'>" . $sl_htmlcaption . onclick="location.href='$url';"</div>";
?>
I get "syntax error, unexpected T_STRING, expecting ',' or ';" showing up in my slider, and the rest of my site not working. I've tried many variations of what I've tried to do here, but I can't seem to find one that works.
Here's the original entire slider code if it's helpful: http://pastebin.com/4nKxXkSa
Your opening/closing of double-quotes is wrong : in PHP, strings must be enclosed in either quotes or double-quotes ; and if you want to put a double-quote in a double-quotes enclosed string, you have to escape it with a \.
For example, you need to open a quote or double-quote before onclick, as this is part of a string.
Also, your onclick should be inside the <div ...> tag, and not between <div> and </div>.
In the end, your PHP code would look a bit like this (I've set up hard-coded values for the variables, to help with testing) :
$sl_caption = 'ID';
$sl_htmlcaption = 'HTML';
$url = "URL";
echo "<div id='"
. $sl_caption
. "' class='nivo-html-caption' onclick=\"location.href='$url'\">"
. $sl_htmlcaption
. "</div>"
;
And you'd get the following HTML as output :
<div id='ID' class='nivo-html-caption' onclick="location.href='URL'" >HTML</div>
Your string quotes are not correctly placed. Try this
echo "<div id='" . $sl_caption . "' class='nivo-html-caption'>" . $sl_htmlcaption . "onclick=\"location.href='$url';\"</div>";
The problem is what it says - "onclick" isn't a quoted string in your example (T_STRING in PHP). Everything you join together (concatenate) in a string needs to be either a) a string in quotes (single or double), b) something that can be converted to a string or c) a variable/constant/function call.
If you didn't have that error then your current example would also have the "onclick" as the content of the tag, rather than an attribute on the tag. What I think you want is:
<?php
echo "<div id='" . $sl_caption . "' class='nivo-html-caption' onclick='location.href=\'" . $url . "\''>" . $sl_htmlcaption . "</div>";
?>
If you want standard HTML attributes then you'd normally use double-quotes, which would give you:
<?php
echo '<div id="' . $sl_caption . '" class="nivo-html-caption" onclick="location.href=' . $url . '">' . $sl_htmlcaption . '</div>';
?>
Also, is there any reason why you're using an onclick to set the current location rather than a normal <a href>?
the qoute isn't the only problem. The onclick is also out of the div element's properties. It must be (changes the doubles for singles to make it more clear):
echo '<div id="' . $sl_caption . '" class="nivo-html-caption" onclick="location.href=' . $url . ';">' . $sl_htmlcaption . '</div>';
Your quotes are the problem. It should be:
echo "<div id='" . $sl_caption . "' class='nivo-html-caption'>" . $sl_htmlcaption . "onclick=\"location.href='$url';\"</div>";
You needed double quotes to start the string again after the concatenation operator (.), but then you need to escape the double quotes inside this string wit a blackslash so the PHP interpreter won't think the string has ended too soon.
And as Pascal pointed out, the onclick attribute should actually be inside the stating div tag anyway:
echo "<div id='" . $sl_caption . "' class='nivo-html-caption'onclick=\"location.href='$url';\">" . $sl_htmlcaption . </div>";
Using interpolation may make things easier for you also. When using double quotes to delimit a string you can insert variables' values using curly brackets ({}) like this:
echo "<div id='{$sl_caption}' class='nivo-html-caption'onclick=\"location.href='{$url}';\">{$sl_htmlcaption}</div>";
This way you only have to open and close the string once (at the beginning and end).
Beware:
You cannot interpolate function calls directly. You can either concatenate like "<p>".strlen($x)."</p>" or store the result in a variable and the interpolate like before; "<p>{$result}</p>".
You'll still have to escape double quotes within the string though.