Jump to content

PHP / HTML - Form is empty

Joveice
Go to solution Solved by Joveice,

So the issue was that the .php for some reason made it not work the form was sent since I could see the data in the header.

/errortest.php

to 

/errortest

and boom it worked.

So I'm having issues with my form not containing anything when sent.

Yes I do have names for them as you see.

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>UBN - Signup</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="/plugins/iCheck/square/blue.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition register-page">
<div class="register-box">
  <div class="register-logo">
    <a href="/"><b>Ubuntrix</b>Group</a>
  </div>

  <div class="register-box-body">
    <p class="login-box-msg">Sign up</p>

    <form action="/errortest.php" method="POST">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="uid" placeholder="username"/>
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="email" class="form-control" name="email" placeholder="Email"/>
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" name="pwd" placeholder="Password"/>
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" name="rpwd" placeholder="Retype password"/>
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group">
        <select class="form-control" name="timezone">
          <option disabled selected value=""> -- Timezone -- </option>
          <option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
          <option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
          <option value="-10.0">(GMT -10:00) Hawaii</option>
          <option value="-9.0">(GMT -9:00) Alaska</option>
          <option value="-8.0">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
          <option value="-7.0">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
          <option value="-6.0">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
          <option value="-5.0">(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
          <option value="-4.0">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
          <option value="-3.5">(GMT -3:30) Newfoundland</option>
          <option value="-3.0">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
          <option value="-2.0">(GMT -2:00) Mid-Atlantic</option>
          <option value="-1.0">(GMT -1:00) Azores, Cape Verde Islands</option>
          <option value="0.0">(GMT  0:00) Western Europe Time, London, Lisbon, Casablanca</option>
          <option value="1.0">(GMT +1:00) Amsterdam, Brussels, Copenhagen, Oslo, Roma</option>
          <option value="2.0">(GMT +2:00) Kaliningrad, South Africa</option>
          <option value="3.0">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
          <option value="3.5">(GMT +3:30) Tehran</option>
          <option value="4.0">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
          <option value="4.5">(GMT +4:30) Kabul</option>
          <option value="5.0">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
          <option value="5.5">(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
          <option value="5.75">(GMT +5:45) Kathmandu</option>
          <option value="6.0">(GMT +6:00) Almaty, Dhaka, Colombo</option>
          <option value="7.0">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
          <option value="8.0">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
          <option value="9.0">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
          <option value="9.5">(GMT +9:30) Adelaide, Darwin</option>
          <option value="10.0">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
          <option value="11.0">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
          <option value="12.0">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
        </select>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox" name="tos"> I agree to the <a href="terms.php">terms of use</a>
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat">Sign up</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
    <a href="/login.php" class="text-center">I already have a membership</a>
  </div>
  <!-- /.form-box -->
</div>
<!-- /.register-box -->

<!-- jQuery 2.2.3 -->
<script src="../../plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="../../plugins/iCheck/icheck.min.js"></script>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' // optional
    });
  });
</script>
</body>
</html>
<?php

session_start();

$path = $_SERVER['DOCUMENT_ROOT'];
include  $path.'/scripts/db_handler_script.php';

echo mysqli_real_escape_string($conn, $_POST['uid']);
echo mysqli_real_escape_string($conn, $_POST['pwd']);
echo mysqli_real_escape_string($conn, $_POST['rpwd']);
echo mysqli_real_escape_string($conn, $_POST['email']);
echo mysqli_real_escape_string($conn, $_POST['timezone']);

?>

 

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

The values i passed in by your code were transfered all okay to the errortest.php

comment all the stuff out and use for example var_dump($_POST); to see that you get it all.

 

But your errortest.php is totally wrong.

Im not familair with mysqli but try to use Prepared statements. Your errortest.php should look something like this

 

<?php


//Connection Details
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO users (uid, email, pwd, timezone) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $_POST['uid'], $_POST['email'], $_POST['pwd'], $_POST['timezone']);

//execute the statement
$stmt->execute();

//Close connection and statement
$stmt->close();
$conn->close();

echo htmlentities($_POST['uid'])." your account has been created";


?>

 

Once you done this and think yay i got it working, try to make it secure i link you a post with some startup stuff you can do.

 

Session start is for logging in actually, not for just putting stuff into the DB

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

37 minutes ago, Cruorzy said:

The values i passed in by your code were transfered all okay to the errortest.php

