Skip to content

Commit

Permalink
FIX: Updating no longer updates entire databse without fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hippo23 committed Jul 30, 2022
1 parent 151ed89 commit 46a0edd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/act4.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php session_start(); ?>
<?php include './database.php'; ?>

<!DOCTYPE HTML>
<html class='h-auto w-full bg-white'>
Expand All @@ -15,7 +16,6 @@
</head>

<body class='w-full h-auto m-0 p-0 text-base border-none'>
<?php include './database.php'; ?>
<div class='w-full h-screen h-screen flex lg:flex-row flex-col items-center justify-around bg-white'>
<?php include './masthead.php'; ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/create_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
</svg>
<div>
<span class="font-medium">Submission failed!</span> Please fill up all required fields.
<span class="font-medium">Submission failed!</span> Please fill up all fields.
</div>
</div>
<div class="w-full h-full flex lg:flex-row flex-col justify-around items-center">
Expand Down
2 changes: 1 addition & 1 deletion src/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'poemon');
define('DB_NAME', 'pokemon');

try {
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
Expand Down
5 changes: 2 additions & 3 deletions src/logic/form_logic.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,21 @@
}
}


$query = "UPDATE Pokemons SET ";

if (count($conditions) > 0) {
$query .= implode(', ', $conditions);
}

$query .= ' ' . $_SESSION['update_data'];
echo $query;

if ($query != 'UPDATE Pokemons SET ' && $_SESSION['update_data'] != '') {
if (!mysqli_query($conn, $query)) {
echo 'There is no matching pokemon in the database.';
}
$data = mysqli_fetch_all(mysqli_query($conn, "SELECT * FROM Pokemons " . $_SESSION['update_data']), MYSQLI_ASSOC);
}

$data = mysqli_fetch_all(mysqli_query($conn, "SELECT * FROM Pokemons " . $_SESSION['update_data']), MYSQLI_ASSOC);
}

?>

0 comments on commit 46a0edd

Please sign in to comment.