
|
View Full Version : Setting up a personal server - Problems
Deposeni 05-06-2003, 03:46 PM I've recently setup a personal server on my Win98SE box, using Apache (Newest), PHP (Newest), and MySQL(Newest) - it all works fine, expect for one minor detail...
Notice: Undefined index: title in C:\apache\htdocs\main.php on line 17
Notice: Undefined index: date in C:\apache\htdocs\main.php on line 17
Notice: Undefined index: date in C:\apache\htdocs\main.php on line 17
Notice: Undefined index: user in C:\apache\htdocs\main.php on line 17
Title: Date Posted: 12/31/69 Time: 18:00 Posted by:
Notice: Undefined index: news in C:\apache\htdocs\main.php on line 21
I get that whenever I try to run my "Portal Script" on my server, line 17 is...
print "<td><strong>Title:</strong> ".$row['title']." <strong>Date Posted:</strong> ".date("m/j/y", $row['date'])." <strong>Time:</strong> ".date("H:i", $row['date'])."<strong> Posted by:</strong> ".$row['user'];
And line 21 is
print $row['news'];
This script works FINE on my linux box (Was pre-setup when I bought it), I merely copied the database over from that to my personal server...
Could it be my configurations? I just installed php, mysql, and apache, and didn't configure anything besidse the default directories...
kmalik 05-06-2003, 04:52 PM the only thing i can suggest is to check and compare the phpinfo() output on both machines...
Deposeni 05-06-2003, 05:34 PM Where's that?
kmalik 05-06-2003, 05:41 PM creat a file called phpinfo.php in the root directory with the following content...
<? phpinfo() ?>
Xerpher 05-06-2003, 05:47 PM Heh, you don't need to do anything with phpinfo();
What you need to do is edit your php.ini file, go to line 260 or around there where it says
error_reporting = E_ALL; display all errors, warnings and notices
That is the default.. it shows every little problem you make in your script, and the way your checking for variables (it still works but is not the proper way) is why its giving you notices (its improper because variables need to be fully defined before accessing them). But the most likely reason that your getting these messages is because its not finding the data your looking for in the database, try to change the "E_ALL" to "E_ALL & ~E_NOTICE" like so:
error_reporting = E_ALL & ~E_NOTICE; display all errors, warnings and notices
The php.ini file is most often in your windows system directory on a windows server, on linux I have no idea
Deposeni 05-06-2003, 05:50 PM Notices and errors are gnoe, problem still remains...
Title: Date Posted: 12/31/69 Time: 18:00 Posted by:
Date and time and Posted by all work fine on my other linux box, but not on my window box....
Xerpher 05-06-2003, 06:04 PM Then you screwed up as far as the database goes or the mysql query, because the query isn't returning ANY data that you think it should be. Show your full query.
Deposeni 05-06-2003, 06:12 PM How about the entire PHP part of the file?
<?php
$conn = mysql_connect ("localhost", "root", "");
mysql_select_db("testDB", $conn);
//date("m/j/y", $row['date'])
//date("H:i", $row['date'])
$gettime = mysql_query("SELECT * FROM news ORDER BY date LIMIT 0, 10");
print "<table width=\"50%\" boarder=\"2\">";
while ($row = mysql_fetch_array($gettime, $conn)){
print "<tr>";
print "<td><strong>Title:</strong> ".$row['title']." <strong>Date Posted:</strong> ".date("m/j/y", $row['date'])." <strong>Time:</strong> ".date("H:i", $row['date'])."<strong> Posted by:</strong> ".$row['user']."";
print "</td></tr>";
print "<tr>";
print "<td>";
print $row['news'];
print "<br><br>";
print "</td>";
print "</tr>";
}
print "</table>";
?>
Xerpher 05-06-2003, 06:26 PM First of all, are you absolutely sure the db is all filled out properly?
If so then change your query to "SELECT * FROM news" and at the end of your code inside the while statement put print_r($row);
Xerpher 05-06-2003, 06:41 PM Just to let everyone know, since I helped him fix it over MSN Messenger, he needed to change:
while ($row = mysql_fetch_array($gettime, $conn)){
to:
while ($row = mysql_fetch_array($gettime, ASSOC)){
kmalik 05-06-2003, 07:43 PM whats the difference?
Xerpher 05-07-2003, 10:52 AM The difference is that your not supposed to put the connection id in that function. You instead need to add an optional constant to the function to decide whether it will return an array with the row data in numerated form or associated names form. For example, if you had a table with three fields, id, name, and data, then numerated would return $row[0] = id, $row[1] = name, and $row[2] = data., while associated would return $row['id'] = id, $row['name'] = name, and $row['data'] = data.
Deposeni's problem was that his code assumed that it was associated but since $conn, which is what he used, did not return the constant value of either numerated or associated, it used its default which is numerated form.
kmalik 05-07-2003, 03:25 PM hey! thanks for the explaination..
|