Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

php troubleshootin

Posted on 2015-02-14
24
Medium Priority
?
100 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 84

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 111

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 111

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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

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 111

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 84

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

580 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