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 11 of 11
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts

    PHP MYsql posting data to a DB using forms

    I need help with a simple form that I want to be able to enter values and have them inserted into mysql DB. It seems to be connecting and trying to post but what gets posted to the DB are blank fields each time I run the page. Below are the 2 files that I created. Ones and HTML form and the other is the PHP that it posts to.
    Code:
    <html>
    <boby>
    <table cellpadding=20 border=2><tr><td>Enter data in the fields.</td></tr><tr><td align="center">
    <p><b>
    
    </b></p>
    Please enter your first name 
    <form action="test3.php" methode="post">
    <input type="text" name="firstn">
    <br>and Last Name<br>
    <input type="text" name="lastn"><br>
    <input type="submit" value="SUBMIT">
    </form>
    
    </td>
    </tr>
    </table>
    </body>
    </http>
    now heres the test3.php code
    Code:
    <html>
    <body>
    <?php 
    mysql_connect("mysql-g19a.mysqldbserver.com","fundsf","******");
    mysql_select_db("fundsf");
    
    $query = "INSERT INTO test (first, last)
    VALUES ('$_POST[firstn]','$_POST[lastn]')");
    
    mysql_query($query)
    
    ?>
    </body>
    
    </html>
    Thanks
    John

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Code:
    <form action="test3.php" methode="post">
    Is this your actual code or an example? Pretty obvious typo there.

    Also:
    PHP Code:
    $query "INSERT INTO test (first, last)
    VALUES ('$_POST[firstn]','$_POST[lastn]')"
    ); 
    You have a closing parens there for some reason. You should have some error handling in your script.

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Not the cause of your problem, but your query is open to tampering.

    You are blindly inserting into your database whatever the user (or bot) entered into your form - could be their name or it could be malicious code.

    Never trust user input.
    John

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Guys I'm just asking a question on a test code with a test site and database. None of this is published. I appreciate the concern - PappaJohn. Not sure why you would say things like that without giving me a solution to my problem. As for the obvious typo. if it was obvious to me do you think I would of posted for help?

  • #5
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Quote Originally Posted by Jstrausss View Post
    Not sure why you would say things like that without giving me a solution to my problem.
    Forgive me for trying to point out a potential problem that could have caused you considerable grief when the hackers find it.That is, if it's not caught during testing.
    John

  • #6
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Jstrausss View Post
    Not sure why you would say things like that without giving me a solution to my problem. As for the obvious typo. if it was obvious to me do you think I would of posted for help?
    Did either of the mistakes I've pointed out actually help the problem? Are you still having an issue with this? Or would you prefer to continue complaining about the free support you're receiving?

  • #7
    New Coder
    Join Date
    Dec 2009
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts
    you guys just don't get it. all you did was made me feel foolish when all I was asking was for some help on a really basic problem. I was not asking for someone to point out the obviuos or was I asking if my code was secure. I was just generally asking about why can not insert these values from a form. That is it and you two made it more complicated and didn't even clearly help me at all. first guy just highlighted things and pappa you just said that I have a security issue and didn't even help. I would mind the extra advice when it comes with the answer to my original question.

  • #8
    New Coder
    Join Date
    Dec 2009
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by bdl View Post
    Did either of the mistakes I've pointed out actually help the problem? Are you still having an issue with this? Or would you prefer to continue complaining about the free support you're receiving?
    o if you were talking about the closing parens that should not of been there. I took it out, but its still not inserting the data. its just inserting blanks in each field no errors on the page after submit, but don't worry about it. I'll ask my question somewhere else. Thanks anyway for your great support.

  • #9
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Jstrausss View Post
    first guy just highlighted things
    Well I can't possibly reach into my PC and hold your hand, now can I? All I can do is point out errors I see and make suggestions. If you're not willing to take advice or even some constructive criticism, and then take these things and try them on your own, then you can't be helped in a public forum.

  • #10
    New Coder
    Join Date
    Dec 2009
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by bdl View Post
    Well I can't possibly reach into my PC and hold your hand, now can I? .
    I guess holding the hand of a newbie programmer that needs help was asking to much.

  • #11
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Jstrausss View Post
    I guess holding the hand of a newbie programmer that needs help was asking to much.
    Not really, but you need to provide some feedback, some sense that you're actually trying here. When we see something wrong and call you on it, you should take it as constructive criticism and move on. If I say "hey there's a glaring error here (that is obvious to me)", don't be offended by it, try the corrections we've suggested and post back the results.

    Now, in an attempt to get this train back on track, do you require further help with this? Can you post what you're still working on that you're having trouble with?


  •  

    Posting Permissions

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