Page 1 of 1

what's wrong with this code?

Posted: Sat Apr 25, 2009 4:49 pm
by p_sha85
Can someone tell me what's wrong with this code? It keeps giving an error that there's an unexpected '<' on line 34 (35 here).... ???

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Candidates' Interview Information</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$DBConnect = @mysqli_connect("localhost", "root", "pooj0317")
     Or die("<p>Unable to connect to the database server.</p>"
     . "<p>Error code " . mysqli_connect_errno()
     . ": " . mysqli_connect_error()) . "</p>";
 
$DBName = "interviews";
if (!@mysqli_select_db($DBConnect, $DBName))
     die("<p>There is no candidate information!</p>");
 
$TableName = "candidates";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (mysqli_num_rows($QueryResult) == 0)
      die("<p>There is no candidate information!</p>");
 
echo "<p>The following candidates have been interviewed:</p>";
echo "<table width='100%' border='1'>";
echo "<tr><th>Name</th><th>Communication Abilities</th><th>Professional Appearance</th><th>Computer Skills</th><th>Business Knowledge</th><th>Interviewer's Comments</th></tr>";
$Row = mysqli_fetch_assoc($QueryResult);
do {
     echo "<tr><td>{$CandName['cand_name']}</td>";
     echo "<td>{$CommAbil['comm_abil']}</td>";
     echo "<td>{$ProfApp['prof_app']}</td>";
     echo "<td>{$CompSkills['comp_skills']}</td>";
     echo "<td>{$BusKnow['bus_know']}</td>";
     echo "<td>{$Comments['comments']}</td>";</tr>
     $Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
 
mysqli_free_result($QueryResult);
mysqli_close($DBConnect);
?>
</body>
</html>
 

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 5:19 pm
by requinix

Code: Select all

echo "<td>{$Comments['comments']}</td>";</tr>
Take a good, hard look at that.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 6:36 pm
by McInfo
I'm foreseeing another problem.

Should this
p_sha85 wrote:

Code: Select all

$Row = mysqli_fetch_assoc($QueryResult);
do {
     echo "<tr><td>{$CandName['cand_name']}</td>";
     echo "<td>{$CommAbil['comm_abil']}</td>";
     echo "<td>{$ProfApp['prof_app']}</td>";
     echo "<td>{$CompSkills['comp_skills']}</td>";
     echo "<td>{$BusKnow['bus_know']}</td>";
     echo "<td>{$Comments['comments']}</td>";</tr>
     $Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
be this

Code: Select all

while ($Row = mysqli_fetch_assoc($QueryResult))
{
     echo "<tr><td>{$Row['cand_name']}</td>";
     echo "<td>{$Row['comm_abil']}</td>";
     echo "<td>{$Row['prof_app']}</td>";
     echo "<td>{$Row['comp_skills']}</td>";
     echo "<td>{$Row['bus_know']}</td>";
     echo "<td>{$Row['comments']}</td></tr>";
}
?

Edit: This post was recovered from search engine cache.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 6:40 pm
by requinix
The first assumes there's (at least) one result from the query, the second does not. Besides that they're the same.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 6:58 pm
by McInfo
tasairis wrote:The first assumes there's (at least) one result from the query, the second does not. Besides that they're the same.
There's that, and the variable names are different, which would be more obvious if the syntax highlighter was a little more complete.

Edit: This post was recovered from search engine cache.

Edit: The old syntax highlighter did not distinguish variables within double-quoted strings. The current one does, apparently.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 7:19 pm
by requinix
McInfo wrote:
tasairis wrote:The first assumes there's (at least) one result from the query, the second does not. Besides that they're the same.
There's that, and the variable names are different, which would be more obvious if the syntax highlighter was a little more complete.
Ah. Hmm. Yes. That's absolutely right. :?

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 7:25 pm
by p_sha85
Wow, thanks so much for your replies to this. So should the variable names not be different?? I had them as all the same before but then I thought it was wrong so I changed it. I've been doing this for like 2 days straight so I can hardly even think properly on this stuff anymore.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 7:43 pm
by requinix
McInfo's right.

Code: Select all

$Row = mysqli_fetch_assoc($QueryResult)
The only variable around is called $Row and it has all the information you need. Those variables you were trying to use don't exist so it won't work.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 7:52 pm
by p_sha85
Ahh okay, so I use this $Row one several times for each thing is it? Like this?:

Code: Select all

 
$Row = mysqli_fetch_assoc($QueryResult);
while ($Row = mysqli_fetch_assoc($QueryResult))
{
       echo "<tr><td>{$Row['cand_name']}</td>";
       echo "<td>{$Row['comm_abil']}</td>";
       echo "<td>{$Row['prof_app']}</td>";
       echo "<td>{$Row['comp_skills']}</td>";
       echo "<td>{$Row['bus_know']}</td>";
       echo "<td>{$Row['comments']}</td></tr>";
}
 

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 8:57 pm
by McInfo
You don't need the first

Code: Select all

$Row = mysqli_fetch_assoc($QueryResult);
The statement inside the while condition is NOT a comparison between $Row and mysqli_fetch_assoc($QueryResult). Notice that there is a single equal sign (=), not two (==) or three (===). $Row is being set to the result of mysqli_fetch_assoc(), which is either an array or NULL. The while condition is evaluating the entire assignment statement. The statement evaluates to the value of $Row after the assignment, which is the return value of mysqli_fetch_assoc(). As long as the statement does not evaluate to NULL, the while loop continues.

If there are no rows returned by mysqli_fetch_assoc(), it is like writing

Code: Select all

if (NULL)
or

Code: Select all

if (array())
Both of these conditions are false.

Edit: This post was recovered from search engine cache.

Re: what's wrong with this code?

Posted: Sat Apr 25, 2009 9:02 pm
by p_sha85
ahh okay, I understand... thanks!