Jump to content

PHP Code breaks if any DB stuff is attempted


X0ML

Recommended Posts

OK, about ready to go postal, as I've been wasting inordinate amounts of time trying to resolve this issue!  If I create basic HTML echo-ed content, PHP works fine.  But if I try to reference any database related syntax, the whole PHP web page breaks!  VERY FRUSTRATING.  This works:

<?php

// Printing results in HTML
echo "<html>\n";
echo "<head>";
echo "</head>";
echo "<body bgcolor=\"#CCCCCC\">";

echo "<CENTER><H1>Current Inventory</H1>";

but this blows up and just gives me a white page with nothing!:

<?php

// Printing results in HTML
echo "<html>\n";
echo "<head>";
echo "</head>";
echo "<body bgcolor=\"#CCCCCC\">";

echo "<CENTER><H1>Current Inventory</H1>";



$dbhostip = "192.168.0.10";
$dbport = "5432";
$dbname = "testdata";
$dbuser = "postgres";
$dbpass = "password1";

$dbconn = pg_connect($dbhostip,$dbport,$dbname,$dbuser,$dbpass);

echo $dbconn;
if(!$dbconn) {
	echo "An error has occurred (line 17)\n";
	exit;
	}


	$result = pg_query($dbconn, "SELECT * FROM inventory");
	if(!$result){
	echo "An error has occurred (line 24)\n";
	exit;
	}
	
$resultCheck = pg_num_rows($result);

	if ($resultCheck > 0) {
		while ($row = pg_fetch_assoc($result)){
		echo $row['cid'];			
		echo $row['item_title'];				
		}

	}
?>

Any help would be appreciated.  It seems that anything with $whatever causes the issue...

 

Link to comment
Share on other sites

you are either getting a fatal php syntax/parse error or a fatal run-time error. for both of these, get php to help you by finding the php.ini that php is using and set error_reporting to E_ALL and display_errors to ON, so that php will report and display all the errors it detects. stop and start your web server to insure any changes made to the php.ini take effect and use a phpinfo() statement in a .php script file to confirm that the settings took effect.

  • Thanks 1
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.