Jump to content

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

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.