Ebniax.Axel
Ebniax.Axel

Reputation: 3

sending data from form to database not working (php, sql)

I'm making a simple registration form for a test website and for some reason it isn't sending the data to the database, and I don't get an visual error. I've searched around for a fix but haven't found any that work.

This is basically my form (I only copied the form part of the page):

    <form action="includes/insert.php" method="post">
        <h3>Username</h3>
        <input type="text" name="username">
        <br>
        <br>
        <h3>Email Address</h3>
        <input type="email" name="email">
        <br>
        <br>
        <h3>Password</h3>
        <input type="password" name="password">
        <br>
        <br>
        <br>
        <input id="submit-btn" type="submit" name="submit" value="Submit">
    </form>

As you can see everything is as its suppose to be.

and this is my insert.php

<?
define('DB_NAME', 'logindb');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];

$sql = "INSERT INTO `users` (`id`, `username`, `email`, `password`, `timestamp`) VALUES (NULL, '$username', '$email', '$password', CURRENT_TIMESTAMP)";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}

mysql_close();
?>

Upvotes: 0

Views: 85

Answers (2)

muya.dev
muya.dev

Reputation: 977

Use NOW() instead of CURRENT_TIMESTAMP.

Upvotes: 0

Duane Lortie
Duane Lortie

Reputation: 1260

Opening PHP tag is

<?php 

Recent versions of PHP do not enable the short code syntax by default.

Upvotes: 1

Related Questions