LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP help - first timer (https://www.linuxquestions.org/questions/programming-9/php-help-first-timer-395671/)

vxc69 12-22-2005 11:33 AM

PHP help - first timer
 
Table called links contains the following:

+----+--------+--------------------------------+---------+
| id | author | link | caption |
+----+--------+--------------------------------+---------+
| 1 | Me | http://www.google.com/ig?hl=en | Google |
+----+--------+--------------------------------+---------+

PHP Code:
Code:

        <div id=body> <br>

        <?php
        //Connect to DB server
        $dbcnx = @mysql_connect('localhost', 'root', 'test');       
        if (!$dbcnx) {
                exit('<p>Unable to connect to the datbase server at this time.</p>');
        }
       
        //Select the homepage database
        if (!@mysql_select_db('homepage')) {
                exit('<p>Unable to locate the homepage database at this time.</p>');
        }
        ?>
       
        <p>My Links:</p>
        <blockquote>
       
        <?php
       
        //Request links for author Me
        $mylinks = @mysql_query("SELECT link, caption FROM links WHERE author='Me'");
       
        if(!$mylinks) {
                exit('<p>Error performing query: ' . mysql_error() . '</p>');
        }
       
        //Display the links
        while ($row = mysql_fetch_array($mylinks)) {
        echo '<p><a href=\"' . $row['link'] . '>' . $row['caption'] . '</a></p>';       
        }
       
        ?>
        </blockquote>
        </div>

It's supposed to fetch links for author 'Me'. But it doesn't work. Nothing shows up. The mysql authentication was double checked. Maybe there's something wrong with the "//Display the links" section of the code.

Thanks in advance,
vxc

Matir 12-22-2005 11:41 AM

It looks like you might have a problem with:
Code:

$mylinks = @mylinkssql_query("SELECT link, caption FROM links WHERE author='Me'");
I am not aware of any function name mylinkssql_query. Perhaps you meant mysql_query?

vxc69 12-22-2005 11:55 AM

Quote:

Originally Posted by Matir
It looks like you might have a problem with:
I am not aware of any function name mylinkssql_query. Perhaps you meant mysql_query?

Oops...That's a mistake I made replacing words after copying the code. The actual code is "@mysql_query..."

I've changed my previous post. Sorry about that.

Anyway, problem still not solved. Could it be some kind of configuration error. I've got the default ubuntu php4 installation. Haven't changed php.ini

Thanks again,
vxc

Matir 12-22-2005 12:10 PM

Does even "My Links:" show up? Try (temporarily) removing the error-supressing @ in front of each function call to see if that sheds any light on things.

vxc69 12-22-2005 02:04 PM

My Links doesn't show up. Removing the @ sign gives this error:

Fatal error: Call to undefined function: mysql_connect() in /var/www/test.php on line 4

Line 4 is:
$dbcnx = mysql_connect('localhost', 'root', 'test');

I Googled the error and I think found the problem.

According to phpinfo():

Code:

Configure Command          '../configure' '--prefix=/usr'
'--with-apxs2=/usr/bin/apxs2' '--with-config-file-path=/etc/php4/apache2'
'--enable-memory-limit' '--disable-debug' '--with-regex=php'
'--disable-rpath' '--disable-static' '--with-pic' '--with-layout=GNU'
'--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem'
'--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars'
'--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype'
'--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro'
'--enable-ftp' '--with-gettext' '--enable-mbstring'
'--with-pcre-regex=/usr' '--enable-shmop' '--enable-sockets'
'--enable-wddx' '--disable-xml' '--with-expat-dir=/usr' '--with-xmlrpc'
'--enable-yp' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr'
'--with-openssl=/usr' '--enable-dbx'
'--with-mime-magic=/usr/share/misc/file/magic.mime'
'--with-exec-dir=/usr/lib/php4/libexec' '--without-mm'
'--without-mysql' '--without-sybase-ct'

My mysql support hasn't been enabled.

In order to enable it I installed php4-mysql from the ubuntu repositories and presto it worked.

Thanks for the help Matir! Problem solved! :)

vxc

Matir 12-22-2005 02:21 PM

No problem, glad we were able to get it working! In the future, I suggest avoiding error supression (@function) while debugging. They can help sometimes. :)


All times are GMT -5. The time now is 11:05 AM.