Jump to content

[SOLVED] php works but only conditionally


InO

Recommended Posts

let me explain.  here is my code

 

<?php

 

$connection = mysql_connect("localhost","root","thetrap") or die ("couldn't connect to server");

$db = mysql_select_db("socialtemp",$connection) or die ("couldn't select database");

$query = "Select * FROM users";

$result = mysqli_query($query) or die("query failed :" . mysql_error());

echo "<TABLE BORDER='1'>";

echo "<TR>";

echo"<TH>Name</TH><TH>Number</TH>";

echo "</TR>";

 

while ($row = mysql_fetch_array($result)){

echo "<TR>";

echo "<TD>", $row['name'], "</TD><TD>",

$row['number'],"</TD>";

echo "</TR>";

}

echo "</TABLE>";

echo "hello";

mysql_close($connection);

?>

 

the script will not return anything.  no errors, nothing.  however if i just write echo "working" working will display in the browser.  I'm wondering if it's my configuration something in the code i don't know.  Any help would be greatly appreciated.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/59072-solved-php-works-but-only-conditionally/
Share on other sites

First, surround code with [code] and [/code] tags to make it easier to read.

 

Try your script again, right-click in some empty space on your browser and "View Source"

 

Paste what you see here (using code tags!) and we'll go from there.

thanks for the responses, i changed mysqli but i have another problem as well.  my php.ini is set to display errors off and i've been trying to change the setting, i've restarted apache, looked for multiple files and everything.  this is why i can't get any errors returned.  also what do you mean be by code tags, html tags?  let me know and i'll do it. 

 

this is entire script

 

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

<?php

$connection = mysql_connect("http://www.hotmail.com","","") or die ("couldn't connect to server");

$db = mysql_select_db("socialtemp",$connection) or die ("couldn't select database");

$query = "Select * FROM users";

$result = mysql_query($query) or die("query failed :" . mysql_error());

echo "<TABLE BORDER='1'>";

echo "<TR>";

echo"<TH>Name</TH><TH>Number</TH>";

echo "</TR>";

while ($row = mysql_fetch_array($result)){

echo "<TR>";

echo "<TD>", $row['name'], "</TD><TD>",

$row['number'],"</TD>";

echo "</TR>";

echo "hello";

}

echo "</TABLE>";

//echo "hello";

mysql_close($connection);

 

?>

</body>

</html>

 

when i view the source code in the browser i get this

 

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

<?php
$connection = mysql_connect("http://www.hotmail.com","","") or die ("couldn't connect to server");
$db = mysql_select_db("socialtemp",$connection) or die ("couldn't select database");
$query = "Select * FROM users";
$result = mysql_query($query) or die("query failed :" . mysql_error());

echo "<TABLE BORDER='1'>";
echo "<TR>";
echo"<TH>Name</TH><TH>Number</TH>";
echo "</TR>";
while ($row = mysql_fetch_array($result)){
echo "<TR>";
echo "<TD>", $row['name'], "</TD><TD>",
$row['number'],"</TD>";
echo "</TR>";
echo "hello";
}
echo "</TABLE>";
//echo "hello";
//mysql_close($connection);

?>

when i view the source code i get this

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

 

Generally means your error_reporting is set to too low or display_errors is turned off.

 

www.php.net/init_set

 

init_set('display_errors', 'on');
error_reporting(E_ALL);

 

Add those to the top and see if an error comes out.

found out what the problem is.  thanks for all the help.  for one i was changing the display_errors in the php.ini in the wrong place i.e the description, also my version doesn't seem to have mysql support so i was getting Fatal error: Call to undefined function mysql_connect().

guess i'm going to have to reinstall.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.