如何使用php检查表单上的重复条目?我的前端是c#windows应用程序
我正在使用c#和php文件向数据库添加新用户.
我创建了以下内容:
我在c#(form1)中的项目:
c#编码:
private void btncreate_Click(object sender, EventArgs e) { var request = (HttpWebRequest)WebRequest.Create("http://***.**.***.***/response.php"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; using (var stream = request.GetRequestStream()) { var buffer = Encoding.UTF8.GetBytes("userid= " + txtUserid.Text + " & password=" + txtConformpassword.Text + " & first_name=" + txtFirstname.Text + " & last_name=" + txtLastName.Text + "& role= " + cmbRole.Text + "& active=" + cmbActive.Text + ""); stream.Write(buffer, 0, buffer.Length); } var response = (HttpWebResponse)request.GetResponse(); string result = String.Empty; using (var reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } txtMessage.Text = result; }
我的PHP文件:response.php
connect_error) { die("Connection failed: " . $conn->connect_error); } $sql= "INSERT INTO aster(userid,password,first_name,last_name,role,active) VALUES('$uid', '$pass', '$fname','$lname','$rol','$act');"; if ($conn->query($sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>
它成功添加数据,但是当我在文本框中输入相同的用户ID并单击创建按钮时,我需要在txtmessage中收到错误消息,因为 userid已经存在.
我搜索谷歌搜索但我没有任何关于重复输入的事情请参考我一些编码