I'm new to PHP and mysql (so you're warned ;) ). i'm making a videogame database ( with XAMPP) and something goes wrong when I try to update my game data. It says the update went fine but the only all the spaces are now blank except for the title. Can some see why this is happening??



        <link rel="stylesheet" type="text/css" href="opmaak.css">


         <!-- Banner-->
        <div id="header">
            <div class="innertube">
                <h1>Gamechick1988's Gaming Database  </h1>
                <img id="logo" src="image.png" alt="logo.png" title="gamertag"/>

       <!-- Gedeelte vlak onder de header-->
       <div id="wrapper">


                <div id="content">
                    <div id="toevoegen">

                        if ((isset($_SESSION["gebruikersnaam"])) AND (isset($_SESSION["wachtwoord"])))
                            //database connectie maken
                            //variable aanmaken van de server

                            $servername= "localhost";
                            $username = "root";
                            $password = "";

                            //variable database-naam en tabelnaam

                            $dbname = "gamingdatabase";

                            //connectie maken

                            $conn = mysqli_connect($servername, $username, $password, $dbname);
                            // connectie controleren

                            if (!$conn)
                                die("Connectie mislukt:" . mysqli_connect_error());

                                echo "";

                            $titel = $_POST["titel"];
                            $platform= $_POST["platform"];
                            $genre = $_POST["genre"];
                            $publisher = $_POST["publisher"];
                            $se = $_POST["se"];
                            $finished = $_POST["finished"];
                            $copy = $_POST["copy"];

                                echo "Er werd op de knop toevoegen gedrukt </br>";

                                $sql = "INSERT INTO games(titel, platform, genre, publisher, se, finished, copy) VALUES('$titel', '$platform', '$genre', '$publisher', '$se', '$finished', '$copy')";

                                if($conn->QUERY($sql) === TRUE)
                                    echo ("De game is succesvol toegevoegd </br>");
                                    echo "Error, geen gegevens toegevoegd aan DB";

                                echo "Er werd op de knop wijzigen gedrukt </br>";
                                $sql="UPDATE games SET platform='.$platform.', genre='.$genre.', publisher='.$publisher.', se='.$se.', finished='.$finished.', copy='.$copy.' WHERE titel ='.$titel.'";
                                //Controleren of de gegevens worden gewijzigd
                                if ($conn->query($sql) === TRUE)
                                    echo ("De game is succesvol gewijzigd<br>");
                                    echo "Error, geen gegevens gewijzigd in DB";

                        //connectie met server sluiten nadat al de data werd opgehaald  


                              header('location: index.php');


        <nav id="nav">
                <div class="innertube">
                    <h3>Mijn collectie</h3>
                        <li><a href="toevoegen.php">Een game toevoegen/wijzigen</a></li>
                        <li><a href="opvragen.php">Mijn games opvragen</a></li>
                        <li><a href="verwijderen.php">Een game verwijderen</a></li>
                        <li><a href="consolestoevoegen.php"> Een console toevoegen </a></li>
                        <li><a href="consolesopvragen.php"> Mijn consoles opvragen </a></li>
                        <li><a href="rapport.php"> Mijn rapport opvragen </a></li>

                        <form id="aanmelden" action= "index.php" method="post">
                            <label class="logoutLblPos">
                                <input type= "submit" name="afmelden" id="afmelden" value="Afmelden"/>




        <footer id="footer">
            <div class="innertube">
                <a href="index.php"> Loginscherm </a>|<a href="toevoegen.php"> Een game toevoegen/wijzigen </a>|<a href="opvragen.php"> Games opvragen </a>|
                <a href="verwijderen.php"> Een game verwijderen </a>|<a href="consolesopvragen.php"> Mijn consoles opvragen </a>|<a href="consolestoevoegen.php"> Een console toevoegen </a>|
                <a href="rapport.php"> Mijn rapport opvragen </a>|



1 Year
Discussion Span
Last Post by diafol
$sql="UPDATE `games` SET `platform` ='$platform', `genre` = '$genre', `publisher` = '$publisher', `se` = '$se', `finished` = '$finished', `copy` ='$copy' WHERE `titel` = '$titel'";

Try that - it should work for you, if your fieldnames are correct. However - you MUST sanitize your variables before directly placing them into an SQL statement, otherwise you run the risk of SQL injection - where users could delete or get hold of ALL your data. As you're using mysqli - you can use mysqli_real_escape_string to sanitize your variables.

You also seem to be using a mish-mash of OOP and procedural style with mysqli - this can't work. Use one or the other.

Try not to mix up HTML and PHP like this as it will become very difficult to maintain. When you get a little more confident, you can write functions and hide them away in pure php files and call them after you include / require them.

See my tutorial for some basics - it may help: https://www.daniweb.com/programming/web-development/tutorials/499320/common-issues-with-mysql-and-php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.