Ashcartwright Posted October 19, 2015 Share Posted October 19, 2015 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_INCREMENTFname varchar(200) latin1_swedish_ci Yes NULLLname varchar(200) latin1_swedish_ci Yes NULLEmail varchar(200) latin1_swedish_ci Yes NULLUsername varchar(200) latin1_swedish_ci Yes NULLPassword varchar(200) latin1_swedish_ci Yes NULLTimestamp timestamp No CURRENT_TIMESTAMPUserLevel int(11) No 1ProfileImage text latin1_swedish_ci Yes NULLBio 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> Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 19, 2015 Share Posted October 19, 2015 (edited) 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 October 19, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Barand Posted October 19, 2015 Share Posted October 19, 2015 (edited) 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 October 19, 2015 by Barand Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 19, 2015 Share Posted October 19, 2015 (edited) 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 October 19, 2015 by maxxd 1 Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted October 19, 2015 Share Posted October 19, 2015 <form id="RegisterForm" name="RegisterForm" method="post"> You haven't added an action <form id="RegisterForm" name="RegisterForm" action="" method="post"> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 20, 2015 Share Posted October 20, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 20, 2015 Share Posted October 20, 2015 I have had to tell people about the empty action not being spec so many times I am actually burned out on that subject. People don't seem to grasp that things change when versions change and what was once OK may not be anymore. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted October 20, 2015 Share Posted October 20, 2015 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? Quote Link to comment Share on other sites More sharing options...
hansford Posted October 20, 2015 Share Posted October 20, 2015 (edited) 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 October 20, 2015 by hansford Quote Link to comment Share on other sites More sharing options...
Strider64 Posted October 20, 2015 Share Posted October 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 20, 2015 Share Posted October 20, 2015 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.