Jump to content

[SOLVED] Registeration Problem


Garcia

Recommended Posts

I am currently making a script to register and some reason the query isn't running...

Main Script:
[code]
<?php
/* Registeration Form
// Date Started: January 7th, 2007
// Created by Brian Garcia
// Ticket System v. 1.0
*/
session_start();
require ("config.php");

switch (@$_POST['do'] )
{
case "new":
//Checks to see if the fields are blank. If so form resets with error.
foreach($_POST as $field => $value)
{
if ($value == "")
{
$blanks[] = $field;
}
}

if(isset ($blanks) )
{
$error_new = "You can not submit fields with nothing written! Please enter the required information: ";
    foreach ($blanks as $value)
{
$error_new .= "$value, ";
}
extract ($_POST);
include("register_form.php");
exit();
}

//Checks the forms for illegal characters.
foreach ($_POST as $field => $value)
{
if (!empty ($value) )
{
if (eregi ("name", $field) and
!eregi ("login", $field))
{
if (!ereg ("^[A-Za-z' -] {1, 50}$", $value) )
{
$errors[] = "$value is not a valid name.";
}
}
if (eregi ("email", $field) )
{
  if (!ereg ("^.+@.+\\..+$", $value) )
{
  $errors[] = "$value not a valid email address.";
}
}
}
}

if (@is_array ($errors) )
{
$error_new = "";
foreach ($errors as $value)
{
$error_new .= $value."Please try again<br />";
}
extract ($_POST);
include("register_form.php");
exit();
}

//clean data

$sql = "SELECT loginName FROM members WHERE loginName = '$loginName'";
$result = mysql_query ($sql, $con)
or die ("Couldn't execute select query");
$num = mysql_num_rows ($result);
if ($num > 0)
{
$error_new = "$loginName already used. Select another User Name.";
include ("register_form.php");
exit();
}

//Time to Add the new member
else
{
  $sql = "insert into members (loginName, password, email) values ('$loginName, $password, $email')";
  $rs = mysql_query ($sql, $con)
  or die ("Couldn't execute");

$_SESSION['auth'] = "yes";
$_SESSION['logname'] = $loginName;

//Email being sent
$email_mess = "Thank You, your new Member Account has been set up.";
$email_mess.= "Your new Member ID and Password are: ";
$email_mess.= "\n\n\t$loginName\n\t$password\n\n";
$email_head = "From: support@trueamericanlife.com\r\n";
$subj = "New Member Account from Ticket System";
$mailsend=mail ("$email", "$subj", "$email_mess", "$email_head");
header("Location: new_member.php");
}
break;

default:
include ("register_form.php");

}

?>
[/code]

Config Script:
[code]
<?php
$host = "localhost";
$dbUser = "garcia_ticketsys";
$dbPass = "******";
$database = 'garcia_ticketsystem';

$con = mysql_connect("$host", "$dbUser", "$dbPass");
if (!$con)
{
die('Could not connect: ' .mysql_error() );
}

@mysql_select_db($database) or die( 'Unable to select database');

?>
[/code]

Here is my form:
[code]
<html>
<head><title>Registeration Form</title></head>
<body>
Already a Member? <a href="login.php">Log In</a><br/>

<?php
if (isset($error_new) )
{
print "$error_new";
}
?>

<br/>
<form action="register.php?do=new" method="POST">
Member Name: <input type="text" name="loginName" value="<?php print $loginName ?>" size="20" /><br />
Password: <input type="password" name="password" value="<?php print $password ?>" size="20" /><br />
Email Address: <input type="text" name="email" value="<?php print $email ?>" size="40" /><br />
<input type="hidden" name="do" value="new">
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>
[/code]

The problem I am having is that it won't execute the query. Any help is much appreciated.

Thanks
Link to comment
Share on other sites

yes, what do you mean when you say "it's not executing." are you getting your die message? If so, change it to this:
[code]
$rs = mysql_query ($sql, $con) or die ("query: $sql <br/>" . mysql_error());
[/code]

look at the query string that is actually being sent. maybe you'll figure out a mistake from it.  Or look at the error; maybe you'll figure out the mistake then.  If not, please post that stuff here.
Link to comment
Share on other sites

This is the query:

[code]
  $sql = "insert into members (loginName, password, email) values ('$loginName, $password, $email')";
  $rs = mysql_query ($sql, $con)
  or die ("Couldn't execute");
[/code]

I checked the table and in fact isn't inserting any data, and yes I am getting the Couldn't Execute message.
Link to comment
Share on other sites

Guest
This topic is now 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.