Php/mysql queries are not processing

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

frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Php/mysql queries are not processing

Post by frankpmjr »

Hi,
The queries on one of my sites I look after stopped processing MySQL queries. The site is written in PHP and I have been over the code over and over again. No matter what i do it won't process the queries, nor will it give me an error. The php server is working because it will print out Echo statements but queries just leave everything blank. Even the HTML code after the query doesn't process. Its like the processing gets stuck on the query. What can I do? Thanks.

Frank
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post some code. That is the first recommendation. Then let us know what your server settings and server versions are. After that, explain what you mean by 'queries just leave everything blank'. A little more information will help us help you a little better.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thanks for a quick reply here is version 1 (I rewrote existing code to see if it made a difference)

Code: Select all

<? $connection = mysql_connect($host,$username,$password)
   or die ("Couldn't connect to database");
   
   $db= mysql_select_db($dbase, $connection)
   or die ("Couldn't select database");
   
   $query = "Select * from idm_message";
   
   $result = mysql_query($query)
    or die ("Couldn't execute query");
	
	$row = mysql_fetch_array($result); ?>
	
	<p class=title_text>a message from phil</p>
<? echo $row["title"]; ?></b> <? echo $row["message"]; ?>
Here is version 2 (this is actually the original version)

Code: Select all

<? $connection = mysql_connect($host,$username,$password); 
if ($connection == false){ 
  echo mysql_errno().": ".mysql_error()."<BR>"; 
  //echo("Your username or password is not correct."); 
  exit; }  

$select_success = mysql_select_db("dmn"); 
$db_message = mysql_query("SELECT * FROM idm_message"); 
$row = mysql_fetch_array($db_message);
?>
<? echo $row["title"]; ?></b> <? echo $row["message"]; ?></p> 

<? mysql_close(); ?>
Server is PHP 5 (not sure what other version info there is)

Not sure about settings either, as I didn't set this up, I only maintain the site and make minor adjustments.

The pages are empty past the point of where a query is made. For instance on the home page (http://www.insidedigitalmedia.com, hope its OK to put in urls) the top and left side of the page are fine, then the center of the page is blank is blank (except for 2 lines of text right before the first query). Usually there is a section that contains a message from the site's owner (source of the code above). Then below that is a section with links to interviews that is also pulled from the MySQL db.

Hopefully this is OK, thanks again for the help.

Frank


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");

$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
    $le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
     $le = $eol . $le;
}
else
{
 $le = '<pre>' . $le . '</pre>';
}

$ec = array(
   'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

if (!$cli)
{
  echo '<html><head><title>quick info</title></head><body>' . "\n";
}

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;

if (!$cli)
{
  echo '</body></html>' . "\n";
}

?>
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Here is the output:
PHP Version: 4.4.2
PHP OS: FreeBSD
Error Reporting: 2047 (E_ALL)
Register Globals: Off
Short Tags: On
Display Errors: Off
Loaded Extensions:
standard apache
Look forward to learning what this means. Thanks.

Regards,

Frank
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You may need to turn error_reporting on to see if there are errors being thrown that are not being displayed.

At the beginning of your page that has errors on it, add this line..

Code: Select all

<?php
ini_set('display_errors', 1);
?>
Run the page again and see if anything gets outputted that could help you out (and help us help you out).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Frank,

Did you reinstall PHP? Are you hosting this with another company?

MySQL isn't even loaded. Error reporting is on, but display errors is off so your not even seeing the errors.

Someone mucked with your PHP installation...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Man, I didn't even look that far. He seems to have a few extensions loaded. He should probably be getting all sorts of calls to undefined function errors.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Thank you guys. I am working with the hosting company right now to get this corrected.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Hi again,

It seems my host is telling me that I am wrong. He insists that I have something incorrect in my code and reminded me that the MySQL server is sitting at 127.0.0.1. I inserted the code prescribed above to turn error reporting display on and here is the output.
Fatal error: Call to undefined function: mysql_connect() in /usr/local/www/data-dist/insidedigitalmedia/includes/featured_message.inc on line 1
Is this saying that there is no such function as mysql_connect? I have checked the username, password, and host IP several times and they are correct. Thanks.

Frank
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Everah wrote:Man, I didn't even look that far. He seems to have a few extensions loaded. He should probably be getting all sorts of calls to undefined function errors.
The reason I posted this statement is becuase if the mysql extension is not enabled, PHP will not know what the heck function mysql_* will be. Since it is undefined (unknow) it throws an error. Tell your host to check your PHP info page to see which extensions are loaded. Also tell them they are full it if they think that they are right since your call to a function they say is enabled returned an error.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Thanks, that gives me the ammo I need to take back to the host. I appreciate the help and will keep you posted.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

Is there anyway for me to do this myself? I don't know if I'll ever hear from the host.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Do you have ssh access? You may need to recompile PHP..
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

I do but you will have to walk me through it.
Post Reply