0

I have a form that is submitted to a php script with jquery and ajax, but turning out blank in the php script.

form:

<table id="coachapplication">

<form id="coachapplicationform" action="" method="post">

<tr><td>Briefly explain your teaching methods:<br /> <textarea maxlength="100" name="coachmethods" id="coachmethods"></textarea></td></tr>

<tr><td><input type="checkbox" value="yes" name="agree" id="agree" /> I am fully prepared to take on the responsibilities of being a coach which include logging into the website daily and hosting sessions.

<tr><td><button id="submitcoachapplication" type="button">Submit</button></td></tr>

</form>

</table>

jquery script:

$('#submitcoachapplication').click(function() {

$.ajax({

type: "POST",

url: "includes/sendcoachapplication.php",

data: $("form#coachapplicationform").serialize(),

success: function(msg){

    $("#coachapplication").html(msg);

}

});

});

php script:

<?php

session_start();

$user = $_SESSION['username'];

include("dbcon.php");

include("user.php");

$result = mysql_query("SELECT * FROM coachapplications ORDER BY username");

while($row = mysql_fetch_array($result)) {

$username = $row['username'];

if($username == $user) die("You already have a pending application.");

}

$coachmethods = $_POST['coachmethods'];

$coachmethods = mysql_real_escape_string($coachmethods);

$agree = $_POST['agree'];

if($coachmethods == "") die("Please enter some info about how you intend to teach.");

if($agree != "yes") die(" Please agree to the terms.");

$sql="INSERT INTO coachapplications (username, methods) VALUES ('$user', '$coachmethods')";

if (!mysql_query($sql,$con)) die('Error: ' . mysql_error());

echo 'Your application has been submitted, and is awaiting admin approval. If you are found suitable for the program, you will be taught how to use the system.';

mysql_close($con);

?>

1 Answer 1

2

A <form> element is not allowed as a child of <table>. Your browser is likely error correcting by moving it outside the table, which would mean that the <input> elements are no longer inside it.

Put the <table> inside the <form>, not the other way around.

Better yet, don't use tables for layout.

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

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.