我收到了这个错误:
Notice: Undefined index: prospectname in C:\wamp\www\var\SAS\insert.php on line 12
这是代码
<form action="#" method="POST" class='form-horizontal form-bordered'>
<div class="control-group">
<label for="prospectname" class="control-label">Prospect Name</label>
<div class="controls">
<input type="text" name="prospectname" id="prospectname" placeholder="prospectname" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label for="status" class="control-label">Status</label>
</div>
</form>
sas.js
$(".registeradd").click(function () {
var prospectname = $("#prospectname").val();
var status = $("#status").val();
var dataString = 'prospectname =' + prospectname + '&status=' + status;
if (prospectname == '') {
alert("Please Enter Some Text");
} else {
$("#flash").show();
$("#flash").fadeIn(400).html;
$.ajax({
type: "POST",
url: "insert.php",
data: dataString,
cache: false,
success: function (html) {
$("#display").after(html);
$("#flash").hide();
}
});
}
return false;
});
Insert.php
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'root';
$dbPassword = '';
$dbDatabase = 'test';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$prospectname =$_POST['prospectname'];
$status=$_POST['status'];
$sql_insert="insert into salesactivity(prospectname,status) values '$prospectname','$status')";
print $sql_insert;
mysql_query($sql_insert);
?>
答案 0 :(得分:0)
更改数据字符串
var dataString = 'prospectname ='+ prospectname +'&status='+status;
到json object
var dataString = { 'prospectname': prospectname, 'status': status};
答案 1 :(得分:-1)
我认为您忘记了表单中的状态文本字段,将其添加到html表单
replace your form with this
<form action="#" method="POST" class='form-horizontal form-bordered'>
<div class="control-group">
<label for="prospectname" class="control-label">Prospect Name</label>
<div class="controls">
<input type="text" name="prospectname" id="prospectname" placeholder="prospectname" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label for="prospectname" class="control-label">Status</label>
<div class="controls">
<input type="text" name="status" id="status" placeholder="status" class="input-xlarge">
</div>
</div>
</form>