You're mixing mysqli and mysql
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
For example:
$result = @$conn->query($query_str);
if(mysql_query($query_str)){
Your connection is based on:
$conn = @new mysqli('localhost', 'root', '', 'CCM3413');
which is mysqli, but you're trying to use the old mysql_* functions to process the query. There may be other issues with the code, but that's the first thing that struck me.
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
Yes, look at the manual as I mentioned - with the link. Replace all mysqli functions with mysql ones.
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
Why "connection failed?", surely it's "query failed"? Have an or die() clause on the query line to tell you exactly why the query is failing.
Alternatively,echo the query string to the screen, copy and paste it into phpMyAdmin and run it in the SQL window. See what happens.
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
This won't work:
$result = @$conn->query($query_str);
echo "Query Passed <br/>";
if ($result === FALSE)
{
echo "Query Failed <br/>";
$conn->close();
exit;
}
For one thing, you've suppressed errors with @
Query passed will be echoed every time as you don't provide a test.
Try:
$result = $conn->query($query_str);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
die('Invalid query: ' . $conn->error);
Ah, forgot he was using class.
diafol
Keep Smiling
10,636 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,508
Skill Endorsements: 57
Remove line 9.
Also this:
mysql_query('SELECT * FROM ccm3414.StudentInfo');
if (false) { die ('Unable to Select that DB : ' . mysql_error()); }
doesn't work, use this:
$result = mysql_query('SELECT * FROM ccm3414.StudentInfo') or die (mysql_error());
Lines 16-19 can be removed too.
pritaeas
Posting Prodigy
9,267 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86
So the database (ccm3414) is wrong and/or the table (StudentInfo).
pritaeas
Posting Prodigy
9,267 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86