PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Sat Apr 25, 2009 4:49 pm
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>
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Apr 25, 2009 5:19 pm
Code: Select all
echo "<td>{$Comments['comments']}</td>";</tr>
Take a good, hard look at that.
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Sat Apr 25, 2009 6:36 pm
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.
Last edited by
McInfo on Tue Jun 15, 2010 12:25 pm, edited 1 time in total.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Apr 25, 2009 6:40 pm
The first assumes there's (at least) one result from the query, the second does not. Besides that they're the same.
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Sat Apr 25, 2009 6:58 pm
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.
Last edited by
McInfo on Tue Jun 15, 2010 12:29 pm, edited 1 time in total.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Apr 25, 2009 7:19 pm
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.
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Sat Apr 25, 2009 7:25 pm
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.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Apr 25, 2009 7:43 pm
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.
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Sat Apr 25, 2009 7:52 pm
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>";
}
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Sat Apr 25, 2009 8:57 pm
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
or
Both of these conditions are false.
Edit: This post was recovered from search engine cache.
Last edited by
McInfo on Tue Jun 15, 2010 12:32 pm, edited 1 time in total.
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Sat Apr 25, 2009 9:02 pm
ahh okay, I understand... thanks!