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">';
Related
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'm storing text in database like "He can't ...". But when I echo this text, as it is inside HTML markup, browser get's ' as closing of some html element's markup. Which PHP function to use before, to echo safely this type of text inside html markup?
Use htmlentities():
echo "<input type='text' value='" . htmlentities($text, ENT_QUOTES | ENT_HTML401) . "'>";
The ENT_QUOTES flag tells it to convert both single and double quotes to entities (the default is just double quotes).
I have a problem with my page. I am displaying images using PHP Loop statement. Now I want to assign these images with different id's. Example first loop the first image displayed will have an id="img1", next loop and second image has id="img2". Numbers on the id changes based on the loop iteration variable, while "img" is constant. Here's my code:
for ($i=1;$i<=6;$i++){
echo ("<img src='gangjeong.png' width='113' id='img'.$i>");
}
but it's not working. Any help would be much appreciated.
UPDATE: I got it to work now, thanks for the answers. The working code is:
for ($i=1;$i<=6;$i++){
echo ("<img src='gangjeong.png' width='113' id='img$i'>");
}
You can't use unescaped single quotes if you start your string by single quotes.
These are the possibilities you have:
Using double quotes inside single quotes:
for ($i=0;$i<6;$i++){
echo ('<img src="gangjeong.png" width="113" id="img' . ($i+1) . '" />');
}
Using escaped single quotes inside single quotes (ugly):
for ($i=0;$i<6;$i++){
echo ('<img src=\'gangjeong.png\' width=\'113\' id=\'img' . ($i+1) . '\' />');
}
Using double quotes for starting/ending the string:
for ($i=0;$i<6;$i++){
echo ("<img src='gangjeong.png' width='113' id='img" . ($i+1) . "' />");
}
Using escaped double quotes inside double quotes (ugly):
for ($i=0;$i<6;$i++){
echo ("<img src=\"gangjeong.png\" width=\"113\" id=\"img" . ($i+1) . "\" />");
}
Quotes inside quotes are a no no without proper escaping. Also you have a missing > for the img tag. This should do:
for ($i=1;$i<=6;$i++){
echo "<img src='gangjeong.png' width='113' id='img".$i."'>";
}
Where's your escape characters? Your quotes need escaping, or put your HTML part in double quotes and PHP strings in single, or vice versa. Just make sure you're not confusing start and end quotes.
your syntax is not correct, use:
for ($i=1;$i<=6;$i++){
echo '<img src="gangjeong.png" width="113" id="img'.$i.'" alt="">';
}
Use:
for ($i=1;$i<=6;$i++){
echo "<img src=\"gangjeong.png\" width=\"113\" id=\"img$i\">";
}
<?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... .
Hi i have been using this php echo statement
echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."'"."onclick='return
confirm(/Are you sure, you want to delete?/)'>Delete</a>";
The statement is working i am seeing this message /Are you sure, you want to delete?/ instead of this Are you sure, you want to delete?
Your quote nesting is a little messed up. Try to follow these rules:
Outer quote = " (This marks the beginning and end of the string)
Inner quote = \" (Escaped as to not flag "beginning/end of string")
Third-tier quote = ' (Literal quote)
Fourth-tier quote = \' (Literal quote that will be generated as an escaped outer quote)
Result:
echo "<a href=\"message_delete_script_outbox.php?id=".$row['id']."\"onclick=
\"return confirm('Are you sure, you want to delete?')\">Delete</a>";
More info about quote nesting: http://blog.opensourceopportunities.com/2007/10/nested-nested-quotes.html
You enclose the message in quotes, and those quotes need to be escaped to avoid confusing the PHP script:
echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."'"."onclick='return
confirm(\"Are you sure, you want to delete?\")'>Delete</a>";
Just add double quotes and escape them
echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."' onclick='return confirm(\"Are you sure, you want to delete?\")'>Delete</a>";
I am not sure if you added a new line when you posted here, but you should know you cannot have that script on 2 lines.