0

I've created an update page, where users can update their cards. It's working fine on localhost, but I just uploaded it to 000webhostapp and my database doesn't update. I don't get any errors, or anything, it just doesn't update it. I'm using Xampp for the localhost. My update code:

<?php
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', '1');
define('DB_PASSWORD', '2');
define('DB_NAME', '3');

if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] === false){
  header("Location: login.php");
 } else {

$mysqli = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
mysqli_set_charset($mysqli, "utf8");

if($mysqli === false){
    die("failed to connect. " . mysqli_connect_error());
}

$id = $_GET['id'];

if (isset($_POST['sub'])) {
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $phone2 = $_POST['phone2'];
    $email = $_POST['email'];
    $zipcode = $_POST['zipcode'];
    $address = $_POST['address'];
    $company = $_POST['company'];
    $job = $_POST['job'];
    $description = $_POST['description'];
    $userid = $_SESSION['id'];

    if (
      strlen($name) < 31 &&
      strlen($job) < 51 &&
      strlen($zipcode) < 5 &&
      strlen($email) < 51 &&
      strlen($phone) < 21 &&
      strlen($phone2) < 21 &&
      strlen($address) < 51 &&
      strlen($company) < 51 &&
      strlen($description) < 501) {
        $stmt = $mysqli -> prepare('UPDATE cards SET name=?, phone=?, phone2=?, email=?, zipcode=?, address=?, company=?, job=?, description=?, visibility=?, confirmed=?  WHERE id = ?');
        $stmt->bind_param('ssssissssiii', $name, $phone, $phone2, $email, $zipcode, $address, $company, $job, $description, $visibility, $confirmed, $id);
        $success = $stmt -> execute();
      if ($success) {
          echo "Sikeres módosítás!";
    } 
  } else {
        echo $mysqli -> error;
    }    
} 
$getstmt = $mysqli->prepare("SELECT * FROM cards WHERE id= ?");

if ($getstmt and
    $getstmt->bind_param('i', $id) and
    $getstmt->execute() and
    $result = $getstmt->get_result() and
    $row = $result->fetch_assoc()
    ) {

      if($row['userid'] == $_SESSION['id']){
        $name = $row['name'];
        $phone = $row['phone'];
        $phone2 = $row['phone2'];
        $email = $row['email'];
        $zipcode = $row['zipcode'];
        $address = $row['address'];
        $company = $row['company'];
        $job = $row['job'];
        $description = $row['description'];
    }else{
        header("Location: index.php");
    }
 ?>

It is so frustrating because I have absolutely no idea why it doesn't work there if it's working on localhost...

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mower
  • 177
  • 2
  • 10
  • you have to check if the `username` and `password` are right also the `db` host, check the error logs if you have access. – ROOT Feb 25 '20 at 10:51
  • These are right, I just changed them here. How can I check the error logs at 000webhostapp? – Mower Feb 25 '20 at 10:54
  • check `/var/log/php`, `/var/log/nginx` if you are using `Nginx`, `/var/log/apache` folder if you are using `Apache` – ROOT Feb 25 '20 at 10:57
  • That if statement doesn't look right. Why do you even need it? Just enable error reporting instead. – Dharman Feb 25 '20 at 10:58
  • I'm not. Simply dropped my folders to it's file uploader. – Mower Feb 25 '20 at 10:58
  • You should be using utf8mb4 charset. Don't use utf8! – Dharman Feb 25 '20 at 10:59
  • I changed my connection to oop-style, but it still doesn't update my database. I think you are right any there's something bad in my if statement, but what? – Mower Feb 25 '20 at 11:09
  • I never said to change to oop. I told you to enable MySQLi exceptions. – Dharman Feb 25 '20 at 11:11
  • 1
    This is what I get after enabled it: ```Fatal error: Uncaught mysqli_sql_exception: Column 'visibility' cannot be null in /storage/ssd2/322/12606322/public_html/update.php:30 Stack trace: #0 /storage/ssd2/322/12606322/public_html/update.php(30): mysqli_stmt->execute() #1 {main} thrown in /storage/ssd2/322/12606322/public_html/update.php on line 30``` But my bisibility column is auto-null in my database. – Mower Feb 25 '20 at 11:24

1 Answers1

0

The problem was that in my mysli->prepare, I wanted to use the 'visbility' and the 'confirmed' columns, but I don't change them here. Thanks @Dharman for helping me with exceptions. It helped a lot.

Mower
  • 177
  • 2
  • 10