mysql_fetch_array works on php 5.0.4 not php 4.4.3

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
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

mysql_fetch_array works on php 5.0.4 not php 4.4.3

Post by imstupid »

Hello everybody, how's it going? oh, that's nice.

Hey, speaking of code, is there any reason why this code:

Code: Select all

$email = mysql_query("SELECT email FROM magicalschoolbus WHERE dude='$tinaturner'") 
 	or die(mysql_error()); 
$oem = mysql_fetch_array( $email )
	or die(mysql_error());
Would work on php 4.4.3, and not php 5.0.4? That's the only thing I think it can be...

For reference, here's the what I'm trying to do

Code: Select all

// connect, login, ms.dash, etc. 

$email = mysql_query("SELECT email FROM magicalschoolbus WHERE dude='$tinaturner'") 
 	or die(mysql_error()); 
$oem = mysql_fetch_array( $email )
	or die(mysql_error()); 

$oem['email'] = stripslashes($oem['email']) ;

Code: Select all

<input name="email" type="text" value="<?PHP echo $oem['email'] ?>" size="35" />
I get nothing. blank white screen. bright, plain and souless... like the vast lands of the antartic. nothing in the source either. thanks in advance for any help.
Last edited by imstupid on Thu Jun 08, 2006 10:15 am, edited 1 time in total.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

mysql_fetch_array() takes two paramateres, I thought.

The MySQL resource and the type of array.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Re: mysql_fetch_array works on php 4.4.3 not php 5.0.4

Post by bdlang »

imstupid wrote: I get nothing. blank white screen. bright, plain and souless... like the vast lands of the antartic. nothing in the source either. thanks in advance for any help.

Add these lines to the top of your script:

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
I assume you actually make a database connection above this code? Check your connection.

Is any HTML output? Check your page source.

Check any and all include files.

Check your PHP syntax, make sure all lines have ending semicolons ';', all concatenation operators are in place, etc.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Daedalus- wrote:mysql_fetch_array() takes two paramateres, I thought.

The MySQL resource and the type of array.
The resulting array type is optional.
PHP Manual: mysql_fetch_array()
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

PHP5 uses the mysqli library by default. Have you installed the mysql extension for PHP5?
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

Thanks everybody-
everah- I'd love to be able to answer that question, however I'm pretty useless. I checked out that phpinfo() jobber, and there's a bunch of paths to a couple mysql socks and what not.

bdlang- the code

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
also displays no message... like a lonely sailor, checking his answering machine waiting for his ex-girlfriend to call. and there's also nothing in the page source either.


Finally, When I comment out these two lines:

Code: Select all

$oem = mysql_fetch_array( $email )
        or die(mysql_error());
it works. but of course I'd need that mysql_fetch_array to actually display data instead of the Resource ID #2 correct?

Thanks guys.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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";
}

?>
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

holy crap. holy crap. holy crap. nevermind. probably dumbest mistake I ever made. well, there was a good 4 hours wasted... works like a charm. thanks and sorry.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, Enlighten us. What was your WTF?!?!? moment of zen?
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

OK, Enlighten us. What was your WTF?!?!? moment of zen?
Yeah, this was a rough one. basically, I've been testing all the code on one server while they were updating the real one. I put a couple of variables in hidden html form fields, and forgot to change the header() redirect on the submit.php page. So of course, all the variables were going to the script on the testing server, while I was checking out the results on a completely different domain.

On one hand, it's hard to own up to such a mistake, but even harder trying to figure out how I was going to explain it to this community.

Anyway, i'm sure i'll be posting some more ridiculous questions in the future. Thanks again.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Welcome to the club. I can't even remember half the stupid crap I've done (actually I can, I'm just pleading stupidity right now).
Ronald Reagan (or was it Oliver North) wrote:I can't recall...
Post Reply