Difficulty adding PHP MYSQL data

Asked

Viewed 49 times

0

Well, the title itself is self-explanatory. Perhaps the only relevant detail I can add, is the fact that when performing the operation I get no error, nor Warning.

Thank you in advance for your answers.

    <?php

        if($_POST){
        ///conexao 
        $con = mysqli_connect('localhost', 'root','','SocialNetwork');

        if (mysqli_connect_errno())
        {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }

        ///variaveis
        $name = $_POST['name'];
        $description = $_POST['description'];
        $maxguest = $_POST['maxguest'];
        $currentguest = $_POST['currentguest'];
        $address = $_POST['address'];
        $privacy = $_POST['privacy'];


        ///insercao dos elementos no banco de dados
        $query = "INSERT INTO `events`(`name`, `description`, `maxguest`, `currentguest`, `address`, `privacy`) VALUES ('$name', '$description', '$maxguest', '$currentguest', '$address', '$privacy')";

        mysqli_query($con,$query or die(msqli_error($con)));
    }

?>

<h1>New event</h1>
<form class="form" action="newEvent.php" method="post" enctype="multipart/form-data" autocomplete="off"><br><br>
    <input type="text" name="name" value="" placeholder="partys name" required /><br><br>
    <input type="text" name="description" value="" placeholder="description" required /><br><br>
    <input type="number" name="maxguest" value="" placeholder="guests limit" required /><br><br>
    <input type="number" name="currentguest" value="" placeholder="current guests" required /><br><br>
    <input type="text" name="address" value="" placeholder="address" required /><br><br>
    <input type="radio" name="privacy" value=0 checked>Public<br><br>
    <input type="radio" name="privacy" value=1>Private<br><br>
    <input type="submit" name="newParty" value="new party!"/>
</form>
  • mark as answer accepted

1 answer

1


What is not letting add data is

mysqli_query($con,$query or die(msqli_error($con)));

 <?php
 if($_POST){
    ///conexao 
    $con = mysqli_connect('localhost', 'root','SENHA','SocialNetwork');


    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    ///variaveis
    $name = $_POST['name'];
    $description = $_POST['description'];
    $maxguest = $_POST['maxguest'];
    $currentguest = $_POST['currentguest'];
    $address = $_POST['address'];
    $privacy = $_POST['privacy'];

    mysqli_query($con,"INSERT INTO `events`(`name`, `description`, `maxguest`, `currentguest`, `address`, `privacy`) VALUES ('$name', '$description', '$maxguest', '$currentguest', '$address', '$privacy')") or die(mysqli_error($con));
}

?>
  • That. How the exit is Connection1 I realized that there was the type cast in the variable.

  • Thanks man, that’s right

Browser other questions tagged

You are not signed in. Login or sign up in order to post.