Skip navigation
Currently Being Moderated

sql inserting new record error

May 2, 2012 12:01 PM

I am trying to simply insert a new record using sql.  here is my code:

 

$sql="INSERT INTO question(topic, message, datetime)

                    VALUES('$topic', '$message', '$datetime'";

                    $result=mysql_query($sql);

                    if($result){

                              $success = 1;

                    }

                    else {

                              $error = "There was an error posting your question.  Please try again, or contact us.";

                    }

 

When I try posting a new question, I get the error message.  It worked for me before.  I believe it has to do with the way that my SQL table is set up.  I have an ID field in the table, that is auto-incremented, as well as a primary key.  so not sure why it wouldn't be able to insert a new record there.  don't see anything that could really cause any conflict.  any thing else it could possibly be?

 

EDIT:

 

just noticed it had a cardinality of 3... how do i change this?

 
Replies
  • Currently Being Moderated
    May 2, 2012 2:16 PM   in reply to future-architect

    What has a cardinality of 3? The PK? How many rows are in the table? Do you have any other constraints on the table?

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 4:21 PM   in reply to future-architect

    Dunno, possibly a problem related to a datatype mismatch. Use mysql_error() to get the details.  The cardinality is correct if you have 3 rows in that unique column.

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 4:44 PM   in reply to future-architect

    Ah, I see that now. Did you use mysql_error() to find that error?

     
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2012 5:58 PM   in reply to future-architect

    Looks like it used to, but no more. From the manual:

     

    "Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_error() to retrieve the error text."

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points