<?php while($result = mysql_fetch_array( $resulta )) {
echo "<tr>";
echo "\t\t<td>{$result['denumire_locatie']}</td>\n";
echo "\t\t<td>{$result['tip_locatie']}</td>\n";
echo "\t\t<td>{$result['judet']}</td>\n";
echo "\t\t<td>{$result['localitate']}</td>\n";
echo "\t\t<td>{$result['strada']}</td>\n";
echo "\t\t<td>{$result['numar']}</td>\n";
echo "\t\t<td>{$result['telefon']}</td>\n";
echo "\t\t<td>{$result['fax']}</td>\n";
echo "\t\t<td>{$result['email']}</td>\n";
echo "\t\t<td>{$result['descriere']}</td>\n";
echo "\t\t<td>click pentru detalii</td>\n";
echo "</tr>";
}
When I run I get the following error message:
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\SITE\index.php on line 157
Line 157 is the following one:
echo "\t\t<td>click pentru detalii</td>\n";
Can anyone see the problem?
You are trying to use double quotes wrapped by double quotes...when you get this situation either alternate single and double quotes or escape the inner quotes with \ like \".
But escaping is the better choice in IMHO, when you want to maintain
consistency while writing the attributes of html tags.
Either:
echo "\t\t<td>click pentru detalii</td>\n";
Or
echo "\t\t<td><a href='/oferta.php?id={$result['id_oferta']}'>click pentru detalii</a></td>\n";
Changed code:
<?php while($result = mysql_fetch_array( $resulta ))
{
echo "<tr>";
echo "\t\t<td>{$result['denumire_locatie']}</td>\n";
echo "\t\t<td>{$result['tip_locatie']}</td>\n";
echo "\t\t<td>{$result['judet']}</td>\n";
echo "\t\t<td>{$result['localitate']}</td>\n";
echo "\t\t<td>{$result['strada']}</td>\n";
echo "\t\t<td>{$result['numar']}</td>\n";
echo "\t\t<td>{$result['telefon']}</td>\n";
echo "\t\t<td>{$result['fax']}</td>\n";
echo "\t\t<td>{$result['email']}</td>\n";
echo "\t\t<td>{$result['descriere']}</td>\n";
echo "\t\t<td>click pentru detalii</td>\n";
echo "</tr>";
}
echo "</table>";
In this line the double quotes end your echo string.
echo "\t\t<td>click pentru detalii</td>\n";
^
To avoid (escape) this behavior put a backslash infront of it
echo "\t\t<td>click pentru detalii</td>\n";
^ ^
echo "\t\t<td><a href="
^ end of string
Replace with:
echo "\t\t<td>click pentru detalii</td>\n";
You have to escape the " as you use it as delimiter.
Try this:
echo "\t\t<td>click pentru detalii</td>\n";
You have to escape your " so PHP won't get confused... .
Related
Hi guys i'm trying to output my database values in a datalist
this is my code
my query works:
but my datalist is empty
Your syntax is incorrect:
echo "<input id="numero" list="posti1" >
<datalist id="posti1" >";
Should be:
echo '<input id="numero" list="posti1" >
<datalist id="posti1">';
Because you have double quotes in the string, you can use single quotes to contain it.
Try
echo "<input id='numero' list='posti1' ><datalist id='posti1'>";
instead of
echo "<input id="numero" list="posti1" ><datalist id="posti1" >";
If you want to use double quotes inside the double quotes then you need to use slash (\) before the double quote
i.e,
echo "<input id=\"numero\" list=\"posti1\" ><datalist id=\"posti1\">";
That is not only error you having on your script when you done fixing that error you gonna get another error:
bellow are the errors you have:
echo "<input id="numero" list="posti1" >
<datalist id="posti1" >";
echo "<option value="$row[numero]"/>"; // Format for adding options
They should look like this:
echo "<input id=\"numero\" list=\"posti1\">
<datalist id=\"posti1\">";
echo "<option value=\"".$row['numero']."\"/>"; // Format for adding options.
Therefore your full code should be:
<?php
session_start();
$conn = oci_connect('insidedba', 'progetto16', 'localhost/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
echo "<input id=\"numero\" list=\"posti1\">
<datalist id=\"posti1\">";
$sql = oci_parse($conn, "SELECT NUMERO FROM POSTI WHERE PRENOTAZIONE=NULL");
oci_execute($sql);
foreach ($dbo->query($sql) as $row) {
echo "<option value=\"" . $row['numero'] . "\"/>"; // Format for adding options
}
echo "</datalist>";
?>
NB: When you have a double quotes inside double quotes, you will need escape characters.
Some common php escape characters.
\" -Print the next character as a double quote, not a string closer
\' - Print the next character as a single quote, not a string closer
\n- Print a new line character
\t -Print a tab character
\$ -Print the next character as a dollar, not as part of a variable
\ -Print the next character as a backslash, not an escape character
echo "<input id=" numero "list=" posti1 "><datalist id=" posti1 " >";
when php try to read your code line , It sees it as above. it thinks only highlighted words are strings and specially those strings aren't connected by a .dot it throws the syntax error .
best way to fix this is as to do it according to the above answers .,
echo '<input id="numero" list="posti1" > <datalist id="posti1">';
Im trying to pass a variable in the URL and to post the variable on the page. I currently have a table and a variable named $record['Filename']. The value is not displaying correctly.
Right now I have the following
while($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" ."<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>". " </td>";
echo "<td>" . $record['Description'] . "</td>";
echo "</tr>";
}
PHP strings 101:
echo "<td>" ."<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>". " </td>";
^--start string end string --^
Since you never "exit" your "-quoted strings, your . are just plaintext periods, not concatenation operators.
You probably want this:
echo <<<EOL
<td>{$record['Filename']}</td>
EOL;
Notice how using a heredoc removes the need to hop in/out of string mode, and you can use proper quoting in the HTML. Also note the {}-extended string syntax around the variables.
try to change,
<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>
to
<?php echo $record['Filename'];?>
Use single quotes instead of double quotes. It's faster and more efficient.
while($record = mysql_fetch_array($mydata)){
echo '<tr>';
echo '<td>'.$record['Filename'].'</td>';
echo '<td>'. $record['Description'].'</td>';
echo '</tr>';
}
I want to echo these two strings. This is my current code:
echo str_replace(array_keys($swears), array_values($swears), $main).<br />;
echo str_replace(array_keys($swears), array_values($swears), $post).<br />;
But it produces this error:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\new\new.php
Please let me know your feedback.
Use this instead since you have to use quotes for displaying HTML tags:
echo str_replace(array_keys($swears), array_values($swears), $main)."<br />";
echo str_replace(array_keys($swears), array_values($swears), $post)."<br />";
echo str_replace(array_keys($swears), array_values($swears), $main) . '<br />';
Ths is a string, so it has to be quoted.
echo str_replace(array_keys($swears), array_values($swears), $main). '<br />';
I am trying to print a variable between curly braces as
Product_number{product_version}
I tried
echo "$product_number{$product_version}";
But that does not work. I don't understand why :(
try using double braces:
echo "$product_number{{$product_version}}";
You can also do:
echo "$product_number{".$product_version."}";
{ followed by $ is treated specially. It is mainly used when you want to append a string immediately at the end of a variable's value:
$v = 'hack';
echo "I {$v}ed it";
echo $product_number . "{" . $product_version . "}";
Escape the "{":
echo "$product_number\{$product_version}";
How can i echo " i mean if i want to show: "Patrik", i would do:
<?php echo " "Patrik" "; ?>
but as you know you cant do this
Escape double quotes with \ when full string itself is in double quotes:
<?php echo " \"Patrik\" "; ?>
Or:
<?php echo ' "Patrik" '; ?>
More Info:
PHP: Double quotes vs Single quotes
http://pt.php.net/manual/en/language.types.string.php
<?php echo '"Patrik"'; ?> or.. <?php echo "\"Patrik\""; ?>
<?
echo " \"Patrik\" ";
// or
echo '"Patrick"';
?>
if it's HTML or XML, you can use " as substitute for the double-quote.