Calling a PHP variable through button onclick [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
The goal is to call the variable $url when the button is clicked. With this current bit of code, when the button is clicked nothing happens and the error says unexpected token.
<?php
$url = "edit_beginningcakephp.php?title=$title&author=$author&isbn=$isbn
&year=$year&pages=$pages&price=$price";
>?
<input type="button" value="Edit Book" onclick="window.location.href='<?= $url ?>'">

I suppose you're not correctly encoding the content of the variables (known as XSS)
You need to urlencode the content of your variables. Also, & needs to be entered as an HTML entity &.
Try:
$url = 'edit_beginningcakephp.php?title='.urlencode($title).'&author='.urlencode($author).'&isbn='.urlencode($isbn).'&year='.urlencode($year).'&pages='.urlencode($pages).'&price='.urlencode($price);
PS: >?should be ?> and make sure the URL doesn't contain any newlines.

" >? "
That looks like it might be a problem, definitely throws a syntax error on my local :)

While MrTux's answer is very good and his advice should surely be followed, the actual problem with your code is the return in the URL. URLS can't contain returns!
Solution: delete the return. And the spaces. And follow MrTux's advice.

Related

Image Source to Include a PHP Input [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create an image that changes dependent on the genre grabbed from an icecast server, I am pretty sure I have the base code correct I think I've just incorrectly inputted the PHP variable.
<?php
$stats = $core->radioInfo( "http://http://sc.onlyhabbo.net:8124/status-json.xsl" );
?>
<img src=http://www.habbo.com/habbo-imaging/avatarimage?user=<?php
echo $stats['genre'];
?>&action=std&direction=2&head_direction=2&gesture=sml&size=m&img_format=gif/>
is the full code. Have I inputted the PHP variable incorrectly
Where are the quotes in your Html?
<img src="http://www.habbo.com/habbo-imaging/avatarimage?user=<?php
echo $stats['genre'];
?>&action=std&direction=2&head_direction=2&gesture=sml&size=m&img_format=gif"/>
UPDATE EVERYBODY
This is now resolved, I decided to go down the CURL route for this, and at first it didn't work until my host raised our CloudLinux Process Limit. I am unsure what the actual issue with this code was, but the CURL route works fine. Thank you for any answers

Image retrieval from mysql database in php not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am getting an image from mysql database and trying to show it. I am using the following code. But its not working .What's the mistake i am making?
while ($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
$photo=$row['photo'];
$name=$row['firstname'].' '.$row['lastname'];
$email=$row['email'];
echo "<tr><td>".'<img src="data:image/jpeg;base64,<?php echo base64_encode( $photo ); ?>" />'.'</td><td>'.$name.'</td><td>'.$email.'</td></tr>';
}
Strip the double quotes after img src because you have already used a single quote before and it is being taken a string so remove double quotes
Ok thanks. I could solve the problem. I just changed the echo line as following
echo "<tr><td>".'<img src="data:image/jpeg;base64,'.base64_encode($photo).'" alt="photo">'."</td><td>".$name."</td><td>".$email."</td></tr>";

PHP use a variable in a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I hava a problem at my PHP script!
I want to do something like
echo "hello $var";
And the output should be "hello $var". So it should not take the value of $var, but a string "$var".
I want to use this to create a php file with a php script...
Is there any way to solve this?
Thanks in advance!
Use single quotes:
echo 'hello $var';
Or escape the $:
echo "hello \$var";

Login Functionality not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
So I took the login script demonstrated in this tutorial: http://www.9lessons.info/2014/07/ajax-php-login-page.html
However, when I try to run it, I keep getting an incorrect login information error. The database, the table, all of that is correct. I'll look at it again, but I'm sure that's fine.
I haven't changed anything besides the name of the table, and my db info.
Why does the PHP dissapear? Solved
the php at the top of index.php goes away when I look at the source code on a browser
This is a good thing :)
PHP code is processed server-side. The result of that code (which is usually HTML) is then sent to the browser. PHP code itself should never be sent to the browser for a couple of reasons:
It would expose your server-side code to users, which could help them do malicious things.
The browser wouldn't know what to do with it.

How to echo url and database variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have a piece of code used to search a database for videos based on keywords. It then pulls the url from column $url. I then want to echo out a hyperlink to the video by echoing the website link and concatenating on the url variable pulled from the database.
So far I've come up with the following code. I'm new to php so im not sure how to concatenate variables in an echo.
echo "Link";
Also when I run this code the link brings me to http://danu6.it.nuigalway.ie/sm4business/danu6.it.nuigalway.ie/sm4business
Any help or resource that could help me to fix this would be appreciated.
You need to use dot to concate constant string with variables:
echo ''.$name.'';
for security reason you need to take care about propper variable escaping. Check php.net doc for htmlspecialchars and htmlentities
you can try something like this:
echo "Link";
or you can concat the $url value in the string like this:
echo "Link";
Hope it helps!

Categories