Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Db wont update?!

    Can Anybody tell my whats wrong with this? It just wont update the database?

    PHP Code:
    <?php


    ## CONNECT TO DB HERE

    mysql_select_db("news",$db);

    $result mysql_query("SELECT * FROM newsdb",$db);
      
      if (
    id) {
      
        
    $sql "UPDATE `newsdb` SET id='$id',displaytitle='$displaytitle',news='$news',displaydate='$displaydate',time='$time',by='$by',realtitle='$realtitle' WHERE id='$id'";
        
          
    // run SQL against the DB

      
    $result mysql_query($sql);
        
        
    printf("<font face='Verdana' size=1 color=#667AA6>Thankyou - The Selected News Item has been Edited.! <br> To Return to the Admin Center - Click <a href=index.php3>Here</a>\n");

    }
      
              
    ?>
    Thanks

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    if (id) {
    should be
    if ($id) {

    but as thats probably just a typo... so get MySQL to tell you whats wrong...



    PHP Code:
    <?php


    ## CONNECT TO DB HERE

    mysql_select_db("news",$db)or die(mysql_error());

    $result mysql_query("SELECT * FROM newsdb",$db)or die(mysql_error());
      
      if (
    $id) {
      
        
    $sql "UPDATE `newsdb` SET  id='$id',displaytitle='$displaytitle',news='$news' ,displaydate='$displaydate',time='$time',by='$by',realtitle='$realtitle' WHERE id='$id'";
        
          
    // run SQL against the DB

      
    $result mysql_query($sql)or die(mysql_error());
        
        
    printf("<font face='Verdana' size=1 color=#667AA6>Thankyou - The Selected News Item has been Edited.! <br> To Return to the Admin Center - Click <a href=index.php3>Here</a>\n");

    }
      
              
    ?>
    hopefully the error messages will answer your question
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this was the message i got..

    You have an error in your SQL syntax near 'by='Josh',realtitle='Josh has become smart' WHERE id='13'' at line 1

    i used this code:

    PHP Code:
    mysql_select_db("news",$db)or die(mysql_error());

    $result mysql_query("SELECT * FROM newsdb",$db)or die(mysql_error());
      
      if (
    $submit) {
      
        
    $sql "UPDATE `newsdb` SET   id='$id',displaytitle='$displaytitle',news='$news'  ,displaydate='$displaydate',time='$time',by='$by',realtitle='$realtitle' WHERE id='$id'";
        
          
    // run SQL against the DB

      
    $result mysql_query($sql)or die(mysql_error());
        
        
    printf("<font face='Verdana' size=1 color=#667AA6>Thankyou - The Selected News Item has been Edited.! <br> To Return to the Admin Center - Click <a href=index.php3>Here</a>\n");

    }
      
              
    ?> 
    Any more suggestions?

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    hi if 'id' is an integer field (INT,SMALLINT) etc you need to lose the sngle quotes >'< , also no need to reupdate the id....


    $sql = "UPDATE `newsdb` SET displaytitle='$displaytitle',news='$news' ,displaydate='$displaydate',time='$time',by='$by',realtitle='$realtitle' WHERE id=$id";
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Do not create two topics with the same general question.

    Database prob - wont update or insert?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hmm, this is the error -

    You have an error in your SQL syntax near 'by='Josh',realtitle='Josh has become smart' WHERE id=13 ' at line 1

    this is the code:

    PHP Code:

    $sql 
    "UPDATE newsdb SET displaytitle='$displaytitle',news='$news',displaydate='$displaydate',time='$time',by='$by',realtitle='$realtitle' WHERE id=$id "
    Any more suggestions again?
    Thanks for your help!

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, this is the PHP code, but that does not tell us how the query string really looked like, with all these PHP variables interpolated.
    It's generally helpful for debugging SQL activities to echo out the query string with sth. like echo $sql in your case, so you can see what really was in the string that made the SQL interpreter choke.

    Also, make sure that the format of the single table fields match the format of the contents of the PHP variables. In your case, perhaps you've forgot to run an addslashes() over some critical fields.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •