Author Topic: PHP Problems  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
PHP Problems
« on: February 08, 2007, 05:48:19 AM »
Hi all

I am using a very simple php script which i've uploaded to a server, but I get no result not do I get any errors, this is the same with any code im trying to use where it pulls content from a MySQL datababase.

Can anyone give me any idea what it might be? Im battling with it to get anything to come up.

Code: [Select]
<?
$db_name ="****";
$server = "localhost";
$dbusername = "****";
$dbpassword = "****";

$connection = mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = mysql_select_db($db_name,$connection)or die(mysql_error());


$sql = mysql_query("SELECT * FROM documents ORDER BY value ASC")or die(mysql_error());
while($row = mysql_fetch_array($sql))
{
print "".$row['id']."<br><br>";
}
?>

Any help at all would be great.

Thanks

Ed
« Last Edit: February 08, 2007, 05:50:20 AM by CanMan2004 »

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #1 on: February 08, 2007, 06:03:23 AM »
Is there another way I should write the code? we have to connect to the database through a SSH client if that helps in anyway

Offline Jaysonic

  • Fanatic
  • Posts: 3,332
  • Gender: Male
  • 8548863
    • View Profile
    • I Am Lewy Babes
Re: PHP Problems
« Reply #2 on: February 08, 2007, 06:08:01 AM »
change this:
Code: [Select]
while($row = mysql_fetch_array($sql))
{
print "".$row['id']."<br><br>";
}

to this:
Code: [Select]
$i = 0;
while($row = mysql_fetch_array($sql)){
echo $row['id']." - I = {$i}<br><br>";
$i++;
}

and see if it outputs any numbers. should output 0, 1, 2 or however much results are in the database.
Good luck with your coding.
Jason ~ ProjectFear ~ Jaysonic (and variations of... :))

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #3 on: February 08, 2007, 06:13:04 AM »
I still get nothing displayed on the page

Offline Jaysonic

  • Fanatic
  • Posts: 3,332
  • Gender: Male
  • 8548863
    • View Profile
    • I Am Lewy Babes
Re: PHP Problems
« Reply #4 on: February 08, 2007, 06:15:45 AM »
do you have anything in your database? put this above your while loop:

Code: [Select]
echo "Rows: ".mysql_num_rows($sql)."<br>";
make sure its below your $sql line though. tell me how much rows it displays.
Good luck with your coding.
Jason ~ ProjectFear ~ Jaysonic (and variations of... :))

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #5 on: February 08, 2007, 06:26:22 AM »
Hi

That doesnt seem to work, nor does it print anything.

What's strange, is that if I place

<?
print "testing";
?>

and put it right at the top of my php page, above all the db connection details, then it prints "testing" without a problem, but if I place

<?
print "testing";
?>

and put this anywhere under the db connection details, then it wont print anything.

Does that make sense?

Why would that happen?

Thanks

Ed

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #6 on: February 08, 2007, 07:01:01 AM »
Can anyone help me on this? Getting no result despite what I do

Offline fiddy

  • Enthusiast
  • Posts: 75
    • View Profile
Re: PHP Problems
« Reply #7 on: February 08, 2007, 07:06:22 AM »
If you are getting a blank page. then there should be problem with the DB connection i guess. It might not show you errors if error reporting is off in your php.ini.

Just a Thought...
:)

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #8 on: February 08, 2007, 07:14:47 AM »
Is there a default port number that is used as my port number maybe different, could this be the reason?

Offline Tyche

  • Irregular
  • Posts: 49
  • Gender: Female
    • View Profile
Re: PHP Problems
« Reply #9 on: February 08, 2007, 07:24:26 AM »
It sounds like your are generating a mysql_error but the die statement is not closing off your html
so no error is visible in your browser

Try replacing the 3 occurances of
Code: [Select]
die(mysql_error()) with
Code: [Select]
die(mysql_error()."</body></html>")

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #10 on: February 08, 2007, 07:26:42 AM »
I've just tried

Code: [Select]
<?php
$link 
mysql_connect('localhost''xxx''xxx');
print 
"hello";
if (!
$link) {
   die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';
mysql_close($link);
?>

Anything test page text you put above that code displays on the page, but anything that is added under that code, does not work.

Strange, totally confused it wont even tell me it cant connect
« Last Edit: February 08, 2007, 07:29:27 AM by CanMan2004 »

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #11 on: February 08, 2007, 07:29:02 AM »
Thanks Tyche, but it still doesnt show anything

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #12 on: February 08, 2007, 08:02:57 AM »
What should I check in the php.ini file? Or would that not be causing the issue

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: PHP Problems
« Reply #13 on: February 08, 2007, 09:12:12 AM »
You may need to tun on error reporting. Put this at the top of your script.

Code: [Select]
<?php error_reporting(E_ALL); ini_set('display_errors','1'); ?>

Offline CanMan2004Topic starter

  • Enthusiast
  • Posts: 256
    • View Profile
Re: PHP Problems
« Reply #14 on: February 08, 2007, 10:09:52 AM »
Thanks, I get the error

Call to undefined function mysql_connect()

Do I need to enable something?