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 Coder
    Join Date
    Apr 2011
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    form post to php to sql database fields empty.

    hello i had it posting empty fields nbow its not posting at all

    i have a form below on sign_up.tpl

    Code:
    <form name="register" method="post" action="tested.php">
    Name:<br>
    <input type="text" name="first_name">
    <br>
    Email: <br>
    <input type="text" name="user_email">
    <br>
    Email2: <br>
    
    <input type="text" name="user_email2">
    <br>
    Email3: <br>
    <input type="text" name="user_email3">
    <br><br>
    <input type="Submit" name="Submit" value="Submit">
    </form>
    with action to tested.php

    in my php it should insert to database but not

    Code:
    <?php
    require_once 'includes/global.php';
    
    if($smarty -> template_exists(basename(str_replace(DYNAMIC_EXTENSION,TEMPLATE_EXTENSION,$_SERVER['PHP_SELF']))))
    {
    ####################################################################
    ################ DATABASE CONFIGURE ##############################
    ####################################################################
    if (isset($_POST['register'])) {
        //Create the databse link, ("localhost", "username", "password")
        mysql_connect("", "", "")
            OR die(mysql_error()); //for debugging
        mysql_select_db("user_info")
            OR die(mysql_error()); //for debugging
        //ensure that items have been passed, and set them 
     if (!empty($_POST['user_name']))
            $user_name = $_POST['user_name'];
        else
            $user_name = '';
    		if (!empty($_POST['user_email']))
            $user_email = $_POST['user_email'];
        else
            $user_email = ''; 
    		if (!empty($_POST['user_email2']))
            $user_email2 = $_POST['user_email2'];
        else
            $user_email2 = '';
    		if (!empty($_POST['user_email3']))
            $user_email3 = $_POST['user_email3'];
        else
            $user_email3 = '';
    		
    		
    		$sql = "INSERT INTO `user_info`
            (`user_name`, `user_email`, `user_email2`, `user_email3`)
            VALUES ('$_POST[user_name]','$_POST[user_email]','$_POST[user_email2]','$_POST[user_email3]')"; 
    		
    		 if (mysql_query($sql))
            echo 'Query executed';
        else
            die(mysql_error()); echo 'error';
        mysql_close();
    }
    
    
    
    
    $smarty -> display(basename(str_replace(DYNAMIC_EXTENSION,TEMPLATE_EXTENSION,$_SERVER['PHP_SELF'])));
    }
    
    
    
    my_log_error('2000','APPLICATION','SMARTY template is missing',__FILE__,__LINE__);
    
    exit;
    
    ?>
    can any one help me please

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You have no variable $_POST['register'].

    This is a PHP question and should be moved to the PHP forum.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    ???? Fumigator: WHY should he have $_POST['register']??? Where is there any field by that name in the <form>???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    First, you create these variables:
    Code:
    if (!empty($_POST['user_name']))
            $user_name = $_POST['user_name'];
        else
            $user_name = '';
    		if (!empty($_POST['user_email']))
            $user_email = $_POST['user_email'];
        else
            $user_email = ''; 
    		if (!empty($_POST['user_email2']))
            $user_email2 = $_POST['user_email2'];
        else
            $user_email2 = '';
    		if (!empty($_POST['user_email3']))
            $user_email3 = $_POST['user_email3'];
        else
            $user_email3 = '';
    And then you IGNORE those variables completely in this code:
    Code:
    		$sql = "INSERT INTO `user_info`
            (`user_name`, `user_email`, `user_email2`, `user_email3`)
            VALUES ('$_POST[user_name]','$_POST[user_email]','$_POST[user_email2]','$_POST[user_email3]')";
    I'm no PHP person, but it seems clear to me that you should have done
    Code:
    	$sql = "INSERT INTO `user_info`
            (`user_name`, `user_email`, `user_email2`, `user_email3`)
            VALUES('$user_name','$user_email','$user_email2','$user_email3')";
    But no matter WHAT you do, learn to DEBUG DEBUG DEBUG!!!

    Right after setting $sql to that string, DEBUG it:
    Code:
       echo "<hr>DEBUG SQL: " . $sql . "<hr>";
    And ensure that the SQL query you are actually using is the one you intended to use.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bubbbbbz (04-20-2011)

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Quote Originally Posted by Old Pedant View Post
    ???? Fumigator: WHY should he have $_POST['register']??? Where is there any field by that name in the <form>???
    There isn't, that's why I pointed out it doesn't exist so he shouldn't be referring to it.

    I suppose I should have said "No variable $_POST['register'] exists, you shouldn't be referring to it".

    FYI One question mark does the job, no need to use three.

  • #6
    New Coder
    Join Date
    Apr 2011
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thanks i got it to work now. i have a page saying thank you is there a way to stop the user typing in the thank you url with out registering.

    or dont you think its a prob as there is no log in feature yet? regards

  • #7
    New Coder
    Join Date
    Apr 2011
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thumbs up

    [QUOTE=bubbbbbz;1080709]thanks i got it to work now. ok now for the email lol.

    i have the email sending fine but i have $_post[first_name] as my value and my email message says

    $owner_message = <<<HTML


    a new member $first_name is this correct? also i have '$email_address' but it just shows me the '$email_address' & $first_name.

    all done now user '$_REQUEST[first_name]'
    Last edited by bubbbbbz; 04-20-2011 at 10:56 AM. Reason: DONE

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    I'm not only blind as a bat, I'm anal retentive!!!!!!! <grin/>

    Sorry, Fumigator. Dunno how I missed that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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