Jump to content

Why isnt this working?


Kryllster

Recommended Posts

This code is almost a carbon copy of code that works. I am trying to create a simple account creation script and I have been working on it trying different things and still cant insert the data into the mysql database. Here is the code.

 

<?php
$message = "Please do NOT leave any fields empty Thank You!!";
$nickname = $_POST['nickname'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$email = $_POST['email'];

if (
    empty($_POST['nickname']) ||
    empty($_POST['firstname']) ||
    empty($_POST['lastname']) ||
    empty($_POST['password']) ||
    empty($_POST['email'])
  ) {
    echo $message;
    exit();
  }

// connect to database
include('scripts/db_config.php');

// Test for duplicate Username. If True then back to form. If not continue.
$sql = "select * from $tbl_name where nickname='" . $_POST['nickname'] . "'"; 
$result = mysql_query($sql);
if (mysql_num_rows($result) >= 1) { 
	echo "That Nickname is already taken please choose another!";
	exit();
	}

// continue if all these checks are ok Im hoping
else {		
// Populate table from form and defined info
mysql_query("INSERT INTO $tbl_name (nickname, firstname, lastname, password, email) VALUES('$nickname','$firstname','$lastname','$password','$email')");

// Close Database
	mysql_close();

// Direct on Creation Success
header("Location:index.php?show=success");

}
?>

 

Any ideas why this may not be working properly?

Link to comment
https://forums.phpfreaks.com/topic/198251-why-isnt-this-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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