我將更新具有userid autoincrement屬性的coeds_user表,每當發生插入時,它會自動獲取1自動增量,然後在該字段的其餘部分插入相應的數據。到目前爲止,我已經成功插入行,但我的問題是如何更新此行時,userid是autoincrement,請你讓我知道如何實現自動增量用戶標識的更新功能,謝謝你提前。 insert_search.php如何更新數據庫行如果userID具有自動增量屬性
<?php
$user="root";
$server="localhost";
$password="";
$db="coedsproddb1";
$dbconn= mysql_connect($server,$user,$password);
mysql_select_db($db,$dbconn);
?>
<html>
<head><title>Insert</title>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-ui.js"></script>
</head>
<body>
<header> <img src="images/ipoint.png" class="logo" /> USER REGISTRATION</header>
<div class="container">
<h1 style="text-align:center">ADDING THE USER DETAILS</h1>
<style>
#display {
color:red;
font-size:12px;
text-align:center;
}
.logo {
padding:5px;
float:left;
}
header {
background-color:#074e7c;
height:60px;
width:100%;
text-align:center;
color:white;
font-size:40px;
}
#wrap {
text-align:center;
}
</style>
<form name="useradd" id="useradd" action="#" method="post">
<table align='center' border='1'>
<tr>
<td> <label for="userName">UserName</label></td>
<td ><input id="userName" name="userName" type="text" /></td>
</tr>
<tr>
<td> <label for="userEmail">Email</label></td>
<td ><input id="userEmail" name="userEmail" type="text"/></td>
</tr>
<tr>
<td>
<label for="userPassword">password</label></td>
<td ><input id="userPassword" name="userPassword" type="password" /></td>
</tr>
<tr>
<td> <label for="regDate">RegistrationDate</label></td>
<td ><input id="regDate" name="regDate" type="text" /> </td>
</tr>
<tr>
<td> <label for="ogeeid">Ogeeid</label></td>
<td ><input id="ogeeid" name="ogeeid" type="text" /> </td>
</tr>
</table>
<br>
<div id="wrap">
<input type="submit" name="add" value="add" id="add">
</div>
</form>
<div id="display">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#regDate").datepicker({
dateFormat: "yy-mm-dd"
});
$("#add").click(function(e){
var userName = $("#userName").val();
var userEmail = $("#userEmail").val();
var userPassword = $("#userPassword").val();
var regDate = $("#regDate ").val();
var d=$.datepicker.formatDate("yy-mm-dd", new Date(regDate));
var ogeeid = $("#ogeeid").val();
var dataString='userName='+userName+'&userEmail='+userEmail+'&userPassword='+userPassword+'®Date='+d+'&ogeeid='+ogeeid;
alert(dataString);
if(userName==""||userEmail==""||userPassword==""||regDate==""||ogeeid=="")
{
document.getElementById("display").innerHTML="Please Enter The Fields";
}
else
{
$.ajax({
type: "POST",
url: "insert.php",
data: dataString,
cache: false,
success: function(result){
//alert("submitted"+result);
$('#display').html(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
e.preventDefault();
}
});
});
</script>
</body>
</html>
insert.php
<html>
<head><title>Insertion</title>
</head>
<body>
<div id="display">
<?php
include('db.php');
$userName=mysql_real_escape_string($_POST['userName']);
$userEmail=mysql_real_escape_string($_POST['userEmail']);
$userPassword=mysql_real_escape_string($_POST['userPassword']);
$regDate1=mysql_real_escape_string($_POST['regDate']);
$regDate = date("Y-m-d", strtotime($regDate1));
function generateCode($characters)
{
$possible = '23456789abcdefghjkmnpqrstuvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
$registration_key=generateCode(10);
$ogeeid=mysql_real_escape_string($_POST['ogeeid']);
$str="insert into coeds_user(userName,userEmail,userPassword,regDate,registration_key,ogeeid) values('$userName','$userEmail','$userPassword','$regDate','$registration_key',$ogeeid)";
echo $str;
$query=mysql_query($str);
if($query)
{
$display="Success";
}
else
{
$display= "Failed";
}
echo $display;
?>
</div>
</body>
</html>
爲什麼你還在使用Mysql ** mysql擴展名已棄用** –