www.webdeveloper.com
Results 1 to 13 of 13

Thread: Insert Into

  1. #1
    Join Date
    May 2003
    Location
    Pensacola, FL
    Posts
    635

    Insert Into

    I know that my answer is probably written all over the web, but I have yet to find an answer. I have looked, and read sample scripts and went to other forums and searched, and even searched on this forum. The closet thing I found was the example user login system that pyro gave which used the make pass and such. My question / problem is that I cannot add data to my database table... I want users to be able to register and here is my form... I made it bare as possible until I can get it to work...

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <form method="POST" action="add.php">
    First Name:<input type="text" name="first">
    Last Name:<input type="text" name="last">
    Username:<input type="text" name="user">
    Password:<input type="text" name="pass">
    Email:<input type="text" name="email">
    <input type="submit">
    </form>
    </body>
    </html>

    And here is the "add.php" page...

    <?

    //DB Variables
    $Host = "localhost";
    $User = "********";
    $Pwd = "********";
    $DBName = "jdm71488_web";
    $Link = mysql_connect($Host,$User,$Pwd);

    $Query = "INSERT into members values ('$_POST[first]','$_POST[last]','$_POST[user]','$_POST[pass]','$_POST[email]')";
    $Result = mysql_db_query($DBName, $Query, $Link);

    echo"$Query\n";
    mysql_close ($Link);
    ?>

    I forgot where I got this from. I copied it from somewhere, then filled in my info from there... After submitting the data, it redirects to the add.php page and displays what it is supposed to insert, for example (INSERT into members VALUES (aslfjsd, lasjfljaf, pwueruwe, aowurlk aslkj, alsidf)) but when I got to my table in phpmyadmin, no rows are there... whats wrong??? please help...

    JDM
    Last edited by JDM71488; 06-16-2003 at 12:11 PM.

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Here's how I'd try it...

    PHP Code:
    <?PHP
    if (isset($_POST["submit"])) {
        
    //DB Variables
        
    $user "********"#username
        
    $pass "********"#password
        
    $dbname "test"#database name
        
    $tablename "jdm71488_web"#table name

        
    $dbh=mysql_connect ("localhost""$user""$pass") or die ('I cannot connect to the database because: ' mysql_error());
        
    mysql_select_db ("$dbname"); 

        
    $query "INSERT INTO $tablename VALUES ('','$_POST[first]','$_POST[last]','$_POST[user]','$_POST[pass]','$_POST[email]')"#should be one line

        
    mysql_db_query ($dbname$query$dbh);
        
    mysql_close ($dbh); 
    }
    ?>

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form method="POST" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>"> 
    First Name:<input type="text" name="first"> 
    Last Name:<input type="text" name="last"> 
    Username:<input type="text" name="user"> 
    Password:<input type="text" name="pass"> 
    Email:<input type="text" name="email"> 
    <input type="submit" name="submit" value="submit"> 
    </form> 

    </body>
    </html>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    May 2003
    Location
    Pensacola, FL
    Posts
    635
    Thanks again pyro...

    It adds the info that the user submits, but it just refreshes the page once it is complete... How can I make it echo something? or even change a page?

    One more thing... Once I finish this page, and then the log in script, what can I use to make it where people cannot just type in the url of the page to get to it?

    JDM

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    For simplicitys sake, I had it all in one file. If you want, you can have you form submit to the PHP page. Either way, to echo the data to the screen, just do something like this:

    PHP Code:
    echo $_POST["first"]."<br>";
    echo 
    $_POST["last"]."<br>";
    #etc... 
    http://forums.webdeveloper.com/showt...&threadid=9950 shows how to make it so people can't just call the page directly from the browser...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    May 2003
    Location
    Pensacola, FL
    Posts
    635
    You're the best pyro!

    JDM

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    lol...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  7. #7
    Join Date
    May 2003
    Location
    Pensacola, FL
    Posts
    635
    Sorry to bother again... While we are on the topic... I looked at the other page in reference to the page blocking... AND... on the passwordreader.php page, I dont understand how to retrieve the info from the database... I mean I get how to set the variable but I dont know how to start this login php script....

    if ($_POST['log_user']) == $user && ($_POST['log_pass']) == $pass)
    {
    setcookie ("verified", true);
    header ("Location:http://www.jdm71488.com");
    }
    else
    {
    echo ("Incorrect Password");
    }

    ?>

    The origianl requires me to enter the md5 password and user. How can I make it where it will take the user info that they submitted and check to see if they are in the database, then it will set the variable and redirect? please help...

    JDM

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You need to connect to the DB and look through the results, something like this:

    PHP Code:
    <?PHP
    if (isset($_POST["submit"])) {

        
    $frmuser $_POST["user"];
        
    $frmpass $_POST["pass"];
        
    //DB Variables
        
    $user "********"#username
        
    $pass "********"#password
        
    $dbname "infini15_test"#database name
        
    $tablename "jdm71488_web"#table name    

        
    $dbh mysql_connect ("localhost""$user""$pass") or die ('I cannot connect to the database because: ' mysql_error());
        
    mysql_select_db ("$dbname"); 

        
    $query "SELECT * FROM $tablename WHERE user='$frmuser'"
        
        if (
    mysql_db_query ($dbname$query$dbh)) {
            
    $result mysql_query($query);
            
    $num_rows mysql_num_rows($result);
            
            if (
    $num_rows != 0) { #if a username was found        
                
    while($row mysql_fetch_array($result)) {
                    if (
    $row["pass"] == $frmpass) { #if password matches the one in the DB
                        
    echo "Valid";
                    }
                    else { 
    #if it did not match
                        
    echo "Password incorrect"
                    }
                }
            }
            else { 
    #if a username was not found
                
    echo "Username incorrect";
            }
        }
        
    mysql_close ($dbh); 
    }
    ?>

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form method="POST" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>"> 
    Username:<input type="text" name="user"> 
    Password:<input type="password" name="pass"> 
    <input type="submit" name="submit" value="submit"> 
    </form> 

    </body>
    </html>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  9. #9
    Join Date
    May 2003
    Location
    Pensacola, FL
    Posts
    635
    Sweet! Ill build on from here...

    Thanks again...

    JDM

  10. #10
    Join Date
    Aug 2008
    Posts
    4
    I have a problem with this script,can soembody help me out here?

    <?PHP
    if (isset($_POST["submit"])) {
    //DB Variables
    $user = "opssrv_opsdata; #username
    $pass = "000000123"; #password
    $dbname = "opssrv_data"; #database name
    $tablename = "web_members"; #table name

    $dbh=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("$dbname");

    $query = "INSERT INTO $tablename VALUES ('','$_POST[ops_name]','$_POST[rec_by]','$_POST[game_slct]','$_POST[clan]','$_POST[fname]','$_POST[lname]','$_POST[gender]','$_POST[country]','$_POST[skype]','$_POST[xfire]','$_POST[msn]','$_POST[yahoo]','$_POST[email]','$_POST[postalc]')"; #should be one line

    mysql_db_query ($dbname, $query, $dbh);
    mysql_close ($dbh);
    }
    ?>



    <html>
    <head>
    <title>OPS* User Administration Panel</title>
    </head>
    <form method="POST" action="<?PHP echo $_SERVER["PHP_SELF"]; ?>">
    <font type="arial" size="2" color="black" />
    OPS Username:
    <input type="text" name="ops_name" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    Recruited By:
    <input type="text" name="rec_by" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    Game Selection:
    <input type="text" name="game_slct" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    Clan:
    <input type="text" name="clan" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    First Name:
    <input type="text" name="fname" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    Last Name:
    <input type="text" name="lname" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    Gender:
    <input type="text" name="gender" style="background-color: #444444; color:#FF6600" size="15" maxlength="6" />
    <br>
    <br>
    Country:
    <input type="text" name="country" style="background-color: #444444; color:#FF6600" size="15" maxlength="30" />
    <br>
    <br>
    Skype Username:
    <input type="text" name="skype" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    X Fire Username:
    <input type="text" name="xfire" style="background-color: #444444; color:#FF6600" size="15" maxlength="15" />
    <br>
    <br>
    MSN Address:
    <input type="text" name="msn" style="background-color: #444444; color:#FF6600" size="15" maxlength="30" />
    <br>
    <br>
    Yahoo Address:
    <input type="text"name="yahoo" style="background-color: #444444; color:#FF6600" size="15" maxlength="30" />
    <br>
    <br>
    E-Mail Address:
    <input type="text" name="email" style="background-color: #444444; color:#FF6600" size="15" maxlength="30" />
    <br>
    <br>
    Postal Code:
    <input type="text" name="postalc" style="background-color: #444444; color:#FF6600" size="15" maxlength="5" />
    <br>
    <br>
    </font>
    <input type="submit" name="submit" value="Upload Data" />
    <input type="reset" name="reset" value="Reset all Fields" />

    </body>
    </html>

  11. #11
    Join Date
    Apr 2007
    Posts
    133
    cybercom,

    just to let you know, what you are doing is hijacking JDM71488's thread. Why not start your own! Also explain exactly what you want,what the problem is i.e. MY query won't insert, just ask question the right way.

    Also when posting php code, use the go advanced button, then the php tags(shown in html to illustrate)
    HTML Code:
    [php]<?php echo "place the code between"; ?>[/php]
    as these will syntax highlight , its much easier to read and de-bug like this
    PHP Code:
    <?php echo "place the code between"?>

  12. #12
    Join Date
    Aug 2008
    Posts
    4
    I get this error message:

    Parse error: syntax error, unexpected T_LNUMBER in /home/opssrv/public_html/ops_test/ops_mem_add.php on line 5

  13. #13
    Join Date
    Aug 2008
    Posts
    4
    Bump

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles