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 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Problematic PHP / Mysql Insert

    I've just coded a shoutbox, but it won't insert....

    i can manually insert the data into the database and it echo's it
    but this line is being problematic:
    PHP Code:
    $insert mysql_query("INSERT INTO `ccurityo_cms`.`shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`)VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')"); 
    all variables are accounted for..
    it just doesn't insert..

    any ideas?

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Maybe this?
    PHP Code:
    $insert mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')"); 
    I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.

  • #3
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by fl00d View Post
    Maybe this?
    PHP Code:
    $insert mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')"); 
    I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.
    lol, thanx for trying, but i copied and pasted it straight from my db when inserting a set of values manually.
    anyway i DID try it, no luck, still won't post.

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Can you post the rest of the code?

  • #5
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    PHP Code:
    $short_date date("d/m/Y H:i");
    $user $_SESSION['username'];
    $ip $_SERVER['REMOTE_ADDR'];
    echo 
    "<form method=\"post\">\n<br />\n<textarea name=\"message\" class=\"shoutbox_ta\"></textarea>\n<br /><input type=\"submit\" value=\"Shout!\"></form>";
    if(
    $_POST){
     
    $message sanitize("sql"$_POST['message']);
      
    $insert mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')");
     if(!
    $insert){
      echo 
    "Could Not Post Shout";
     }
    }
    $shouts mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 0,5");
    echo 
    "<table>";
    while(
    $shout mysql_fetch_array($shouts)){
     echo 
    "<tr><td><b>".$shout['author']."</b><br />".$shout['time'];
     echo 
    "<br />".$shout['message'];
     if(
    $_SESSION['auth'] > 102){
      echo 
    "<br />".$shout['ip'];
     }
     echo 
    "</td></tr>";
    }
    echo 
    "</table>"
    by the way, a little offtopic, i fixed the script on your thread

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,960
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Assuming your are getting the output from - echo "Could Not Post Shout";, add some error reporting to get php/mysql to tell you why it is failing -

    PHP Code:
     if(!$insert){ 
    echo 
    "Could Not Post Shout";
    echo 
    mysql_error();


    If you are not getting the "Count Not Post Shout", that would indicate that your code is not executing either due to a fatal parse or runtime error or the conditional logic is not being satisfied.

    What symptoms are you getting?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Jesuspwnt (12-24-2007)

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by fl00d View Post
    Maybe this?
    PHP Code:
    $insert mysql_query("INSERT INTO `ccurityo_cms.shoutbox` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES ('', '{$message}', '{$user}', '{$short_date}', '{$ip}')"); 
    I removed the ` from the dot (`.` became .) and I spaced VALUES out from the bracket.
    `database`.`table` should work fine. You can't remove the backticks in the middle unless you remove the ones on the end too, but proper syntax for MySQL uses backticks.

  • Users who have thanked Inigoesdr for this post:

    Jesuspwnt (12-24-2007)

  • #8
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    don't worry guys i fixed it, it was a problem in my sql db, i forgot to use auto_increment, sometimes, you forget the simplest of things


  •  

    Posting Permissions

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