LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2005, 11:33 AM   #1
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
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

Last edited by vxc69; 12-22-2005 at 11:50 AM.
 
Old 12-22-2005, 11:41 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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?
 
Old 12-22-2005, 11:55 AM   #3
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Original Poster
Rep: Reputation: 33
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
 
Old 12-22-2005, 12:10 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 12-22-2005, 02:04 PM   #5
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Original Poster
Rep: Reputation: 33
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

Last edited by vxc69; 12-22-2005 at 02:10 PM.
 
Old 12-22-2005, 02:21 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
About timer.... help rajsun Programming 3 05-24-2005 06:06 AM
php system() and #!/bin/sh .. first timer..lil help please? :) chibi Programming 8 05-05-2005 10:28 PM
First timer, help!!!!! jcniest5 Linux - Newbie 7 02-24-2004 08:32 AM
timer... perdesiz Linux - Software 1 09-18-2003 03:39 AM
QT Timer kusio Linux - Software 1 04-15-2003 05:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration