Connect to database with mysqli

@Freeranger said:
I do just have to recreate the code, some parts dissappeared… :cry:

I have one more question too:

If I want to upload for example a minecraft mod, the file size is over 200mb, is there any way I can still make the downloadable?

Thanks

Yes, you can upload it to a specialized file hosting service where they allow larger files and share the link on your website. Sharing large files from a website hosting account is always a bad idea.

Thanks!

Back to the normal subject of the question:

For some reason, this code gives me a HTTP 500 error. Do anyone know why?

<?php
  require_once 'connect.php';
  if(isset($_GET['keywords'])){
      $keywords = $db->escape_string($_GET['keywords']);
      $query = $db->query("
         SELECT id, title, description
         FROM search_product
         WHERE id LIKE '%{$keywords}%'
         OR title LIKE '%{$keywords}%'
         OR decription LIKE '%{$keywords}%'
      ");
     ?>
      <div class="result-count">
          Found <?php $query->num_rows;?> results.  
      </div>
   
  }

Thanks!

@Freeranger said:
Thanks!

Back to the normal subject of the question:

For some reason, this code gives me a HTTP 500 error. Do anyone know why?

<?php
  require_once 'connect.php';
  if(isset($_GET['keywords'])){
      $keywords = $db->escape_string($_GET['keywords']);
      $query = $db->query("
         SELECT id, title, description
         FROM search_product
         WHERE id LIKE '%{$keywords}%'
         OR title LIKE '%{$keywords}%'
         OR decription LIKE '%{$keywords}%'
      ");
     ?>
      <div class="result-count">
          Found <?php $query->num_rows;?> results.  
      </div>
   
  }

Thanks!

Did you check your error logs?

Regarding your code, I see two things:

  • A variable $db for which I can’t see what it is.
  • No error checking whatsoever. No exceptions are being caught and no connection errors are being checked.

Thanks, but how can i define $db?

Edit: It’s defined in connect.php

$db = new MySQLi($hostname, $username, $password, $database);

Regardless of what $db is, a 500 error means your script crashes and your error logs should have more information. If they don’t, try to enable PHP display errors (can be found under Alter PHP Config in the control panel) to see if you can figure out the actual error.

Ok, so I get this message:

Parse error: syntax error, unexpected end of file in /home/vol11_3/epizy.com/epiz_21490173/htdocs/search.php on line 19

Here’s the code:

<?php
  require_once 'connect.php';
  
  if(isset($_GET['keywords'])){
      
      $keywords = $db->escape_string($_GET['keywords']);
      $query = $db->query("
         SELECT id, title, description
         FROM search_product
         WHERE id LIKE '%{$keywords}%'
         OR title LIKE '%{$keywords}%'
         OR decription LIKE '%{$keywords}%'
      ");
     ?>
      <div class="result-count">
          Found <?php $query->num_rows;?> results.   
      </div>
  }

The last row is number 19. I can’t figure out what’s wrong!

Thanks

when you have an unexpected end of file in the line
check all the brackets and put space between the code and end ?>

Do you know where it can be? At least, I can’t find it…

sure :wink:
use this https://phpcodechecker.com/
or other tool online

Says the same :frowning:

more help PHP Error Decoder | PHP Reference Book Blog

Thanks! Think I’ve fixed that part, but now I get this error:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘epiz_21490173’@‘192.168.0.50’ (using password: YES) in /home/vol11_3/epizy.com/epiz_21490173/htdocs/connect.php on line 6

Warning: mysqli::escape_string(): Couldn’t fetch mysqli in /home/vol11_3/epizy.com/epiz_21490173/htdocs/search.php on line 6

Warning: mysqli::query(): Couldn’t fetch mysqli in /home/vol11_3/epizy.com/epiz_21490173/htdocs/search.php on line 12

Found results.

maybe this PHP: require - Manual

and http://phptester.net/

Thanks, but I think the problem has with this to do:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘epiz_21490173’@‘192.168.0.50’ (using password: YES) in /home/vol11_3/epizy.com/epiz_21490173/htdocs/connect.php on line 6

Any idea of why my access gets denied?

Fixed that part, but now, I don’t get any number inside found results. Does this have with this code to do?

`<?php
require_once (‘connect.php’);

if(isset($_GET[‘keywords’])){

  $keywords = $db->escape_string($_GET['keywords']);
  $query = $db->query("
     SELECT id, title, description
     FROM search_product
     WHERE id LIKE '%{$keywords}%'
     OR title LIKE '%{$keywords}%'
     OR decription LIKE '%{$keywords}%'
  ");

}
?>

  <div class="result-count">
      Found <?php $query->num_rows; ?> results.   
  </div>

`

Fixed it! This discussion can be closed! :slight_smile:

1 Like

I should have an insight into everything you do…but…

Thanks for the help!

I’m glad you did and you should be proud of yourself !