0

most of the keywords here are in norwegian
THIS RIGHT HERE IS THE THING IM HAVING PROBLEMS WITH
it wont display (not even the errors) its supposed to display "bilde" as background image in div boxes so that you upload pictures, but nothing pops up, not even the errors. would be nice if anyone could help me.

if i enable error reporting the site wont load

 $sql = "SELECT bilde FROM meme"; 
$result = $conn->query($sql);

if ($result->num_rows > 0) {
      while($row = $result->fetch_assoc()) {
             echo "<div class='box' style='background-image: url({$row[bilde]});  background-size: 100%; width: 90%; height: 35%;'></div>";
      }
      } else {
           echo "0 results";
      }

here is the insert into database line

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mydb"; //her skriver du navn på databasen

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$bilde = $_REQUEST['bilde'];


$sql = "INSERT INTO meme (bilde) VALUES ('$bilde') ";

if(mysqli_query($conn, $sql)){
    echo "Vellykket";
} else{
    echo "ERROR: Det oppsto en feil <br> $sql. <br><br>";
    echo mysqli_error($conn);
}
echo "<br><br><a href='memepage.php'>Tilbake</a>";

and lastly the form

<form action="insert.php">
       <p class="link">Link her:</p> <br>
       <input type="text" name="bilde"> <br>
       <br>
       <input type="submit" value="Fullfør" method="post">

Kevin
  • 1
  • 4
  • view page source, what does `
    –  May 21 '18 at 21:54
  • 1
    Possible duplicate of [php site wont fetch and display data](https://stackoverflow.com/questions/50455920/php-site-wont-fetch-and-display-data) –  May 21 '18 at 22:17
  • @smith wait what? it doesnt show up in source – Kevin May 21 '18 at 22:22
  • `if i enable error reporting the site wont load` This sounds like an issue in itself...when you turn on reporting, what does the error(s) say? – Rasclatt May 21 '18 at 22:42
  • the site now loads when i enable error reporting but how do i see what the errors are? @Rasclatt – Kevin May 21 '18 at 22:48
  • Well, if you turn on error reporting using `ini_set('display_errors',1); error_reporting(E_ALL);` at the top of your page, you may have the error appear inside a tag so it doesn't show in the browser, but rather in the source of the html, so you look at the source to see if there are any errors. You might have `
    – Rasclatt May 21 '18 at 22:51
  • @Rasclatt $result = $conn->query($sql);
    it said that line 37 was the prob and thats line 37
    – Kevin May 21 '18 at 23:08
  • What is the error though? Can't get property of object or something? – Rasclatt May 21 '18 at 23:19
  • Notice: Undefined variable: conn in /Users/kevin2112/Desktop/It 1/SQL/SKOLEPROSJEKT/memepage.php on line 37 Fatal error: Uncaught Error: Call to a member function query() on null in /Users/kevin2112/Desktop/It 1/SQL/SKOLEPROSJEKT/memepage.php:37 Stack trace: #0 {main} thrown in /Users/kevin2112/Desktop/It 1/SQL/SKOLEPROSJEKT/memepage.php on line 37 – Kevin May 21 '18 at 23:20
  • Your database is not included (or not included properly) so it can't find `$conn`. – Rasclatt May 21 '18 at 23:22
  • THANK YOU SIR U ARE GOLD <3 <3 <3 – Kevin May 21 '18 at 23:25
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Rasclatt May 22 '18 at 21:58

0 Answers0