Jump to content

Database error 404


Deks1948

Recommended Posts

So you are accessing http://localhost/ and you immediately get a 404 error? Does directly accessing a file resolve ok?, eg http://localhost/somefile.php

 

If no, then there appears to be an issue with your (Apache) http server config. How have you configured/setup Apache?

Link to comment
https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474182
Share on other sites

functions.php 

<?php

function get_menu() {

$r = mysql_query ("select * from cats");

$result = "<a href=index.php>Main page</a><br>"; 

while ($row=mysql_fetch_array($r)) 
  $result .= "<a href=index.php?p=filter&cat=$row[id]>$row[cname]</a><br>";
  
return $result;

}

function get_comments($id) {
$id = strip_tags($id);
$result = "";
if (is_numeric($id)) {
$r = mysql_query("select * from comments where rid=$id order by id desc");

while ($row=mysql_fetch_array($r)) {
 $dt = date('d-m-Y', $row[dt]);
 $result .= "<hr><a href=mailto:$row[email]>$row[uname]</a> ($dt) <p>$row[txt]";
 }

}
else $result = "Wrong argument in get_comments()";

return $result;
}

function get_blog_record($id) {

$id = strip_tags($id);
if (is_numeric($id)) {

$r = mysql_query("select * from blog where id=$id limit 1");
$row = mysql_fetch_array($r);
$dt = date('d-m-Y', $row[dt]);

$comments = get_comments($id);

$result = "<h1>$row[header]</h1>
<p>$dt<p>
<b>$row[anonce]</b>
<p>$row[txt]
<p><h2>Comments</h2><p><a href=add_comment.php?id=$id>Add comment</a>$comments";

}
else $result = "Wrong entry ID";


return $result;

}

function get_cat_name($id) {

$id = strip_tags($id);
if (is_numeric($id)) {
$r = mysql_query("select * from cats where id=$id limit 1");

$row = mysql_fetch_array($r);

return $row[cname];

}
else return "Wrong category";


}

function get_cat($id) {

$cat = $_GET[cat];

if (is_numeric($cat)) {

$q="select * from blog where cid=$cat order by id desc";

$r = mysql_query($q);         

$list = "";

while ($row=mysql_fetch_array($r)) {
$dt = date('d-m-Y H:i', $row[dt]);   
    $list .= "<p><table width=100%>
          <tr><td bgcolor=grey width=80%>
          <font color=white>$row[header]</td>
          
          <td bgcolor=grey width=20%>
          <font color=white>$dt</td>
          </tr></table>";

    
    $list .= "<p>$row[anonce]"
    
    $cat = get_cat_name($row[cid]);
    
    $list .= "<p><table width=100%>
          <tr><td width=60%><a href=index.php?p=show&id=$row[id]>Read more</a></td>
          
          <td width=20%>$cat</td>
          <td width=20%>Comments: $row[comments]</td>
          </tr></table>";
          
}
return $list;

}
else return "Wrong category ID";


}
?>

index.php

<?php

include "config.php";

mysql_connect($server, $username, $password);
mysql_select_db($db);

include "functions.php";



$header = join('', file('header.html'));
$footer = join('', file('footer.html'));

echo $header;



$left = get_menu();   
$content = "";

if (isset($_GET['p'])) {
$p = $_GET['p'];
$id = $_GET['id'];


if ($p == "show") $content = get_blog_record($id);
elseif ($p == "filter") $content = get_cat($cat);
else $content = "Wrong page";

}
else {            

$N = 5;              

$r1=mysql_query("select count(*) as records from blog");
$f = mysql_fetch_row($r1);
$rec_count = $f[0];             

if (!isset($_GET['page'])) $page=0;
else $page = $_GET['page']; 

$records = $page * $N;

$q='select * from blog order by id desc limit '.$records.", $N";

$result = mysql_query($q);           
$max = mysql_num_rows($result);      

if ($page > 0) {
$p = $page - 1; 
$content .= "<a href=index.php?page=$p>Back</a>&nbsp";
}

$page++;                                   


if ($records+$N < $rec_count) 
$content .= "<a href=index.php?page=$page>Next</a>";

for ($i=0; $i<$max; $i++)
{
    $row=mysql_fetch_array($result);
    $dt = date('d-m-Y H:i', $row[dt]);    

    $content .= "<p><table width=100%>
          <tr><td bgcolor=grey width=80%>
          <font color=white>$row[header]</td>
          
          <td bgcolor=grey width=20%>
          <font color=white>$dt</td>
          </tr></table>";

    $content .= "<p>$row[anonce]";
    
    
    $cat = get_cat_name($row[cid]);
    
    $content .= "<p><table width=100%>
          <tr><td width=60%><a href=index.php?p=show&id=$row[id]>Read more</a></td>
          
          <td width=20%>$cat</td>
          <td width=20%>Comments: $row[comments]</td>
          </tr></table>";
}
}

echo "<table border=0 width=100%>
<tr><td valign=top width=20%>$left</td><td valign=top>$content</td></tr></table>
$footer";

?>
Link to comment
https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474251
Share on other sites

Put the following on top of the index.php file:

<?php

ini_set('display_errors',1);

ini_set('display_startup_errors',1);

error_reporting(-1);


To debug database queries use the mysql_error() php function:

mysql_connect($server, $username, $password) or die(mysql_error());

mysql_select_db($db) or die(mysql_error());

$r1=mysql_query("select count(*) as records from blog") or die(mysql_error()); // etc.....
Link to comment
https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474280
Share on other sites

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.