Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2014
    Posts
    6

    Unanswered: odd database connection

    I tried to create a subscribe form that uses php to connect to mysql. When i enter the email address into the form, the ID adds another column but does not add the email address into the database. I am going to post the code minus the password and host names.

    If anyone can help me figure it out I would be very greatful

    The form can be found at A-MAIZE-ING PERFORMANCE Cell phone repair Web design Lima, Ohio

    HTML code

    <form action="newsletter.php" method="post" >
    <input name="email" class="email" type="text" placeholder="Enter your email address ...">
    <button type="submit" class="btn_email">Send</button>
    </form>


    PHP code

    <?php

    define('DB_NAME', '*****');
    define('DB_USER', '*****');
    define('DB_PASSWORD','******');
    define('DB_HOST','********');

    $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (!link) {
    die('Could not connnect to the database' . mysql_error());
    }

    $db_selected=mysql_select_db(DB_NAME, $link);

    if (!db_selected) {
    die('Can\'t use' . DB_NAME . ':' . mysql_error());
    }

    $value = $POST['email'];

    $sql = "INSERT INTO newsletter (email) VALUES ('$value')";

    if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
    }

    mysql_close();
    ?>


    Again it adds a row to the database and the ID field populates a new number in the new row, however, it does not post the input into the "email" column of the database.

    My database has 2 columns ID and email

    Thanks

  2. #2
    Join Date
    Sep 2014
    Posts
    6

    odd database connection

    sorry had to edit. Somehow I had posted it twice
    Last edited by rehrnsberger; 09-26-14 at 14:41.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Since your problem dealt with PHP and MySQL, I redirected your thread here to the MySQL forum. It ought to get better answers here than in the Microsoft SQL Server forum.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have you checked that $POST['email'], and by inference $value contains soemthing to insert?

    what is the actual value of $sql? (not the PHP code that creates $sql, but the actual values assigned to $SQL that you are sending to the SQL engine
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2014
    Posts
    6
    I do not know what exactly you are asking. I followed a video to show me how to connect to the database. I am not skilled in this area. I posted all the code I have so if it is not in the post then I do not have it set as a certain value

  6. #6
    Join Date
    Sep 2014
    Posts
    6

    Still in need of help

    I am still in need of help if anyone wants to assist me.

  7. #7
    Join Date
    Sep 2014
    Posts
    6
    ??? anyone want to help????

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have you checked there is a value in $POST['email']
    this is the most likely source of your error. if the insert works but ISN@T posting what you expect then you have passewd the first hurdle. its not network issues, or db issues. its most likely data issues

    how you dispaly the value is up to you. for debugging purposes id probably use
    PHP Code:
    die ('$value is:-'.$value); 
    whilst you are at it make certain (during development) you are reporting all problems in PHP
    http://php.net/manual/en/function.error-reporting.php
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Sep 2014
    Posts
    6
    Thank you.

    I found my error

    I had the code as

    $value = $POST['email'];

    instead of

    $value = $_POST['email'];

Posting Permissions

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