Mysql SELECT with a global joomla variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chitak
Forum Newbie
Posts: 2
Joined: Sat Nov 27, 2010 6:35 pm

Mysql SELECT with a global joomla variable

Post by chitak »

Hi all

here is the code I'm working with

<?php
defined('_JEXEC') OR defined('_VALID_MOS') OR die( "Direct Access Is Not Allowed" );

$user =& JFactory::getUser();

$field = $user->email;


$db_host = 'xx';
$db_user = 'xx';
$db_pwd = 'xx';

$database = 'xx';
$table = 'table';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

// sending query
$sql = "SELECT * FROM `tables` WHERE email = '$field'";
echo $sql;

if ($result=mysql_query($sql)) {
if ($row=mysql_fetch_row($result)) {
echo "Column 1 is ".$row[0]."<br>\n";
echo "Column 2 is ".$row[1]."<br>\n";
echo "Column 3 is ".$row[2]."<br>\n";
echo "Column 4 is ".$row[3]."<br>\n";
}
} else {
echo "<!-- SQL Error ".mysql_error()." -->";
}


mysql_free_result($result);

?>

The line that's a problem is where I send select to the DB. This doesn't get anything in return. I added an echo of $sql just for testing purposes, and it gives the correct statement but still it doesn't work. If I replace $field with text then it works. I'm using this in a joomla article using Jumi. Any ideas? I've tried every modification I could find online for the select statement but no luck I'm starting to think it could be something wrong with the host?!
The server is running PHP 5.2.9, MySQL 5.0.77, this is running on a netfirms.com hosting.

thanks
chitak
Forum Newbie
Posts: 2
Joined: Sat Nov 27, 2010 6:35 pm

Re: Mysql SELECT with a global joomla variable

Post by chitak »

I got it working. No need for help.
Post Reply