How can i display form data in echo php? [duplicate] - php

This question already has answers here:
How to echo php code inside html which is inside php code in this situation? [duplicate]
(2 answers)
Closed 7 years ago.
How can i display form data in echo php ?
My code is:
<?php
echo "<td align='center' style='vertical-align:middle;'> Bust:
<?php
echo $_POST["bust"];
?>
<br> Waist:
<?php
echo $_POST["waist"];
?>
<br> </td>";
?>
But this doesn't work, please guide me with correct steps.

There are a lot of problems with your code.
You're using " in $_POST["bust"] but you opened echo with " as well, causing a conflict.
You're using <?php instead an echo... which is already PHP. There's no need to do this.
It is best to isolate variable printing from your code. Use string concatenation with . as such:
echo "<td align='center' style='vertical-align:middle;'> Bust: ".$_POST["bust"]."<br> Waist: ".$_POST["waist"]."<br> </td>";

Related

Echo value from MYSQL Database to url [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I have a table that draws information from my MYSQL database. I have a button that I want to echo the id of the row of the information I draw. I can echo all the information to the table but for some reason no idea how to get the information into the URL
I want to use it in the next page in the GET function for additional data being drawn
echo "<td> <a href='dashboard.php?id="<php echo[id], ?>"'><button>Next</button></a> </td>";
I am receiving this error:
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in
The unexpected Echo they referring to I think is the second one as the first echo on previous rows in my table I have no issues
Update:
I have this sql string:
$sql = "SELECT * FROM new_case WHERE status = 'Active'";
In the table I have one row as below and it shows the id of that row.
echo "<td>" . $row['id'] . "</td>";
You made mistake here <php echo[id], ?>
you are already inside PHP, so dont use <?php ?>
also echo[id] is not valid, PHP variable start with $
So replace your line with below line.
echo "<td> <a href='dashboard.php?id=".$row['id']."'><button>Next</button></a> </td>";
It seems there is a typo at the echo function, the syntax of the echo function is echo <string> you can see it in the documentation.
So calling echo[id] is invalid syntax, it expects a string of some sorts (this can be a variable too, as long as it implements a __toString function).
A right way to call it would be like echo "<td><a href='dashboard.php?id=$id'"... when you use double quotes PHP will try to interpit the quote and parse any variables written inside of it.
However, it is important to know that is is a security risk to directly output database information into an URL.
Please use below code
echo "<td> <a href='dashboard.php?id=".$id."'><button>Next</button></a> </td>";
instead of
echo "<td> <a href='dashboard.php?id="<php echo[id], ?>"'><button>Next</button></a> </td>";

How to use link (href) in specific part at php echo? [duplicate]

This question already has answers here:
Add PHP variable inside echo statement as href link address?
(8 answers)
Closed 3 years ago.
I want to make underline at specific part using href in php.
Please help..
Here is my code..
echo "Welcome " . $row1['name'] . "Sir ";
//I want to make underline only this part: $row1['name'];
You can actually put anchor tag directly inside your php echo
echo "Welcome <a href='#yourlink'>" . $row1['name'] . "</a> Sir ";
<?php
echo " Welcome <a href='hyperlink'>" . $row1['name'] . "</a> Sir ";
?>
This will work, without any flow

Echo php variable inside of p tag, returns outside of the p tag [duplicate]

This question already has an answer here:
Order of output changes in php echo
(1 answer)
Closed 4 years ago.
I am using WordPress and I thought this advanced custom field would output the_field('price') inside of the p tag however it output's it before the p tag and not inside it. Thanks ahead of time.
<?php
echo "<p> Tickets Start at CA$" . the_field('price') . "</p>";
?>
This is what it looks like in html
How about:
<?php
echo "<p> Tickets Start at CA$" . get_field('price') . "</p>";
?>
The reason why you might be having issues is because the_field() prints the value using echo, so the code sample in your question ends up being equivalent to this:
<?php
echo "<p> Tickets Start at CA$" . echo get_field('price') . "</p>";
?>
Reference: https://www.advancedcustomfields.com/resources/the_field/#overview
Can you try
<p> Tickets Start at CA$ <?=the_field('price') ?></p>

How do I echo a <a> tag which has an href that is using php echo base_url() [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 7 years ago.
Hi I am trying to produce a <td> which also contains an <a> link which will redirect to a function in my controller which also echos the id of my data. Here is my code so far:
<?php
if ($this->session->userdata("username")==$info->U_username) {
echo '<td>EDIT</td>';
}
?>
This code produces an error Disallowed Key characters. Any help or comment is highly appreciated.
For concatenating strings PHP has . operator.
echo '<td>EDIT</td>';
You need to add the result of base_url() to the string you want to output, e.g.:
echo '<td>EDIT</td>';
Either you need to concatinate instead to use php multiple time .use like this
<?php
if ($this->session->userdata("username")==$info->U_username){
echo "<td><a href='".base_url()."'/gamestalker/edit_content/'".$info->C_id."'>EDIT</a></td>";
}
?>
or don't include html into php tags like this
<?php
if ($this->session->userdata("username")==$info->U_username){ ?
<td>EDIT</td>
<? }
?>
You need string concatenation. In PHP you use . for that.
Also codeigniter's base_url can take an argument:
<?php
if ($this->session->userdata("username")==$info->U_username){
echo '<td>EDIT</td>';
}
?>

Display link as hyperlink enabled output from mysql in php page but I am getting error [duplicate]

This question already has answers here:
Print string with a php variable in it
(4 answers)
Closed 11 months ago.
If I execute this I am getting output properly:
echo "'.$elink.'";
but when I want to display my output in a table column format I am not able to insert:
echo "<td width='200'>" '.$elink.' "</td>";
or
echo "<td width='200'>" "'.$elink.'" "</td>";
or
echo "<td width='200'>" ''.$elink.' "</td>";
Please correct the syntax errors.
echo '<td width="200">' . ''.$elink.'</td>';
Looks like you have mismatched quotes. But I would use sprintf.
echo sprintf("<td width='200'><a href='%1$s'>%1$s</a></td>", $elink);
First off you quotes are messed up. They should look like this:
echo "<td width='200'> <a href='".$elink."'>".$elink."</a></td>";
Correct your string format
echo '<td width="200">' . $elink . '</td>';
I suggest you to use the attribute style (style="width:200px;") instead the width attribute.
Remember to Url Encode the parameters contained in the href attribute.

Categories