0

Very new to php. Trying to make an 'add contacts' function. Looked around but still struggling. When I try to add a contact, it just says there is an error with the very last line. It was working before but I changed $res. The page also fails to redirect back to crud/view.php, I think I may have ordered it wrong or put in the wrong syntax. Cheers.

<?php
session_start();
if(isset($_SESSION['u_uid'])){

require_once('connect.php');

if(isset($_POST) & !empty($_POST)){
     $name =  mysqli_real_escape_string($connection,$_POST['name']);
     $comp =  mysqli_real_escape_string($connection,$_POST['comp']);
     $title =  mysqli_real_escape_string($connection,$_POST['title']);
     $phone =  mysqli_real_escape_string($connection,$_POST['urstel']);
     $email =  mysqli_real_escape_string($connection,$_POST['email']);
     $location =  mysqli_real_escape_string($connection,$_POST['location']);

    $uid = ($_SESSION['u_id']);


    $CreateSql = "INSERT INTO `contact` (Name, Company, Title, Phone, Email, Address, users_id) VALUES ('$name', '$comp', '$title', '$phone', '$email', '$location', '$uid')";

    $res = mysqli_query($connection, $CreateSql);
       if ($res){
        echo header('location: crud/view.php');
        echo $smsg = "successfully deleted contact.";
        } else{ 
        echo $fmsg = "failed to delete.";
         }
         }
 ?>

 <!DOCTYPE html>
 <html>
 <head>
 <title>Add contacts</title>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
 </head>
 <body>
 <div class="container">
 <div class="row">
    <form method="post" class="form-horizontal col-md-6 col-md-offset-3">
        <h2>Motoko Insurance Contacts</h2>
        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Name</label>
            <div class="col-sm-10">
              <input type="text" name="name"  class="form-control" id="input1" placeholder="Name" />
            </div>
        </div>

        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Company</label>
            <div class="col-sm-10">
              <input type="text" name="comp"  class="form-control" id="input1" placeholder="Company" />
            </div>
        </div>

        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Title</label>
            <div class="col-sm-10">
              <input type="text" name="title"  class="form-control" id="input1" placeholder="Title" />
            </div>
        </div>


        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Phone</label>
            <div class="col-sm-10">
              <input type="int" name="urstel"  class="form-control" id="input1" placeholder="Phone" />
            </div>
        </div>

        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Email</label>
            <div class="col-sm-10">
              <input type="email" name="email"  class="form-control" id="input1" placeholder="E-Mail" />
            </div>
        </div>

        <div class="form-group">
            <label for="input1" class="col-sm-2 control-label">Address</label>
            <div class="col-sm-10">
              <input type="text" name="location"  class="form-control" id="input1" placeholder="Address" />
            </div>
        </div>

        <input type="submit" class="btn btn-primary col-md-2 col-md-offset-10" value="submit" />
    </form>

 </div>
 </div>
 </body>
 </html>         
kerry sun
  • 68
  • 11

0 Answers0