Jump to content

[SOLVED] Can I make a registration form in only one script page? [more details inside]


samoi

Recommended Posts

Hi guys,  :)

 

I'm just wondering if I just make a reiteration script in only one page! and no html page to redirects the form to be $_POST submitted to another page!

 

For example:

 

The form.html

<form action="register.php" method="POST">

    username : <input type="text" name="username">

                   <br />

    password : <input type="password" name="password">

                   <br />

                     <input type="submit" value="Insert into the db">
</form>

 

 

and the register.php

 

<?php
$conn = mysql_connect("localhost", "root", "pass");
$db = mysql_select_db("database_name");

$username = clean($_POST['username']);
$password = clean($_POST['password']);

if(!$username || !$password)
   {
         echo " No input inserted! ";
   }
else
   {
         $insert = "INSERT INTO users (username, password) VALUES ('$username', '$password')";

         $do_insert = mysql_query($insert);

                echo "the data has been inserted succeffully";
   }

function clean($str)
{
        return mysql_escape_string($str);
}
?>

 

 

 

 

The question is, can I make all of them in only on page? instead of doing them in two pages, and what are the positives and negatives of using this method?

 

 

Thank you in advance. :)

Of course you can. A simple example.

 

<?php
  if (isset($_POST['submit'])) {
    // process form
  } else {
    // display form
?>
<form action="" method="post">
  <input type="submit" name="submit">
</form>
<?php
  }
?>

Of course you can. A simple example.

 

<?php
  if (isset($_POST['submit'])) {
    // process form
  } else {
    // display form
?>
<form action="" method="post">
  <input type="submit" name="submit">
</form>
<?php
  }
?>

 

thank you very much man :)

 

you helped me alot :)

I appreciate it .

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.