Confused about PHP syntax error [closed] - php

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.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am following video tutorials on the Internet, and this is one of them. However, I am getting a syntax error and can't find where it is.
<?php
function hesapla($ilktarih,$sontarih){
$yil=$son-$ilk;
$ay=$yil*12;
$gun=$ay*30;
return array("$ilktarih","$sontarih","$yil","$ay","$gun");
}
$ilktarih=$_POST["ilk"];
$sontarih=$_POST["ikinci"];
hesapla($ilktarih,$sontarih);
list ("$ilktarih","$sontarih",$yil,$ay,$gun)=hesapla($ilktarih,$sontarih);
?>

Remove double quotes from list variables like this :
<?php
function hesapla($ilktarih,$sontarih){
$yil=$son-$ilk;
$ay=$yil*12;
$gun=$ay*30;
return array("$ilktarih","$sontarih","$yil","$ay","$gun");
}
$ilktarih=$_POST["ilk"];
$sontarih=$_POST["ikinci"];
hesapla($ilktarih,$sontarih);
list ($ilktarih,$sontarih,$yil,$ay,$gun)=hesapla($ilktarih,$sontarih);
?>

Related

Include path with constant and variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 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'm trying to include a file to current php page but the name of the file depens on the lang.
This line does not work:
include_once PATH.'lang/'.$_SESSION['lang'].'.php';
How can I achieve that?
Your problem should be the "PATH". It must be a string to concatenate with the other strings. For example:
include_once '/sites/all/files/'.'lang/'.$_SESSION['lang'].'.php';
Also be careful with the slashes that make your path to the file.

What is the "returnto" in this piece of code [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 7 years ago.
Improve this question
header("Location: {$TBDEV['baseurl']}/login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]));
Is it a variable? PHP reserved word? something to do with HTML?
It's a $_GET parameter. When you submit the code, the page receiving it will be able to use $_GET['returnto'] to return you to the page you're currently on.
Take some time to learn about $_GET

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>";

Where's my issue here? (PHP/PDO) - User exist [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
trying to check whether a user exists or not via pdo
$wantedusrnm = $_POST['new-usrnm'];
$userExist1 = "SELECT * FROM users WHERE username=:wantedusrnm";
$userExist = $handler->prepare($userExist1);
$userExist->execute(array(':username' => $wantedusrnm));
$userExist = ($userExist->rowCount());
for some reason it errors, dunno why, any reasons?
Change:
$userExist->execute(array(':username' => $wantedusrnm));
To:
$userExist->execute(array(':wantedusrnm' => $wantedusrnm));
Because, in your query you've got :wantedusrnm but in your execution array you've got :username.

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";

Categories