Database enteries are not saved at hosting server

Discussion in 'PHP' started by babaMBA, May 25, 2007.

  1. #1
    Urgently required help.

    I will make a guest and it is working fine at localhost and one hosting server, but the server where actually i need that guest book cause a problem. When i add some comment it is not saved in the database and show blank spaces.

    www.wistech.biz/guestbook [Working 100%]
    www.jsiza.com/guestbook [Values are not saved in database and show blank spaces]


    Kindly tell me how can i sovle my problem , I urgently need this gook at "www.jsiza.com"
     
    babaMBA, May 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Set this at the top of your page which is supposed to insert the data.
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
    And add OR die(mysql_error()); behind all queries. You probably just have a wrong password or database name set in your configuration.

    If you need more help, post your code.
     
    nico_swd, May 25, 2007 IP
  3. tutankh

    tutankh Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,
    show us your code

    Regards,
    M
     
    tutankh, May 25, 2007 IP
  4. babaMBA

    babaMBA Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your help.
    The code is given as under.

    Dear the surprizing factor is that, it is working 100% fine at the other hosting server. Code , database, database structure is 100% same. Exported from phpmyadmin of my local host and placed in the control panel of my website in mysql databases.

    username and password to database is also write becoz it is not giving any connection error.

    Plz help meeee............

    <?php
    include ("../connection/config.php");

    $getDate = date("Y-m-d g:i:s");

    $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`)
    VALUES
    ('$sender', '$email', '$country', '$comment', '$getDate')";
    $resultInsertComment = mysql_query($sqlInsertComment);

    if($resultInsertComment)
    {
    header ("Location: ../allComments.php");
    }
    else
    {
    header ("Location: ../errorPages/newCommentError.php");
    }
    ?>

    ----------------------------------------------------------------

    Config file is as under.

    <?php

    $host = "localhost";
    $user = "userhere";
    $password = "passwordhere";
    $database = "guestbook";

    $comments = "comments"; #table name


    mysql_connect("$host","$user","$password")
    or
    die ("<meta http-equiv=\"refresh\" content=\"0;url=errorPages/serverConnectionError.php\" />");

    mysql_select_db("$database")
    or
    die ("<meta http-equiv=\"refresh\" content=\"0;url=errorPages/databaseConnectionError.php\" />");
    ?>
     
    babaMBA, May 25, 2007 IP
  5. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Looks like register_globals is off on that host, hence it inserts blank data because those variables don't actually exist.
     
    projectshifter, May 26, 2007 IP
  6. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can turn it on via your php.ini file. Just open notepad and place

    
    register_globals = on
    
    Code (markup):
    Save it as php.ini and upload it to the dir the script is in.

    
    <?php
    include ("../connection/config.php");
    
    $getDate = date("Y-m-d g:i:s");
    
    $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`)
    VALUES
    ('$sender', '$email', '$country', '$comment', '$getDate')";
    
    $resultInsertComment = mysql_query($sqlInsertComment) or die (mysql_error());
    
    if($resultInsertComment)
    {
    header ("Location: ../allComments.php");
    }
    else
    {
    header ("Location: ../errorPages/newCommentError.php");
    }
    ?>
    
    PHP:
    Ive added the error call in the query so run it and let us know what it says.
     
    HuggyCT2, May 26, 2007 IP
  7. babaMBA

    babaMBA Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I modify the code and add " mysql_error() " function with query , but once again it gives no error, and also blank entry is made with only date appear.

    As for as register_global is confirmed , Once i install oscommerce to my website and when i run it on hosted server (internet) it shows error message
    "register_globals" are off.

    If this is the problem then how can i "on" register_global at my hosting server.
     
    babaMBA, May 26, 2007 IP
  8. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Register_globals is for sure your problem, but if you're on a shared host then you probably can't get them to edit it (it's a security risk and I wouldn't recommend it anyway). I rewrite the line:
    $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`)
    VALUES
    ('$sender', '$email', '$country', '$comment', '$getDate')"; 
    PHP:
    It should be changed to
    
    $sqlInsertComment = "INSERT INTO `$comments` (`sender`, `email`, `country`, `comment`, `dateTime`)
    VALUES
    ('".mysql_real_escape_string($_POST['sender'])."', '".mysql_real_escape_string($_POST['email'])."', '".mysql_real_escape_string($_POST['country'])."', '".mysql_real_escape_string($_POST['comment'])."', '".mysql_real_escape_string($_POST['getDate'])."')"; 
    PHP:
    It no longer needs register globals, and it's also now safe from SQL injection. Cheers
     
    projectshifter, May 26, 2007 IP
  9. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    As I said you need to turn it on via the php.ini file, if you cannot do that then you need to contact your host and ask them to do it.
     
    HuggyCT2, May 26, 2007 IP
  10. tutankh

    tutankh Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    babaMBA:
    Use $_POST and $_GET arrays (don't forget about filtering input data).
    And there will be no problems :)
    Learn good habits in coding.

    Regards,
    M
     
    tutankh, Jun 10, 2007 IP
  11. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #11
    register_globals should never be on. Use the provided super globals to access user input. Also, anyone could hack your site simply by using SQL queries in the form fields.

    You need to validate input and make use of the PHP functions which make user input SQL safe.
     
    KalvinB, Jun 11, 2007 IP