0

Today i am back with another MySQL problem on my Raspberry.

I have a code which inserts me a user input in the table 'users' on the database 'users' which looks like this:

BTW i know logging in with root is not the safest way but i tried to be sure that i dint messed up my MySQL user.

$mysqli = new mysqli("localhost", "root", "passwd", "users");

$mysqli->query("INSERT INTO `users` (username, email, firstname, lastname, password) VALUES ('$username', '$email', '$fname', '$lname', '$passwdhash')");
$mysqli->commit();

This worked fine until i nuked my Raspberry because i had a problem with my ssh server.

i installed everything new (php, mysql, phpmyadmin, apache2) and now my script isnt working.

I checked the status of my apache and mysql service and both are working fine. (acc. to my Raspberry)

For error catching i tried this:

$success = $mysqli->query('localhost', 'root', 'passwd', 'users');
if (!$success) {
print_r($mysqli->error);
}

I dint know if the problem is my Raspberry or my script so i am asking here to be sure that its not my script that is causing the error.

Thank you for your help.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Tolkosino
  • 43
  • 6

1 Answers1

1

what you are trying is wrong. try like below:-

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$mysqli = new mysqli('localhost', 'root', 'passwd', 'users');

if ($mysqli->connect_errno) {
    echo "Error: Failed to make a MySQL connection, here is why: \n";
    echo "Error: " . $mysqli->connect_error . "\n";
    exit;
}

Note:- check this an i hope you will get either some error or get connected

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • i added an else to your code and this works, i now try to implement that into my script above and see if this works too – Tolkosino Mar 10 '17 at 19:03