-1

I asked a question yesterday around this, but I have made some adjustments with my code. I am struggling now to get ANY enter to my Database.

HTML (person.html):

<body>

<form id="person" action="personuploader.php" method="post">
      <table class="#"> 
        <tr>
                <th colspan="2">Test 2</th>
            </tr>
            <tr>
                <td>Email Address:</td>
                <td><input type="text" id="email" name="email"> </td>
            </tr>
            <tr>
                <td>Type:</td>
                <td><input type="text" name="type"> </td>
            </tr>
            <tr>
                <td>Cats:</td>
                <td><input type="text" name="cats"> </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Notify Me" name="submit">
            </tr>
        </table>  
    </form>
</body>
</html>

PHP (personuploader.php):

<?php
$con=mysqli_connect("?","?","?","?");
// Check connection

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

if(isset($_POST['submit'])){

if(empty($_POST['email'] || empty($_POST['type']) || empty($_POST['cats']))
{
die("You need to fill in all the fields.");
}

$email = mysqli_real_escape_string($con, $_POST['email']);
$type = mysqli_real_escape_string($con, $_POST['type']);
$cats = mysqli_real_escape_string($con, $_POST['cats']);

$sql="INSERT INTO Persons (`email`, `type`, `cats`) 
VALUES ('$email','$type','$cats')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}

header("Location: http://domain.co.uk/"); exit();

} // end of if(isset($_POST['upload']


else{ echo ("You cannot do this operation from here."); }

mysqli_close($con);
?>

Whereas my previous PHP allowed the entries to populate the Database (open to SQL injection) I am getting no success whatsoever here nor any entries to the database, can someone point the error of my ways here?

Regards

Dan
  • 3
  • 2
  • if not inserted, then you should have been getting error message. are you getting? – Kumar V Jan 07 '14 at 11:52
  • No errors. That's what is baffling me! – Dan Jan 07 '14 at 11:54
  • Are you getting anything show up at all when the script runs? – Joe Jan 07 '14 at 12:05
  • @Dan Please see my edit in [**my answer**](http://stackoverflow.com/a/20960950/1415724) from your previous/original question. The error is shown on top of it. Taking my code and making it as a new question is not right. I worked hard at coming up with a solution for you. You needed to "work with me" instead, and solving this instead. – Funk Forty Niner Jan 07 '14 at 15:55

1 Answers1

0

Try this

<?php
$con=mysqli_connect("?","?","?","?"); //hope you are filling values...
// Check connection

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

if(isset($_POST['submit'])){

if(empty($_POST['email']) || empty($_POST['type']) || empty($_POST['cats']))
{
die("You need to fill in all the fields.");
}

$email = mysqli_real_escape_string($con, $_POST['email']);
$type = mysqli_real_escape_string($con, $_POST['type']);
$cats = mysqli_real_escape_string($con, $_POST['cats']);

$sql="INSERT INTO Persons (`email`, `type`, `cats`) 
VALUES ('$email','$type','$cats')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}

header("Location: http://domain.co.uk/"); exit();

} // end of if(isset($_POST['upload']

 ?> 

problem found if(empty($_POST['email']) missing )

user1844933
  • 3,296
  • 2
  • 25
  • 42