Jump to content

PHP Problems


CanMan2004

Recommended Posts

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.

 

<?
$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

Link to comment
Share on other sites

change this:

while($row = mysql_fetch_array($sql))
{
print "".$row['id']."<br><br>";
}

 

to this:

$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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

die(mysql_error())

with

die(mysql_error()."</body></html>")

 

Link to comment
Share on other sites

I've just tried

 

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.