-1

Config.php

  $host = 'REMOVED';
  $dbname = 'REMOVED';
  $username = 'REMOVED';
  $password = 'REMOVED';

  try {
  $db = new PDO("mysql:host=".$host.";dbname=".$dbname, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  } catch(PDOException $e) {
    exit($e->getMessage());
  }

The config connects to the server just fine, then I try to insert a row in index.php to the table, and then...

Index.php

require 'config.php';

$text1 = 'teeext';

$text2 = 'teeeext';

$text3 = 'teeeeext';

$db->exec('INSERT INTO users (`row1`, `row3`, `row2`) VALUES ('.$text1.', '.$text2.', '.$text3);

When I run this page, I just get blank, database does not show any rows inserted, even if I run the page 100 times.

Loleris54
  • 35
  • 5
  • 6
    Because running the page 100 times might cause it to work, when it didn't the first time? – random_user_name Oct 11 '17 at 13:52
  • 2
    [PHP's white screen of death](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death). – FirstOne Oct 11 '17 at 13:53
  • 3
    Try using `$db->exec("INSERT INTO users (\`row1\`, \`row3\`, \`row2\`) VALUES ('$text1', '$text2', '$text3')");` – mega6382 Oct 11 '17 at 13:53
  • @mega6382 same shit. – Loleris54 Oct 11 '17 at 13:55
  • See if you can view the error log (for apache it's usually in /var/log/httpd or /var/log/apache2 depending on your distribution). This should tell you the exact problem. If you don't have access you may be able to use a .htaccess file to point it to a file you can view. – Cfreak Oct 11 '17 at 13:55
  • As @mega6382 says, you have a sintax error. It won't work even if you run it 1000000000 times – nacho Oct 11 '17 at 13:55
  • I have updated my comment try that. And also, if any of the values for those variables will be coming from external input, then your code is at risk of sql injection. – mega6382 Oct 11 '17 at 13:59

1 Answers1

-1

There is an syntax error, at the end of the query you didnt close for '.$text3.'

$db->exec('INSERT INTO users (`row1`, `row3`, `row2`) VALUES ('.$text1.', '.$text2.', '.$text3.')');
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Santhosh
  • 142
  • 6