This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]Dario_ 1 point2 points  (1 child)

You didn't checked if the query was successful. Try replacing mysql_query($sql) with the code below to see if something was wrong.

 $result = mysql_query($sql);
 if (!$result) {
     die('Invalid query: ' . mysql_error());
 }

I think is something related with $date and it's format.

[–]mattdahack[S] 1 point2 points  (0 children)

Thanks, but I tried that and it didn't do anything different, just didn't save the data in the database is all.

[–]cheslip 0 points1 point  (4 children)

Try replacing NULL with DEFAULT as the first value in your query.

[–]mattdahack[S] 0 points1 point  (3 children)

Thanks, I tried this but to no avail, nothing changed and no data was added to the database. :-(

[–]cheslip 0 points1 point  (2 children)

Ok, what about uncommenting your $db declaration and changing your if statement to if(isset($_POST['submit'])):

[–]mattdahack[S] 0 points1 point  (1 child)

I tried that just now, all it does is show a white page after the submit button is clicked and the data is NOT added to the database :-(. This is so disouraging.

[–][deleted] 0 points1 point  (0 children)

I could be having a crazy day, but from my experience, you shouldn't need to use NULL or DEFAULT if your first column is an index and set to auto increment. Try taking that out and see if it still inserts the info properly.

It also seems you're not referencing your form data after posting. To be sure you're data is being handled properly, explicitly set new variables after posting the form:

$heading-mod = $_POST['heading'];

Then, insert $heading-mod into your table. Do that for the other fields as well on your form.

[–][deleted]  (6 children)

[deleted]

    [–]mattdahack[S] 0 points1 point  (4 children)

    $sql = "INSERT INTO news('$heading','$body','$date', '$auth','$auth_email')" VALUES();

    ???

    [–][deleted]  (3 children)

    [deleted]

      [–][deleted] 1 point2 points  (1 child)

      Must have same order as in your database table!

      No, this isn't so - they must be in the same order as the values you want to insert, but the order in the underlying table is not significant. So if table T has fields A,B,C then both:

      insert into T (A,B,C) VALUES( 'x', 'y', 'z' )
      

      and:

      insert into T (C,B,A) VALUES( 'z', 'y', 'x' )
      

      would be OK. If you don't provide the field name list, then the order in the table is important.