PHP misreads quotes in HTML string
PHP hangs after that first echo statement because the last quote there is the first one it sees. As a result, my query doesn't get executed. What's going on?
<html>
<head><title>New.</title>
</head>
<body>
开发者_JS百科 <?php
$connect = mysql_connect("localhost", "name", "password");
if (!$connect) {
die ("Hey loser, check your server connection.");
alert("No access.");
}
mysql_select_db("db");
echo "<div class=\"accwrapper\">";
echo "<div id=\"resor\">";
$rresult=mysql_query("SELECT * from node");
while($row=mysql_fetch_array($rresult, MYSQL_ASSOC)) {
echo "<tr class=\"prislista-row\"><td>";
echo $row["node_title"];
echo "</td><td class=\"list-price\">";
echo $row["uc_products_list_price"];
echo "</td><td class=\"sell-price\">";
echo $row["uc_products_sell_price"];
echo "</td></tr>";
}
?>
</div><!--resor-->
</div><!--accwrapper-->
</body>
EDIT: Everything after
echo '<div class="accwrapper">'; //the last single quote in this line
is a string, even with single quotes. Removed single quotes and the alert/die thing and still no luck. But thanks to everyone's responses.
Use single quotes around your echo's then you won't have to excape
echo '</td><td class="sell-price">';
but the main problem is alert is a javascript function not a php
remove this line
alert("No access.");
EDIT
I took out your mysql stuff and it works so now you just gotta figure out whats wrong with your sql
<html>
<head><title>New.</title>
</head>
<body>
<?php
$connect = true;
if (!$connect) {
die ("Hey loser, check your server connection.");
}
//mysql_select_db("db");
echo '<div class="accwrapper">';
echo '<div id="resor">';
echo '<tr class="prislista-row"><td>';
echo $row["node_title"];
echo '</td><td class="list-price">';
echo $row["uc_products_list_price"];
echo '</td><td class="sell-price">';
echo $row["uc_products_sell_price"];
echo '</td></tr>';
?>
</div><!--resor-->
</div><!--accwrapper-->
</body>
If you're using echo tags, try using single quotes eg:
echo '<div class="accwrapper">';
Writing it this way should never cause problem ;) :
<html>
<head>
<title>New.</title>
</head>
<body>
<?php
$connect = mysql_connect("localhost", "name", "password");
if (!$connect) {
die ("Hey loser, check your server connection.");
alert("No access."); //this will never execute
}
mysql_select_db("db");
$rresult=mysql_query("SELECT * from node");
?>
<div class="accwrapper">
<div id="resor">
<?php while($row=mysql_fetch_array($rresult, MYSQL_ASSOC)) : ?>
<tr class="prislista-row">
<td><?php echo $row["node_title"]; ?></td>
<td class="list-price"><?php echo $row["uc_products_list_price"]; ?></td>
<td class="sell-price"><?php echo $row["uc_products_sell_price"]; ?></td>
</tr>
<?php endwhile; ?>
</div><!--resor-->
</div><!--accwrapper-->
So let HTML be HTML, and PHP should stay PHP. Try to avoid mixing them like by echoing HTML from within PHP.
精彩评论