comment all the stuff out and use for example var_dump($_POST); to see that you get it all.

 

But your errortest.php is totally wrong.

Im not familair with mysqli but try to use Prepared statements. Your errortest.php should look something like this

 


<?php


//Connection Details
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO users (uid, email, pwd, timezone) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $_POST['uid'], $_POST['email'], $_POST['pwd'], $_POST['timezone']);

//execute the statement
$stmt->execute();

//Close connection and statement
$stmt->close();
$conn->close();

echo htmlentities($_POST['uid'])." your account has been created";


?>

 

Once you done this and think yay i got it working, try to make it secure i link you a post with some startup stuff you can do.

 

Session start is for logging in actually, not for just putting stuff into the DB

You missed the point of the post, the are no database inserts, there is only a escape string and a echo. I already know the basic php security. The issue is that the form is empty and this is what I need to fix.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

The form isnt empty, you can check this by only doing 

var_dump($_POST);

In your errortest.php

 

If you only want to echo the results directly then its simple, mysql_real_escape_string is created for working with MySQL i thought you were doing that since your first param is looking for a connection,

 

If you want to echo the results directly when the form is submitted do this.

<?php

echo htmlentities($_POST['uid']);
echo htmlentities($_POST['pwd']);
echo htmlentities($_POST['rpwd']);
echo htmlentities($_POST['email']);
echo htmlentities($_POST['timezone']);

?>

 

http://www.w3schools.com/php/func_string_htmlentities.asp

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Cruorzy said:

The form isnt empty, you can check this by only doing 


var_dump($_POST);

In your errortest.php

 

If you only want to echo the results directly then its simple, mysql_real_escape_string is created for working with MySQL i thought you were doing that since your first param is looking for a connection,

 

If you want to echo the results directly when the form is submitted do this.


<?php

echo htmlentities($_POST['uid']);
echo htmlentities($_POST['pwd']);
echo htmlentities($_POST['rpwd']);
echo htmlentities($_POST['email']);
echo htmlentities($_POST['timezone']);

?>

 

http://www.w3schools.com/php/func_string_htmlentities.asp

Notice: Undefined index: uid in D:\xampp\htdocs\errortest.php on line 8

Notice: Undefined index: pwd in D:\xampp\htdocs\errortest.php on line 9

Notice: Undefined index: rpwd in D:\xampp\htdocs\errortest.php on line 10

Notice: Undefined index: email in D:\xampp\htdocs\errortest.php on line 11

Notice: Undefined index: timezone in D:\xampp\htdocs\errortest.php on line 12
array(0) { }

 

Thats empty if you ask me (last is vardump)

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Worked fine for me, are both the files in the same directory?

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Cruorzy said:

Worked fine for me, are both the files in the same directory?

Yes

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Did copy your code nothing changed and it worked fine, try to remove the / before error.php

 

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

 

Else im not sure ;o

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Cruorzy said:

Did copy your code nothing changed and it worked fine, try to remove the / before error.php

 


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

 

Else im not sure ;o

Already tested and it dident work

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Well you could always do it in the same document, where you 

<form action="" method="POST">

And just have a if statement if the submit if pressed then output the value's else do the form etc.

Example : 

if (isset($_POST[submit']))
{
Output the form properties
}
else
{
Else show the form.
}

 

Not sure why it isnt working since it works perfectly on my WAMP machine.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Cruorzy said:

Well you could always do it in the same document, where you 


<form action="" method="POST">

And just have a if statement if the submit if pressed then output the value's else do the form etc.

Example : 


if (isset($_POST[submit']))
{
Output the form properties
}
else
{
Else show the form.
}

 

Not sure why it isnt working since it works perfectly on my WAMP machine.

It works on my login, so I want them to be the same so it's easyer to fix if there is something later on

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Well these things happend to me alot too, try to write it from scratch without any design just a html document with a form linked to a php script.

 

else try moving the script in a other directory and make the form go there.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Cruorzy said:

Well these things happend to me alot too, try to write it from scratch without any design just a html document with a form linked to a php script.

 

else try moving the script in a other directory and make the form go there.

The script I'm using is in a diffrent directory, but due to the issue I created a basic echo file in the same dir to test. I'll try to make one from scratch

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

So the issue was that the .php for some reason made it not work the form was sent since I could see the data in the header.

/errortest.php

to 

/errortest

and boom it worked.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×