2
    <div class="contact-forum">

    <h1>Contact Forum</h1>
    <div class="contact-enters">
    <form action="Home.php" method="post">
        <div class="firstname">
            <p>First Name:</p> </div>  <input type="text" name="firstname" placeholder="FirstName" /> <br />

        <div class="lastname">
            <p> LastName: </p></div> <input type="text" name="lastname" placeholder="LastName" /> <br />

        <div class="Email">
            <p> Email: </p></div>  <input type="text" name="email" placeholder="E-mail" /> <br />

        <div class="topic">
            <p>Topic: </p> </div><input type="text" name="topic" placeholder="Topic" /> <br />


     <div class="message">
        <p> Message: </p> </div> <div class="message-box"><input type="text" name="message" /></div> <br /> 

        <input type="submit" name="Send" />
    </form>
    </div>
</div>

<div class="php">
<?php

$con = mysqli_connect("localhost", "KyleLongrich", "Cash7144") or die('can not connect to server');

mysqli_select_db($con,"kylelongrich") or die("could not connect to database");


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

$Firstname = strip_tags($_POST['firstname']);
$Lastname = strip_tags($_POST['lastname']);
$Email = strip_tags($_POST['email']);
$Topic = strip_tags($_POST['topic']);
$Message = strip_tags($_POST['message']);

$email_query = mysqli_query($con,"SELECT Email FROM emailquestions WHERE Email ='$Email'") or die("Could not check email");
$count_email = mysqli_num_rows($email_query);

if ($count_email > 0)
{
    echo 'Your email is alread in use';
}


$sql = "INSERT INTO emailquestions (Firstname, Lastname, Email, Subject, Message) VALUES ('$Firstname','$Lastname','$Email','$Topic','$Message')";

mysqli_query($con, $sql);

$message = 'Your message has been sent';

}


$message='';



?>

When being displayed the submit button when hit won't send anything or work at all. no php code errors come back but it will not work properly. Could it be because of the the styling? Any help would be great

8
  • dont know if could change anything if you close the tags with /> instead? Commented Feb 6, 2016 at 0:58
  • 2
    There is no such thing as a "php submit button". HTML defines such a button though... Commented Feb 6, 2016 at 1:02
  • Styling has nothing to do with how a form works. What do you actually mean by "wont work at all". Does a request get sent to your server? Do you see an entry in the http servers access log file? Does your browsers development console show a network request? Commented Feb 6, 2016 at 1:06
  • Is your file name home.php? Commented Feb 6, 2016 at 2:58
  • error_reporting() chk erros home.Php same file? Commented Feb 6, 2016 at 3:06

3 Answers 3

1

try to else after your if statement, and use SET in your query.

if ($count_email > 0)
{
echo 'Your email is alread in use';
}
else
{
$sql = "INSERT INTO emailquestions SET         
 (Firstname, Lastname, Email, Subject,   
 Message) VALUES   
     ('$Firstname','$Lastname','$Email','$Topic','$Message')";

mysqli_query($con, $sql);

$success_message = 'Your message has been        
sent';
echo $success_message;
}

hope it helps

Sign up to request clarification or add additional context in comments.

Comments

1

This is a little bit unrelated but I think it will help. You're using mysqli but I would suggest that you use PDO to connect to your database instead. It's safer and easy to expand in the future. Here is an example of how to connect to your database with PDO.

<?php

  $myUser = "XXXXXX";
  $myPass = "XXXXXX";

  try{

    $dbPDO = new PDO('mysql:host=localhost;dbname=xxxxxxxx', $myUser, $myPass);
    $dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    echo "Connection was successful";

  } catch(PDOException $e){

    print "Error!: " . $e->getMessage() . "<br />";
    die();

  }

?>

Simply change the Xs to your server's settings. I would store this in its own file and just include it in all your future files by using something like include_once('dbConn.php');.

When you want to start a query simply you can do it like so:

$query = $dbPDO->prepare("SELECT * FROM Table_Name");
$query->execute();

Of course you'd want to pass variables to your queries so you can do that like this:

$query = $dbPDO->prepare("SELECT * FROM Table_Name WHERE ID = :id");
$query->bindParam(':id', $id);
$query->execute();

That keeps SQL injection off your worries. Just make sure to sanitize your variables before binding them to the query as well.

Passing variables directly into your queries makes you vulnerable to SQL injection, which PDO helps to prevent by binding variables to the query.

Comments

1

Your have to close your contact-enters div. Try flowing code.

<h1>Contact Forum</h1>
    <div class="contact-enters">
    <form action="Home.php" method="post">
        <div class="firstname">
            <p>First Name:</p> </div>  <input type="text" name="firstname" placeholder="FirstName"> <br />

        <div class="lastname">
            <p> LastName: </p></div> <input type="text" name="lastname" placeholder="LastName"> <br />

        <div class="Email">
            <p> Email: </p></div>  <input type="text" name="email" placeholder="E-mail"> <br />

        <div class="topic">
            <p>Topic: </p> </div><input type="text" name="topic" placeholder="Topic"> <br />


     <div class="message">
        <p> Message: </p> </div> <div class="message-box"><input type="text" name="message"></div> <br /> 

        <input type="submit" name="Send">
    </form>
    </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.