Note that there are some explanatory texts on larger screens.

plurals
  1. POaction if MySQL query is NULL
    text
    copied!<p>What I am trying to do is to send visitor to an error page if query is empty or there is a bad code name? My Current Script echos the following "There will be no hacking on this website!", but this is all happening on the same page where original query is sent from.</p> <p>THe goal is to send visitor to my custom error page that is inside the same folder where the first page is.</p> <pre><code>http://www.example.com/download/file.php http://www.example.com/download/error.php </code></pre> <p>and my current script is</p> <pre><code> &lt;?php $host = 'localhost'; $db_name = 'My_DB_Name'; $db_user = 'MY_User_Name'; $db_pass = '******'; $path_to_file_directory = 'download/files/'; mysql_connect( $host, $db_user, $db_pass); mysql_select_db( $db_name ) or die(mysql_error()); $file_code = filter_input( INPUT_GET, 'urlid' ); # Query for file info $res = mysql_query("SELECT * FROM `Files` WHERE `urlID`='".$file_code."'") or die ( mysql_error() ); # If query is empty, there is a bad code name # This catches possible hacking attempt. if( mysql_num_rows($res) == 0 ) { echo 'There will be no hacking on this website! '; exit(); } # Save file info into an array called "$info" $info = mysql_fetch_assoc($res); # File path is below $file_path = $path_to_file_directory.$info['file_name']; # Now push the download through the browser # There is more than 1 way to do this. if (file_exists($file_path)) { echo '&lt;p&gt;if it does not: &lt;a href="'.$file_path.'"&gt;click here to try again&lt;/a&gt;.&lt;/p&gt;'; exit; } ?&gt; </code></pre> <p>I understand that I have to change the echo to something else, but I have no idea what I have to use instead, since simply placing the link to an error page inside echo will only echo it on my file.php page</p> <p>Please help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload