tags:

views:

67

answers:

7
+2  A: 

Your query is valid and it inserts data sucsesfully, therefore MySql_Query() returns true, which in turn "triggers" the first if, but not the second.

See documentation for return values of MySql_Query.

If you want validation you have to write it.

also: your two if statements can be refactored into one. Look at the if/else syntax

Jan Hančič
i think i need a validaiton
Ronnie Chester Lynwood
You have to write it then. It doesn't just magically happen :)
Jan Hančič
how to ? :D could u hlp me?
Ronnie Chester Lynwood
That's a different question so open a new one.
Jan Hančič
well said Jan +1
c0mrade
A: 

try this

    $sonuc = mysql_query($sql);

    <?php
       if($sonuc !== false){
          echo ("<p class='msg done'>Yeni icerik basarili bir sekilde eklendi.</p>");
       } else {
          echo ("<p class='msg warning'>Ekleme basarisiz oldu.</p>");     
       }
    ?>

EDIT: When you need a validation instead of a check if the query worked check this http://www.php-mysql-tutorial.com/wikis/php-tutorial/form-validation-using-php.aspx

Tim
didnt work. showing msg done always
Ronnie Chester Lynwood
A: 

Try this: if ($sonuc !== false){... See php manual entry

David Archer
not work msg done only
Ronnie Chester Lynwood
+1  A: 

replace

$sonuc = mysql_query($sql);

with this

$sonuc = mysql_query($sql) or die(mysql_error());

is there any errors?

is it possible that your table fields do not match that ones you insert?

Adnan
A: 

Jan Hančič has already answered the question but as a side note:

Don't use POST data directly on your queries it will end badly trust me!!

AntonioCS
A: 

What is wrong about it? The return values of mysql_query() is a boolen for INSERT queries, which is true if the operation was successful. Have you tried inserting invalid values (like a text that is too long)? That should generate a warning and return false.

But what bothers much more is that your code is vulnerable to SQL injection. Please read up on sql injections on php.net how to fix that problem.

soulmerge
im trying to get errors of submit succes or not
Ronnie Chester Lynwood
What are you inserting that you think should generate an error?
soulmerge
+1  A: 

If you're trying to have your errors show up in the submitting form just move your post.php code into your form page and condition it like this:

<?php
if(isset($_POST['baslik'])) {
  $sql = "
    INSERT INTO yazilar (baslik, spot, spot_kisa, spot_resim, spot_resim_isim, icerik, kategori, tiklanma, eklemetarihi)
    VALUES
    ('$_POST[baslik]','$_POST[spot]','$_POST[spot_kisa]','$_POST[spot_resim]','$_POST[spot_resim_isim]','$_POST[icerik]','$_POST[kategori]','$_POST[tiklanma]','$_POST[tarih]')
";
  $sonuc = mysql_query($sql);

  if ($sonuc) {
    echo ("<p class='msg done'>Yeni icerik basarili bir sekilde eklendi.</p>");
    exit;
  } 
  else {
    $error = "<p class='msg warning'>Ekleme basarisiz oldu.</p>";  
  }
}
?>

// form code here
<?php if(isset($error)) { echo $error; } ?>
// around where you'd like the error to display

Now if the action is a success the success message will display with nothing else, otherwise the form will be redisplayed with the error message where you positioned it. Also, please see soulmerge's comments on SQL injection, it's a serious security risk that can be easily avoided.

Cryo
thanks this workd.
Ronnie Chester Lynwood