hi, i have this working code
index.php
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var fname = $('#fname').attr('value');
var lname = $('#lname').attr('value');
$.ajax({
type: "POST",
url: "ajax.php",
data: "fname="+ fname +"& lname="+ lname,
success: function(data){
$('form#submit').hide(function(){$('div.success').fadeIn();});
}});
return false;
});
});
</script>
<div class="container">
<form id="submit" method="post">
<fieldset>
<legend>Enter Information</legend>
<label for="fname">First accountname:</label>
<input id="fname" class="text" name="fname" size="20" type="text">
<label for="lname">2nd accountname:</label>
<input id="lname" class="text" name="lname" size="20" type="text">
<button class="button positive"> <img src="../images/icons/tick.png" alt=""> Add Client </button>
</fieldset>
</form>
<div class="success" style="display: none;">Konten wurden kreiert.</div>
<div class="fail" id="fail" style="display: none;">Fehler.</div>
</div>
ajax.php
include('config.php');
$con = mysql_connect($host,$user,$pw);
mysql_select_db($dbname, $con);
// CLIENT INFORMATION
$fname = htmlspecialchars(trim($_POST['fname']));
$lname = htmlspecialchars(trim($_POST['lname']));
$addClient = "CREATE TABLE IF NOT EXISTS $fname(id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),kind VARCHAR(30),date VARCHAR(30),amount INT)";
mysql_query($addClient) or die(mysql_error());
Q1: i want to let the user add more fields fname. How to do this that in index.php these fields are also included in the $.ajax({ data:........})?
Q2: how can i use the success function to display the input the user gave in fname, lname?
Q3: how to give an error message if the table already exists? and how to validate before the ajax if the user only uses literals in the form (fname,lname)?
Couldn't find an example of this, thx for any help!