Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Posts
    1

    Unanswered: add entry into MySQL database

    hi. need some help. am trying to add entries into my database, but when i run it, i get the following message:
    "'You have not entered all the required details.Please go back and try again.".
    I have included the code below.Could someone help me out and tell me what's wrong with it? thanks loads.

    <html>
    <head>
    <title>CD Entry Results</title>
    </head>
    <body>
    <h1>CD Entry Results</h1>

    <?php
    // create short variable names

    $category_id=$HTTP_POST_VARS['category_id'];
    $cd_title=$HTTP_POST_VARS['cd_title'];
    $cd_artist=$HTTP_POST_VARS['cd_artist'];
    $cd_price=$HTTP_POST_VARS['cd_price'];
    $cd_year=$HTTP_POST_VARS['cd_year'];

    if (!$category_id || !$cd_title || !$cd_artist || !$cd_price || !$cd_year)
    {
    echo 'You have not entered all the required details.<br />'
    .'Please go back and try again.';
    exit;
    }


    $category_id = addslashes($category_id);
    $cd_title = addslashes($cd_title);
    $cd_artist = addslashes($cd_artist);
    $cd_price = addslashes($cd_price);
    $cd_year = addslashes($cd_year);

    @ $db = mysql_pconnect('localhost', 'test', '');

    if (!$db)
    {
    echo 'Error: Could not connect to database. Please try again later.';
    exit;
    }

    mysql_select_db('test');
    $query = "insert into cd values
    ('".$category_id."', '".$cd_title."', '".$cd_artist."', '".$cd_price."', '".$cd_year."')";
    $result = mysql_query($query);
    if ($result)
    echo mysql_affected_rows().' cd inserted into database.';
    mysql_close();
    ?>


    </body>
    </html>

  2. #2
    Join Date
    Jan 2004
    Posts
    35

    Question question...

    What version of PHP are you running? And i'm presuming you are passing these form a form via a post method?

    Here are a couple other things I would try to see if your variables are being set.


    import_request_variables('p', 'p_');

    $category_id=$HTTP_POST_VARS['category_id'];
    $cd_title=$HTTP_POST_VARS['cd_title'];
    $cd_artist=$HTTP_POST_VARS['cd_artist'];
    $cd_price=$HTTP_POST_VARS['cd_price'];
    $cd_year=$HTTP_POST_VARS['cd_year'];

    echo "$catagory_id <br>";
    echo "$cd_title <br>";
    echo "$cd_artist <br>";
    echo "$cd_price <br>";
    echo "$cd_year <br>";

    // NOTE: these have the p_ prefix because of the 'import_request_variable' section listed above
    echo "<b><u> THESE HAVE A P_ PREFIX </u></b> <br>";
    echo "$p_catagory_id <br>";
    echo "$p_cd_title <br>";
    echo "$p_cd_artist <br>";
    echo "$p_cd_price <br>";
    echo "$p_cd_year <br>";



    what do you return when trying it this method?

  3. #3
    Join Date
    Feb 2004
    Posts
    29
    jules_0314
    i get the following message:
    "'You have not entered all the required details.Please go back and try again.".
    can you show the code of your first page, from where you are passing these variable values

  4. #4
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    This message is b'coz you are checking for the values of the variable that you pass from the first page (ie your form). Make sure that your passing the variable as post method or get method. If you use get method the you have to use like $HTTP_GET_VARS['varibale1']; or if post the $HTTP_POST_VARS['variable1'];

    Regards
    Rajesh

Posting Permissions

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