1

I'm having trouble with data not saving to a table, I've got the following code in a file called Register.php, I have enabled error_reporting to see any errors, but none are showing. My database is called Registration and the table is called users and is being hosted on GoDaddy

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

<?php
if(isset($_Post['Register'])) {

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

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

}
?>

<!doctype html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<link href="Style/Master.css" rel="stylesheet" type="text/css" />
<title>Register</title>
</head>
<body>
<form action="" method="post" name="RegisterForm" id="RegisterForm">

    <div class="FormElement">
        <input name="First_Name" type="text" required="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="Username" type="text" required="required" class="TField" id="Username" placeholder="Username">
    </div>

    <div class="FormElement">
        <input name="Email" type="text" required="required" class="TField"   id="Email" placeholder="Email">
    </div>

    <div class="FormElement">
        <input name="Password" type="text" required="required" class="TField" id="Password" placeholder="Password">
    </div>

    <div class="FormElement">
        <input name="Register" type="submit" class="button" id="Register"        placeholder="Register">
    </div>
</body>
</html>

This is the code in the Connections.php just without my real username and password

<?php

$con = mysql_connect("localhost", "USERNAME", "PASSWORD", "Registration");

?>

Any help would be very much appreciated!

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • update -- "INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')" – CodeLove Nov 06 '15 at 12:20
  • you are using procedural style and object oriented style..... !!!!!!! – CodeLove Nov 06 '15 at 12:22
  • PHP is case sensitive. `$_POST` needs to be in capitals. You have `if(isset($_Post['Register']))` – ImClarky Nov 06 '15 at 12:24
  • see -- http://php.net/manual/en/function.mysql-connect.php – CodeLove Nov 06 '15 at 12:25
  • Working now, Thank you very much! – Matthew Ralston Nov 06 '15 at 13:51
  • Do you know that your code will not work in PHP 7 (future version of PHP) and that `mysql_*` functions are deprecated since a long time ? – F__M Nov 06 '15 at 15:22
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Aug 04 '16 at 11:56

2 Answers2

0

Try this

mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());
Arvind Jaiswal
  • 442
  • 5
  • 14
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Aug 04 '16 at 11:56
0

You need to edit the Connection.php

mysql_connect("localhost", "USERNAME", "PASSWORD"); 
mysql_select_db("Registration");  //your data base name

And also you have to edit

 mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());
Abdul Razak
  • 2,654
  • 2
  • 18
  • 24
  • Working now, Thank you very much! – Matthew Ralston Nov 06 '15 at 13:51
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Aug 04 '16 at 11:56