1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Insert into mySQL Error

Discussion in 'Scripting & Programming' started by shadowwebs, Mar 1, 2013.

  1. shadowwebs

    shadowwebs Megabyte Poster Forum Leader

    841
    10
    76
    I have been playing with some code today as it's my day off work, and I cannot figure out what is going wrong... my code connects to the dbase successfully, however when trying to insert data, even though the page comes back and says the record has been added, it's not actually going in to the dbase table. I have changed some of the details in the code example below for security reasons, however the main part of the code is all correct... can anyone point out the obvious?

    <?php

    $fname = $_POST['fname'];
    $sname = $_POST['sname'];
    $age = $_POST['age'];
    $email = $_POST['email'];
    $uname = $_POST['uname'];
    $pword = $_POST['pword'];



    $con=mysqli_connect("mysql1454.000webhost.com", "a464549813_admin", "password", "a464549813_members");

    if ($con)
    {
    echo mysqli_connect_error();
    }



    $sql="INSERT INTO members (
    Firstname,
    Surname,
    Age,
    Email,
    Username,
    Password)
    VALUES
    (
    '$fname',
    '$sname',
    '$age',
    '$email',
    '$uname',
    '$pword')
    )";

    if (mysqli_query($con, $sql))
    {
    echo "error inserting new record";
    }
    else
    {
    echo "record added";
    }

    mysqli_close($con);

    - - - Updated - - -

    I have fixed it... stripped all the text back and began again and started working... the main reason was because I moved from mysqli back to MySQL for each of the commands
     
    Certifications: compTIA A+, Apple Certified Technical Coordinator 10.10 (OS X Yosemite, Server and Support)
  2. parman05

    parman05 Byte Poster

    126
    0
    21
    Glad you got it working. I just started looking into SQL for work. Its pretty fun keep it up.
     
    Certifications: A+, Network +, MCTS WIN7 (70-680), MCITP WIN7 (70-685), MCSA WIN7, Linux +,LPIC-1, Novell CLA 11, SUSE 11 Tech Spec, DC Tech Spec
    WIP: 70-640, 70-642, security +, CCNA
  3. ade1982

    ade1982 Megabyte Poster Forum Leader

    566
    12
    52
    you might want to take the connection string off this webpage. I can see it's non-production, but you might use it in the future!
     

Share This Page

Loading...