Jump to content

ERROR FILLING FORM ON PHP ("Oops! Something went wrong. Please try again later")


itzv4sco

Recommended Posts

Here's my code, whenever I try to fill the form it gives me that error "Oops! Something went wrong. Please try again later"

 

Code: 

<?php
// Include config file
require_once "config.php";
 
// Define variables and initialize with empty values
$CodEntrega = $CodCliente = $Dia = $Pagamento = $Funcionario = "";
$CodEntrega_err = $CodCliente_err = $Dia_err = $Pagamento_err = $Funcionario_err = "";
 
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
    // Validate name
    $input_CodEntrega = trim($_POST["CodEntrega"]);
    if(empty($input_CodEntrega)){
        $CodEntrega_err = "Insira o codigo de entrega";
    } else{
        $CodEntrega = $input_CodEntrega;
    }
    
    // Validate address
    $input_CodCliente = trim($_POST["CodCliente"]);
    if(empty($input_CodCliente)){
        $CodCliente_err = "Insira o codigo do cliente";     
    } else{
        $CodCliente = $input_CodCliente;
    }
    
    // Validate salary
    $input_Dia = trim($_POST["Dia"]);
    if(empty($input_Dia)){
        $Dia_err = "Insira a data da entrega"; 
    } else{
        $Dia = $input_Dia;
    }
    
    $input_Pagamento = trim($_POST["Pagamento"]);
    if(empty($input_Pagamento)){
        $Pagamento_err = "Insira o tipo de pagamento"; 
    } else{
        $Pagamento = $input_Pagamento;
    }
    
    $input_Funcionario = trim($_POST["Funcionario"]);
    if(empty($input_Funcionario)){
        $Funcionario_err = "Insira o codigo do funcionario"; 
    } else{
        $Funcionario = $input_Funcionario;
    }
    
    if(empty($CodEntrega_err) && empty($CodCliente_err) && empty($Dia_err) && empty($Pagamento_err) && empty($Funcionario_err)){
       
        $sql = "INSERT INTO entrega(CodEntrega, CodCliente, Dia, Pagamento, Funcionario) VALUES (?, ?, ?, ?, ?)";
         
        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "ssdss", $param_CodEntrega, $param_CodCliente, $param_Dia, $param_Pagamento, $param_Funcionario);
            
            // Set parameters
            $param_CodEntrega= $CodEntrega;
            $param_CodCliente = $CodCliente;
            $param_Dia = $Dia;
            $param_Pagamento = $Pagamento;
            $param_Funcionario = $Funcionario;
            
            if(mysqli_stmt_execute($stmt))
            {
                header("location: home.html");
                exit();
            } 
            else
            {
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
         
        // Close statement
        mysqli_stmt_close($stmt);
    }
    
    // Close connection
    mysqli_close($link);
}
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
<title>Projeto TW</title>
<link rel="stylesheet" href="css/milligram.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

/* Style the header */
header {
  background-color: #B0171F;
  padding: 30px;
  text-align: center;
  font-size: 35px;
  color: white;
}

/* Create two columns/boxes that floats next to each other */
nav {
  float: left;
  width: 30%;
  height: 300px; /* only for demonstration, should be removed */
  background: #ccc;
  padding: 20px;
}

/* Style the list inside the menu */
nav ul {
  list-style-type: decimal;
  padding: 0;
}

article {
  float: left;
  padding: 20px;
  width: 70%;
  background-color: #f1f1f1;
  height: 300px; /* only for demonstration, should be removed */
}

/* Clear floats after the columns */
section::after {
  content: "";
  display: table;
  clear: both;
}

/* Style the footer */
footer {
  background-color: #B0171F;
  padding-top: 7px;
  padding-bottom: 7px;
  text-align: middle;
  color: white;
  position: relative;
  bottom: 0;

}

#content-wrap {
  padding-bottom: 2rem;    /* Footer height */
}

#page-container {
  position: relative;
 
}

@media (max-width: 600px) {
  nav, article {
    width: 100%;
    height: auto;
  }
}

.dropbtn {
  background-color: #4CAF50;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
}


.dropdown {
  position: relative;
  display: inline-block;
}


.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}


.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}


.dropdown-content a:hover {background-color: #ddd;}


.dropdown:hover .dropdown-content {display: block;}


.dropdown:hover .dropbtn {background-color: #3e8e41;}

</style>
</head>
<body>


<header>
  <div class="head1">PROJETO DE TW</div> 
  <div class="head2">Gestão de uma BD</div>
</header>

<div class='container'>
      <div class='navbar'>
        <ul>
          <li><a class="active" href="home.html">Home</a></li>
          <li><a href="#consultar">Consultar</a></li>
          <li><a href="tabela.html">Inserir</a></li>
          <li><a href="#alterar">Alterar</a></li>
          <li><a href="#eliminar">Eliminar</a></li>
        </ul>
      </div> 
   <div class = "body_sec"> 
      <section id="Content"> 
         <h3>INSERIR DADOS DE ENTREGA</h3>
         <button type="button" >ENTREGA</button>         
      </section>
                    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                        <div class="form-group">
                            <label>CodEntrega</label>
                            <input type="text" name="CodEntrega" class="form-control <?php echo (!empty($CodEntrega_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $CodEntrega; ?>">
                            <span class="invalid-feedback"><?php echo $CodEntrega_err;?></span>
                        </div>
                        <div class="form-group">
                            <label>CodCliente</label>
                            <input type="text" name="CodCliente" class="form-control <?php echo (!empty($CodCliente_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $CodCliente; ?>">
                            <span class="invalid-feedback"><?php echo $CodCliente_err;?></span>
                        </div>
                        <div class="form-group">
                            <label>Dia de Entrega</label>
                            <input type="date" name="Dia" class="form-control <?php echo (!empty($Dia_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Dia; ?>">
                            <span class="invalid-feedback"><?php echo $Dia_err;?></span>
                        </div>
                        <div class="form-group">
                            <label>Pagamento</label>
                            <input type="text" name="Pagamento" class="form-control <?php echo (!empty($Pagamento_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Pagamento; ?>">
                            <span class="invalid-feedback"><?php echo $Pagamento_err;?></span>
                        </div>
                        <div class="form-group">
                            <label>Codigo do Funcionario</label>
                            <input type="text" name="Funcionario" class="form-control <?php echo (!empty($Funcionario_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Funcionario; ?>">
                            <span class="invalid-feedback"><?php echo $Funcionario_err;?></span>
                        </div>
                        <input type="submit" class="btn btn-primary" value="Submit">
                        <a href="home.html" class="btn btn-secondary ml-2">Cancel</a>
                    </form>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>

 

 

Edited by Barand
code tags added
Link to comment
Share on other sites

Use the "<>" button when posting code.

All I can tell you from the information given is "Something went wrong".

Whey don't you get mysqli to tell you what went wrong. The easiest way is to put this line of code just above the line where you create your mysqli connection

 mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.