php problem

Barry_Lu

New Member
Messages
4
Reaction score
0
Points
1
I'm trying to add an old php file but it doesn't seem to be working. The original code was this:

<html>
<head>
<title>Query All Movies from Database</title>
<body>

<?

@ $db = mysql_pconnect("localhost","ensvktbm","password");

if (!$db)
{
echo "ERROR: Could not connect to database. Please try again later.";
exit;
}

mysql_select_db("ensvktbm_Week11");

$query = "select * from movie";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);

echo "<p>Number of movies found: ".$num_results."</p>";

for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p>";
echo htmlspecialchars( stripslashes($row["movieid"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["title"]));
echo "<br>";
//echo htmlspecialchars( stripslashes($row["directorid"]));
//echo "<br>";
echo htmlspecialchars( stripslashes($row["year"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["genre"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["runtime"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["plotdescription"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["comments"]));
echo "<br>";
echo "</p>";

}

?>

</body>
</html>

I tried to update it with this:

<html>
<head>
<title>Query All Movies from Database</title>
</head>
<body>

<?php

$db = mysqli_connect("localhost","ensvktbm","password","ensvktbm_Week11");

if (!$db)
{
echo "ERROR: Could not connect to database. Please try again later.";
exit;
}
mysqli_select_db("ensvktbm_Week11");
$result = mysqli_query($db, "SELECT * FROM movie");

$num_results = mysqli_num_rows($result);

echo "<p>Number of movies found: ".$num_results."</p>";

for ($i=0; $i < $num_results; $i++)
{
$row = mysqli_fetch_array($result);
echo "<p>";
echo htmlspecialchars( stripslashes($row["movieid"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["title"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["directorid"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["year"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["genre"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["runtime"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["plotdescription"]));
echo "<br>";
echo htmlspecialchars( stripslashes($row["comments"]));
echo "<br>";
echo "</p>";

}

?>

</body>
</html>

It seems to only activate the if statement and stop. When I delete the if statement, it shows "Number of movies found:" but not the result. What do I do?
 
Last edited:

spacresx

Community Advocate
Community Support
Messages
2,199
Reaction score
195
Points
63
x10 hosting support does not provide help with php scripts.
 
Top