如果数据库包含特定的ID,如何停止将表单发布到mysql? [英] How do stop form posting to mysql if database contains a specific ID?

查看:74
本文介绍了如果数据库包含特定的ID,如何停止将表单发布到mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种表单用于将数据发布到mysql.

I have a form that I am using to post data to mysql.

在提交表单之前,我要检查数据库,并查看"customerid"列中是否有等于"userid"的字段,如果不是,则不发布表单.

Before submitting the form I want to check the database and see if there are any fields in the column 'customerid' that equal 'userid' and if so not to post the form.

基本上,我试图限制我的用户发布不止一次.用户将能够登录到我的系统并发表一个帖子.他们将能够删除和修改自己的信息,但仅限于一篇信息.

Basically, I am trying to limit my users from posting more than once. Users will be able to login to my system and make ONE post. They will be able to delete and modify their post but are only limited to one post.

我该怎么做????到目前为止的代码:

How would I do this??? Code so far:

<?php

include '../login/dbc.php';
page_protect();

$userid = $_SESSION['user_id'];

$sql="INSERT INTO content (customerid, weburl, title, description)
VALUES
('$_POST[userid]','$_POST[webaddress]','$_POST[pagetitle]','$_POST[pagedescription]')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

?>

推荐答案

您应该使用两个查询.如果已经存在具有该ID的记录,则第一个SELECT customerid FROM content WHERE customerid = @ID将返回一行.从那里开始,一条if语句将告诉您的用户他们已经有帖子,或者继续使用您现有的代码来插入记录.

You should use two queries. The first, SELECT customerid FROM content WHERE customerid = @ID will return a row if there already exists a record with that ID. From there, an if statement will either tell your user that they already have a post or proceed with your existing code to insert the record.

这篇关于如果数据库包含特定的ID,如何停止将表单发布到mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