Deks1948 Posted March 27, 2014 Share Posted March 27, 2014 so this is my database name and when i get it to a hosting or anything it just gives me Error 404? <?php $server = "localhost"; $user = "deks"; $password = "cskasofia"; $db = "test.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/ Share on other sites More sharing options...
Ch0cu3r Posted March 27, 2014 Share Posted March 27, 2014 Error 404 has nothing to with databases. You will however get that error if you are requesting for a file which the server cannot find. Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474176 Share on other sites More sharing options...
Deks1948 Posted March 27, 2014 Author Share Posted March 27, 2014 Everything in the other files are Ok, but I thought that it was something to do with my database config file Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474178 Share on other sites More sharing options...
Ch0cu3r Posted March 27, 2014 Share Posted March 27, 2014 How are you getting error 404? Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474179 Share on other sites More sharing options...
Deks1948 Posted March 27, 2014 Author Share Posted March 27, 2014 Error 404 localhost Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9 Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474180 Share on other sites More sharing options...
Ch0cu3r Posted March 27, 2014 Share Posted March 27, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474182 Share on other sites More sharing options...
Deks1948 Posted March 27, 2014 Author Share Posted March 27, 2014 XAMPP. Even if i get it on a hosting that i have I get the same error!?! Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474183 Share on other sites More sharing options...
jazzman1 Posted March 27, 2014 Share Posted March 27, 2014 (edited) 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 March 27, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474185 Share on other sites More sharing options...
Deks1948 Posted March 27, 2014 Author Share Posted March 27, 2014 And still the only thing that loads to my website is the simple main page html... Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474187 Share on other sites More sharing options...
jazzman1 Posted March 27, 2014 Share Posted March 27, 2014 What about to show us all related scrips? I'm not a windows expert but check if all services are started in XAMMP? Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474189 Share on other sites More sharing options...
Deks1948 Posted March 28, 2014 Author Share Posted March 28, 2014 (edited) 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> "; } $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 March 28, 2014 by Deks1948 Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474251 Share on other sites More sharing options...
jazzman1 Posted March 28, 2014 Share Posted March 28, 2014 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..... Quote Link to comment https://forums.phpfreaks.com/topic/287340-database-error-404/#findComment-1474280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.