Jump to content

Recommended Posts

Hi,

 

I have set up a database called "enigmadb" with a table called "user", I have created the database connection in a file called "connection.php", and I also have a page called "Register.php" where i have created a form and a query, but when I try to submit the data using the for nothing happens, and I cant seem to find out why this is, I'm assuming there is an issue with the database connection, but it looks OK to me, but this is the first time i have used MYSQLI and i have alot to learn.

 

Thanks.

 

 
Database: 
 
UserID int(11) AUTO_INCREMENT
Fname varchar(200) latin1_swedish_ci Yes NULL
Lname varchar(200) latin1_swedish_ci Yes NULL
Email varchar(200) latin1_swedish_ci Yes NULL
Username varchar(200) latin1_swedish_ci Yes NULL
Password varchar(200) latin1_swedish_ci Yes NULL
Timestamp timestamp No CURRENT_TIMESTAMP
UserLevel int(11) No 1
ProfileImage text latin1_swedish_ci Yes NULL
Bio text latin1_swedish_ci Yes NULL
 
Connection.php stored in a connection folder.
 

<?php


$con = mysqli_connect("localhost", "root", "password", "enigmadb");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
?>

Register.php

 

<?php  require 'Connection/Connections.php'; ?>
<?php


if(isset($_POST['Register'])){


session_start();
$FName = $_POST['First_Name'];
$LName = $_POST['Last_Name'];
$Email = $_POST['Email'];
$PW = $_POST['Password'];


$sql = $con->query("INSERT INTO user (Fname, Lname, Email, Password)Values('{$FName}', '{$LName}', '{$Email}', '{$PW}')");


header('Location: Login.php');


}


?>
<!doctype html>
<html>
<head>
<link href="CSS/Master.css" rel="stylesheet" type="text/css" />
<link href="CSS/Menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
background-color: #000000;
background-image: url(Assets/bg.jpg);
background-repeat: no-repeat;
}
</style>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="styles.css">
   <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>
<title>Register</title>
</head>


<body>
<div class="Container">
     <div class="Header"></div>
        <div class="Menu">
        <div id="Menu">
<div id='cssmenu'>
<ul>
   <li><a href='#'><span>Login</span></a></li>
   <li><a href='#'><span>Register</span></a></li>
   <li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
</div></div>
        <div class="LeftBody"></div>
        <div class="RightBody">
          <form id="RegisterForm" name="RegisterForm" method="post">
          <div class="FormElement">
            <input name="First_Name" type="text" required class="TField" id="First_Name" placeholder="First Name">
          </div>
          <div class="FormElement">
            <input name="Last_Name" type="text" required="required" class="TField" id="Last_Name" placeholder="Last Name">
          </div>
          <div class="FormElement">
            <input name="Email" type="email" required="required" class="TField" id="Email" placeholder="Email">
          </div>
          <div class="FormElement">
          <input name="Password" type="password" required="required" class="TField" id="Password" placeholder="Password">
          </div>
          <div class="FormElement">
            <input name="Register" type="button" class="button" id="Register" value="Register">
          </div>
          </form>
        </div>
        <div class="Footer"></div>
   </div>
<p> </p>
</body>
</html>

 

 

 

First off, you never send user supplied data directly to the database. Second, the parenthesis around the variables are not needed.

 

If you turned on error reporting you would know what the problems are.

Edited by benanamen

And you cannot mix'n'match mysql and mysqli

 

 

$con = mysqli_connect("localhost", "root", "password", "enigmadb");
if (!$con) {
    die('Could not connect: ' . mysql_error())

 

http://uk1.php.net/manual/en/mysqli.connect-error.php

Edited by Barand

Use PDO. It's easier to handle, and you'll be less likely to mix and match with mysql_* as Barand pointed out.

 

As benanamen stated, you're inserting user-supplied data directly into the query, which is not only a bad idea, it's completely missing the point of using either mysqli or PDO - use prepared statements. (Here's the PDO version of prepare()).

Edited by maxxd
  • Like 1

 

It's perfectly fine to omit the action attribute. In fact, your suggestion is against the specification, because the attribute may only contain non-empty URLs.

 

So that means will still work because browsers fix thousands of issues, but will show up in a validator possibly?

Leave it out, leave it an evil empty string it's still going to submit back to the submitting page as of now. The specs say a lot of things, but the browsers have the last say in whether it's implemented or not. However, in the nature of goodwill and standards promotion, if you're going to submit back to the page, just omit the tag(edit: attribute) and make everyone happy.

Edited by hansford

You can always force the action="" to have something in it by doing something like this :

 

$phpSelf = filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_URL);


$path_parts = pathinfo($phpSelf);


$basename = $path_parts['basename']; // Use this variable for action='':
$pageName = ucfirst($path_parts['filename']);
 
<form id="calendarLogin" class="container" action="<?php echo $basename; ?>" method="post">

now back to the OP original problem.  ;D

The whole reason why an empty action attribute was prohibited in the HTML5 spec is because browsers would not handle this consistently. So, no, this isn't just a theoretical requirement for making the validator and a bunch of language purists happy. Quite the opposite.

 

I guess all current non-crappy browsers do treat an empty action attribute correctly, but if you're also dealing with legacy browsers, I wouldn't rely on it. Plus: Why would anybody prefer an explicit empty action over no action at all?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.