Fatal error: Function name must be a string in C:\xampp\htdocs\test.php on line 6 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fatal error: Function name must be a string in C:\xampp\htdocs\test.php on line 6

<?php $conn = mysqli_connect('localhost','root','','bursary'); // Check connection if (!$conn()) { echo "Failed to connect to MySQL: "; } $result = mysqli_query($conn,"SELECT shortlist_id, user_id, application_status, amount_allocation FROM shortlist"); echo "<table border='0'> <tr> <th>Shortlist Id</th> <th>Applicant Id</th> <th>Application Status</th> <th>Ammount Allocated</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . strtoupper($row['shortlist_id']) . "</td>"; echo "<td>" . strtoupper($row['user_id']) . "</td>"; echo "<td>" . strtoupper($row['application_status']) . "</td>"; echo "<td>" . strtoupper($row['amount_allocation']) . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($conn); ?>

15th Apr 2018, 9:17 AM
Maamun Maamun
Maamun Maamun - avatar
3 Answers
+ 3
Is the mysqli extension installed on your server? do a phpinfo() or: if (!extension_loaded("mysqli")) { echo "mysqli not loaded" } else { echo "mysqli is loaded" }
15th Apr 2018, 9:29 AM
Emma
+ 3
Additionally to what @Xan said, I guess you need to terminate execution upon finding no connection was available, as I see it you only echo "Failed to connect...", but the code execution is continued after that. I guess you should do if(!$conn) ... rather than if(!$conn()) ... The second one (as I see in your code) looked more of a function rather than a variable : )
15th Apr 2018, 9:39 AM
Ipang
0
thanks ipang it worked after i used this: if (!$conn)
16th Apr 2018, 11:51 AM
Maamun Maamun
Maamun Maamun - avatar