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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

One thing I do is uplaoded my code straight to some web space I'm renting.

 

Saves me having to install oodles of files on my PC although the big problem is that I have to be online while writing anything which isn't a problem for me.

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.