Solved

php troubleshootin

Posted on 2015-02-14
24
75 Views
Last Modified: 2015-02-27
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>
0
Comment
Question by:linuxperson
  • 14
  • 4
  • 3
  • +1
24 Comments
 

Author Comment

by:linuxperson
ID: 40609946
How do i troubleshoot this?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40609952
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40609969
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
 

Author Comment

by:linuxperson
ID: 40609985
[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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40609995
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
 

Author Comment

by:linuxperson
ID: 40610047
i see that php installed correctly.

How do i check if i am connecting to the database ?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40610050
Have you set error_reporting to E_ALL as I suggested above?
0
 

Author Comment

by:linuxperson
ID: 40610081
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
 

Author Comment

by:linuxperson
ID: 40610082
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| student            |
+--------------------+
2 rows in set (0.00 sec)
0
 

Author Comment

by:linuxperson
ID: 40610083
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
 

Author Comment

by:linuxperson
ID: 40610089
mysql> select * from student_info;
+-------+--------+------------+
| fname | lname  | pnum       |
+-------+--------+------------+
| user1 | user2  |        416 |
+-------+--------+------------+
1 rows in set (0.00 sec)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40610149
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40610208
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
 

Author Comment

by:linuxperson
ID: 40610270
<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
 

Author Comment

by:linuxperson
ID: 40610272
2015/02/14 Fatal error: Call to undefined function mysqli_connect() in /var/www/html/index.php on line 10
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40610274
That means you have not enabled the 'mysqli' extension in 'php.ini'.
0
 

Author Comment

by:linuxperson
ID: 40610275
how do i enable ?
what is the exact parameter name in php.ini
0
 

Author Comment

by:linuxperson
ID: 40610278
i installed mysql and php in centos 6.2
0
 

Author Comment

by:linuxperson
ID: 40610279
[root@ws01 html]# cat /etc/php.ini | grep -v ';' | grep -i mysql | grep ext
[root@ws01 html]#
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40610311
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
 

Author Comment

by:linuxperson
ID: 40610523
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40611048
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
 

Author Comment

by:linuxperson
ID: 40611056
PHP Version 5.3.3
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40611158
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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now