好吧,我已经在这个位上工作了大约5个小时&我只是无法让它工作。我到处寻找,但我的代码似乎是......独一无二的。 无论如何,我试图改变我的SQL数据库中的特定表中的条目。表的名称是userdb。 我有5个文本框,名称,用户名,密码,电子邮件和ID。其中,ID是查询所需条目所需的主键,其余4个文本框都填入了我想要的新条目。使用PHP编辑SQL数据库中的表格
这是我的主要PHP文件名为admin.php的内容,这个人的头标记:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".test4").click(function() {
var id = $("#txUserid").val();
$.post("updateUser.php", { id: id }, function(data) {
alert(data);
});
});
});
这一个在身体:
<font color="white">Name</font><input class="test1" type="text" id="txNm" value="" onkeyup="nospaces(this)">
<font color="white">Username</font><input class="test1" type="text" id="txUsn" value="" onkeyup="nospaces(this)">
<font color="white">Password</font><input class="test1" type="password" id="txPwd" value="" onkeyup="nospaces(this)">
<font color="white">E-Mail</font><input class="test1" type="text" id="txEml" value="" onkeyup="nospaces(this)">
<font color="white">Updater - ID, only affected by the Delete & Update button.</font><input class="test1" type="text" id="txUserid" value="" onkeyup="nospaces(this)">
<input class="test4" name="Submit" type="submit" value="" id="submit"/>
这一个我的updateUser函数存储在'mshop2.script.js'中:
function updateUser(){
var name = $('#txNm').val();
var username = $('#txUsn').val();
var password = $('#txPwd').val();
var email = $('#txEml').val();
var id = $('#txUserid').val();
var finalData = {
nm: name,
usn: username,
pwd: password,
eml: email,
uid: userid
};
$.post('updateUser.php', finalData, function(resp){
if(resp == 'success'){
alert('User successfully modified.');
getUserList();
}
});
}
这一个是我的updateUser.php文件:
<?php
include 'config.php';
$nm = mysql_real_escape_string($_POST["nm"]);
$usn = mysql_real_escape_string($_POST["usn"]);
$pwd = mysql_real_escape_string($_POST["pwd"]);
$eml = mysql_real_escape_string($_POST["eml"]);
$id = mysql_real_escape_string($_POST["id"]);
$sql = "SELECT ID FROM userdb WHERE ID='$id'";
$result = mysql_query($sql);
if(mysql_num_rows($result) >0)
{
//found
$q = "UPDATE userdb
SET `name` = '$nm',
`username` = '$usn',
`password` = '$pwd',
`email` = '$eml'
WHERE ID ='$uid'";
}
else
{
//not found
die('Error: The ID does not exist.' . mysql_error());
echo mysql_error();
}
$result = mysql_query($q);
if(empty($_POST['nm'])) {
die('You need to enter a value for the Name field');
}
if(empty($_POST['usn'])) {
die('You need to enter a value for the Name field');
}
if(empty($_POST['pwd'])) {
die('You need to enter a value for the Name field');
}
if(empty($_POST['eml'])) {
die('You need to enter a value for the Name field');
}
if(empty($_POST['uid'])) {
die('You need to enter a value for the Name field');
}
if(empty($_POST['id'])) {
die('You need to enter a value for the Name field');
}
if(!mysql_query($q, $con)){
die('Error: ' . mysql_error());
echo mysql_error();
}else{
echo 'success';
}
mysql_close($con);
?>
我想不出什么是导致它不工作,拟进入,我想进入,比如说,如果我输入“50”在ID文本框中。 ID将保持不变,但其余字段为空。我这次做错了什么?
”我写了一些代码,但不知道它是做什么的,请为我修复它“ –
让我休息我一直在阅读我的文本书像地狱几个小时-.- –
请给自己一本书*调试*这是通过运行代码而不是观察它来发现错误的艺术。你真的需要这样一本书。 http://www.ibm.com/developerworks/library/os-debug/是一个很好的开始 –