-
Help!!
What is the problem with this script?
PHP Code:
<?php
mysql_connect (localhost, user, password);
mysql_select_db (nz);
$qry = mysql_query("SELECT user_name FROM DB_Wsers WHERE user_name='$user_name' LIMIT 1")
if ($_POST['action'] == 'save') {
if($_POST['user_password'] == $_POST ['user_password_confirm']){
$result = mysql_query ("INSERT INTO DB_Users Values ('','$user_name','$user_email','$user_password','$user_pending_flag','$user_suspended_flag','$user_moderator_flag','$user_admin_flag','$register_code','$user_real_name','$location','$age','$sex','$season_tkt_no')");
}else{
echo "Sorry";
}
$arr = mysql_fetch_array($qry);
if($arr[0] == ""){
$result = mysql_query ("INSERT INTO DB_Users Values ('','$user_name','$user_email','$user_password','$user_pending_flag','$user_suspended_flag','$user_moderator_flag','$user_admin_flag','$register_code','$user_real_name','$location','$age','$sex','$season_tkt_no')");
}else{
echo "That username is already in use.\n";
}
} else {
?>
Crap
<?php
}
?>
-
uh.. if you're posting scripts, don't just ask 'what is wrong with this?'.. give a description of what you want, what you're getting instead, including any parse errors.
-
nevermind, you're missing a semi-colon on your mysql_query() call in this script too..
add a semi-colon to the end of line 4 after the bracket.
line 4 is this line:
PHP Code:
$qry = mysql_query("SELECT user_name FROM DB_Wsers WHERE user_name='$user_name' LIMIT 1")
change it to:
PHP Code:
$qry = mysql_query("SELECT user_name FROM DB_Wsers WHERE user_name='$user_name' LIMIT 1");
-
Ok, if both are fine it add the record twice why?
-
uhh.. really, you should look into actually learning PHP a bit more..
you've got two queries that insert information into the database at two different points.. you only want one instance where you are inserting data, not two.
your script should be structured something like this, fill in the blanks:
PHP Code:
<?
if($action == "save"){
if($password1 == $password2){
if($user[0] == ""){
//insert user information to database
}else{
echo "user already exists";
}
}else{
echo "passwords don't match";
}
}else{
echo "action is not to save";
}
?>
-
Quote:
Originally posted by kows
uhh.. really, you should look into actually learning PHP a bit more..
you've got two queries that insert information into the database at two different points.. you only want one instance where you are inserting data, not two.
your script should be structured something like this, fill in the blanks:
PHP Code:
<?
if($action == "save"){
if($password1 == $password2){
if($user[0] == ""){
//insert user information to database
}else{
echo "user already exists";
}
}else{
echo "passwords don't match";
}
}else{
echo "action is not to save";
}
?>
I don't use it enough to worry about learning a lot about it