Solved

php troubleshootin

Posted on 2015-02-14
24
94 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 110

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
 
LVL 110

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 110

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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

623 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