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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Location
    Dartmouth, NS
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need some help with Forms

    Hey everyone...
    I'm just learning php and am using forms to load data into a database.... now, before you go saying that this is in the wrong topic, please read on.... My problem is that I have a form on one page, and a submit button. When the user submits the form, the page in the "action" property is loaded... however it seems like the data from the form isn't carried over. Can anyone help me?

    Here is my form code:

    Code:
    <form method="post" action="create_entry.php">
    	<b>Name:</b><input type=text size=40 name=name><br>
    	<b>Location:</b><input type=text size=40 name=location><br>
    	<b>Email:</b><input type=text size=40 name=email><br>
    	<b>Home Page URL:</b><input type=text size=40 name=url><br>
    	<b>Comments:</b>
    		<textarea name=comments cols=40 rows=4 wrap=virtual></textarea>
    		<br>
    	<input type=submit name=submit value="Sign!">
    	<input type=reset name=reset value="Start Over">
    </form>
    and here is the php that handles the request on the next page...
    Code:
    <?php
    
    	include("dbconnect.php");
    	
    	if($submit=="Sign!")
    	{
    		$query = "insert into guestbook
    			(name,location,email,url,comments) values
    			('$name','$location','$email','$url','$comments')"
    		;
    		mysql_query($query) or
    			die (mysql_error());
    
    ?>
    <h2>Thanks!!</h2>
    <h2><a href="view.php">View Guestbook</a></h2>
    
    <?php
    }
    else
    {
    	echo "Error<br>";
    	
    	//include("sign.php");
    }
    ?>
    Thanks for any help...

    Michael

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Maybe this should be in the php forum, but anyways try changing your php code like this:
    PHP Code:
    <?php

        
    include("dbconnect.php");

        if(
    $_POST['submit']=="Sign!")
        {
            
    $query "insert into guestbook values('".$_POST[name]."', '".$_POST[location]."', '".$_POST[email]."', '".$_POST[url]."', '".$_POST[comments]."')";
            
    mysql_query($query) or
                die (
    mysql_error());
    ?>
    <h2>Thanks!!</h2>
    <h2><a href="view.php">View Guestbook</a></h2>
    <?php
    }
    else
    {
        echo 
    "Error<br>";

        
    //include("form.php");
    }
    ?>
    Hope this helps a little
    Last edited by Brandoe85; 10-17-2004 at 11:08 PM.

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Location
    Dartmouth, NS
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks,
    It worked

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should have register globals off in the first place.

    This means the use of $_GET (url) and $_POST (form) superglobals.


  •  

    Posting Permissions

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