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 to the CF scene
    Join Date
    May 2004
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP to MySQL Form

    All,

    I am relativly new to PHP and MySQL but know enough to get the job done. My problem is that I cannot debug a problem which led me here to post a question.

    I have an HTML form that Posts to a PHP script that points to a MySQL database. My Problem is that when i submit the form a new line is generated in my table but the data from the form is not there. what is there is the name of the field in the form.

    check out the form here.
    LRC Builder Form

    I will post my code if needed but this seems like a easy problem to solve since something is getting written to the database just not the correct data.

    Thanks,

    Curt

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Welcome here !

    sadly, the forms code is of no use for us.

    Your PHP code for the insert should look like

    $insert=”INSERT INTO yourtablename (yourfirstcolumnsname, yoursecondscolumnname, …) value (‘” . $_POST[‘id’] .”’, ‘” . addslashes($_POST[‘name’]) . ‘”, …)”;
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New to the CF scene
    Join Date
    May 2004
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Perhaps I should have posted the code

    Raf, Thanks for the welcome. I am pretty excited that I have gotten this to work as well as I have...

    This might be more of a MySQL question than a PHP question after reviewing the last post.

    <?
    $DBhost = "lrcweb01";
    $DBuser = "curt";
    $DBpass = "";
    $DBName = "onlinesignup";
    $table = "online_builder_signup";
    mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

    @mysql_select_db("$DBName") or die("Unable to select
    database $DBName");

    $sqlquery = "INSERT INTO $table
    VALUES
    ('id','company_name','address','city','state','zip','primary_contact','phone','fax','email','comment s')";

    $results = mysql_query($sqlquery);

    mysql_close();

    ?>

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have forgotten to pick up your form variables via $_POST:


    Code:
    <?
    $DBhost = "lrcweb01";
    $DBuser = "curt";
    $DBpass = "";
    $DBName = "onlinesignup";
    $table = "online_builder_signup";
    mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
    
    @mysql_select_db("$DBName") or die("Unable to select
    database $DBName");
    
    $sqlquery = "INSERT INTO $table VALUES('".$_POST['id']."','".$_POST['company_name']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip ']."','".$_POST['primary_contact']."','".$_POST['phone']."','".$_POST['fax']."','".$_POST['email']."','".$_POST['comments']."')";
    
    $results = mysql_query($sqlquery);
    
    mysql_close();
    
    ?>
    Last edited by carl_mcdade; 05-28-2004 at 08:45 PM.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #5
    New to the CF scene
    Join Date
    May 2004
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Now I've got an error

    Here is the error that I am getting...

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\ALLMANAGEDWEBS\lrcproducts\forms\builders\builder1.php on line 14

    Line 14 is VALUES

    Thanks,

    Curt

    <?
    $DBhost = "lrcweb01";
    $DBuser = "curt";
    $DBpass = "";
    $DBName = "onlinesignup";
    $table = "online_builder_signup";
    mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

    @mysql_select_db("$DBName") or die("Unable to select
    database $DBName");

    $sqlquery = "INSERT INTO $table
    VALUES
    ('$_POST['id']','$_POST['company_name']','$_POST['address']','$_POST['city']','$_POST['state']','$_POST['zip ']','$_POST['primary_contact']','$_POST['phone']','$_POST['fax']','$_POST['email']','$_POST['comments']')";

    $results = mysql_query($sqlquery);

    mysql_close();

    ?>

  • #6
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code got broken with carriage returns because I forgot to use a code box. Try again. There should be no breaks in the query rows
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #7
    New to the CF scene
    Join Date
    May 2004
    Location
    Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Off for the weekend back at it on Tuesday

    Thanks all for the help. I think I am getting closer...

    Curt
    ~~~~~~~~~~~~~~
    Curt
    Digital Parrot Technologies LLC
    www.curtbarkey.com

  • #8
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ooop!

    I checked that string in the parser. It was wrong. It's fixed now.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials


  •  

    Posting Permissions

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