Jump to content

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

Do you know what a dot notation for db server is? To get the workaround to that $db just to enclose the string with backticks or rename it.

 

Change:

$db = "test.php";

// to

$db = "`test.php`";

//or 

$db = "test_php";
Edited by jazzman1
Link to comment
https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474185
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";

?>
Edited by Deks1948
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

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.