How do stop form posting to mysql if database contains a specific ID?

Posted by user342391 on Stack Overflow See other posts from Stack Overflow or by user342391
Published on 2010-05-27T16:31:02Z Indexed on 2010/05/27 16:31 UTC
Read the original article Hit count: 149

Filed under:
|

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

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";

?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql