php troubleshootin

I am trying to setup a basic table and tried to connect using PHP.

when i went to the browser i am not seeing any output.


<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
print Date("Y/m/d");

$connect=mysqli_connect("localhost","user","password","student");

if(mysqli_connect_errno()){
        echo "Failed to connect to MYSQL:".mysqli_connect_error();
}

$result=mysqli_query($connect,"SELECT* FROM student_info");

while($row = mysqli_fetch_array($result)){
        echo $row['fname']." ".$row['last_name'];
        echo "<br>";
}

echo "done";

?>
</div>
</body>
</html>
linuxpersonAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
That means you have not enabled the 'mysqli' extension in 'php.ini'.
0
 
linuxpersonAuthor Commented:
How do i troubleshoot this?
0
 
Marco GasiFreelancerCommented:
Put at the top of your file this line

<?php
error_reporting(E_ALL);
?>

You should get some message from Php whcih will help you and us to debug the script: please, post here the result.
A question: do you get a totally blank page or you get at least the date?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Dave BaldwinFixer of ProblemsCommented:
I copied your code and put in my own database info and it works fine.  Is the file named '*.php'?   Are you running it thru a web server that supports PHP?
0
 
linuxpersonAuthor Commented:
[root@ws01 html]# ls -l
total 16
-rwx---r-x. 1 root root 247 Feb 14 11:15 index.cgi
-rw-r--r--. 1 root root 356 Feb 14 12:20 index.html
-rwxr-xr-x. 1 root root 509 Feb 14 13:56 index.php
-rw-r--r--. 1 root root 256 Feb 14 11:24 index.rb
[root@ws01 html]# pwd
/var/www/html
0
 
Ray PaseurCommented:
Install this script, shown here in its entirety.  Name it index.php and navigate to the folder with a web browser.  If you see a large display of information about PHP, you've got it installed correctly.
<?php phpinfo();

Open in new window

0
 
linuxpersonAuthor Commented:
i see that php installed correctly.

How do i check if i am connecting to the database ?
0
 
Marco GasiFreelancerCommented:
Have you set error_reporting to E_ALL as I suggested above?
0
 
linuxpersonAuthor Commented:
I did ..

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php

error_reporting(E_ALL);

print Date("Y/m/d");

$connect=mysqli_connect("localhost","user","password","student");

if(mysqli_connect_errno()){
        echo "Failed to connect to MYSQL:".mysqli_connect_error();
}

$result=mysqli_query($connect,"SELECT* FROM student_info");

while($row = mysqli_fetch_array($result)){
        echo $row['fname']." ".$row['last_name'];
        echo "<br>";
}

echo "done";

?>
</div>
</body>
</html>
0
 
linuxpersonAuthor Commented:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| student            |
+--------------------+
2 rows in set (0.00 sec)
0
 
linuxpersonAuthor Commented:
mysql> describe student_info;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| fname | varchar(20) | YES  |     | NULL    |       |
| lname | varchar(20) | YES  |     | NULL    |       |
| pnum  | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
0
 
linuxpersonAuthor Commented:
mysql> select * from student_info;
+-------+--------+------------+
| fname | lname  | pnum       |
+-------+--------+------------+
| user1 | user2  |        416 |
+-------+--------+------------+
1 rows in set (0.00 sec)
0
 
Marco GasiFreelancerCommented:
echo $row['fname']." ".$row['last_name'];

Open in new window


but the column name is 'lname': this should produce an message saying about an uncknoun column. Probably you have to add this

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
?>
If this doesn't give result, you have to investigate why error messages are not displayed.
0
 
Ray PaseurCommented:
This may have some useful hints:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

And the var_dump() function is your friend.  If you're ever not 100% sure what your data looks like, you can print it out!
0
 
linuxpersonAuthor Commented:
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

print Date("Y/m/d");

$connect=mysqli_connect("localhost","user","password","student");

if(mysqli_connect_errno()){
        echo "Failed to connect to MYSQL:".mysqli_connect_error();
}

$result=mysqli_query($connect,"SELECT* FROM student_info");

while($row = mysqli_fetch_array($result)){
        echo $row['fname']." ".$row['lname'];
        echo "<br>";
}

echo "done";

?>
</div>
</body>
</html>
0
 
linuxpersonAuthor Commented:
2015/02/14 Fatal error: Call to undefined function mysqli_connect() in /var/www/html/index.php on line 10
0
 
linuxpersonAuthor Commented:
how do i enable ?
what is the exact parameter name in php.ini
0
 
linuxpersonAuthor Commented:
i installed mysql and php in centos 6.2
0
 
linuxpersonAuthor Commented:
[root@ws01 html]# cat /etc/php.ini | grep -v ';' | grep -i mysql | grep ext
[root@ws01 html]#
0
 
Dave BaldwinFixer of ProblemsCommented:
I don't know about CentOS 6.2.  I have CentOS 6.6 and the extensions are loaded from '/etc/php.d'.  In my 'php.ini' are lines about MySQL and MySQLi which are 'automatically' loaded and they came with the original install.
0
 
linuxpersonAuthor Commented:
I did install php-mysql-5.3.3-40.el6_6.x86_64 and restarted httpd service.

its works now.

Thanks everyone for your support.
0
 
Ray PaseurCommented:
Not sure what level of PHP you have there, but you may want to think about upgrading your PHP installation.  PHP 5.3 is obsolete - no longer supported for anything except security fixes.  The current versions are shown on the home page of php.net.
    5.6.5
    5.5.21
    5.4.37
0
 
linuxpersonAuthor Commented:
PHP Version 5.3.3
0
 
Dave BaldwinFixer of ProblemsCommented:
PHP 5.3.x is the version currently supported by the CentOS 6 distribution.  And by my Ubuntu 10.4 distribution.  The only way to 'upgrade' these versions is to download the source and compile a newer version.  And the extensions.  At that point, you can no longer use the repositories to download anything related to PHP.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.