0

In my document I recive and $_GET, this array I handle and build my query. Then I try to run it. I get a blank page.

if (isset($_GET['submit'])) {
  
  $skip = 0;
  foreach($_GET as $key => $value)
  {
   if($skip++ > 1) {
       if(!empty($value))
       {
        $link = new mysqli('IP-NUMBER', 'LOGIN', 'PASSWORD', 'DATABASE');

           $values = explode("_", $key);
        $insert_query = "INSERT INTO texts (language, parent_id, text) VALUES (?, ?, ?)";
        
        if($stmt = $mysqli->prepare($insert_query)){
         $stmt->bind_param("sis", $values[0], $values[1], $value);
         $stmt->execute();
         $stmt->close();
        }

       }
   }
  }
 }

if (isset($_GET['submit'])) {
  
  $skip = 0;
  foreach($_GET as $key => $value)
  {
   if($skip++ > 1) {
       if(!empty($value))
       {
        $link = new mysqli('IP-NUMBER', 'LOGIN', 'PASSWORD', 'DATABASE');
        
           $values = explode("_", $key);
        $insert_query = "INSERT INTO texts (language, parent_id, text) VALUES ('".$values[0]."', ".$values[1].", '".$value."')";
        
        if ($result = $mysqli->query($insert_query)) {
         echo "Yes!";
        }

       }
   }
  }
 }

None of the above work, both produce an blank page. And yes $value[1] is an int.

What easy noob mistake am I making here?

swe_mattias
  • 621
  • 1
  • 8
  • 15
  • why this: `if($skip++ > 1)` you might want to use only `if($skip >= 1)` and at the end of the foreach loop add `$skip++` – SuperDJ Jul 10 '15 at 12:03
  • Are you sure you got something in `$_GET['submit']`? Try `var_dump($_GET);` before your first `if` just to make sure how exactly your `$_GET` variable looks like. – Dekel Jul 10 '15 at 12:06
  • I would expect a blank page from the first example because you are not printing anything to the page. – HenryTK Jul 10 '15 at 12:07

1 Answers1

1

In the first snippet,

if($stmt = $mysqli->prepare($insert_query))  // What is $mysqli?

$link is your connection object. Replace $mysqli with $link.

Abey
  • 1,408
  • 11
  • 26