PDA

Click to See Complete Forum and Search --> : Help!!


kiwis
Apr 1st, 2004, 06:52 PM
What is the problem with this script?


<?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_m oderator_flag','$user_admin_flag','$register_code','$user_real_name','$location','$age','$sex','$sea son_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_m oderator_flag','$user_admin_flag','$register_code','$user_real_name','$location','$age','$sex','$sea son_tkt_no')");

}else{
echo "That username is already in use.\n";
}
} else {
?>

Crap

<?php
}
?>

kows
Apr 1st, 2004, 07:51 PM
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.

kows
Apr 1st, 2004, 07:57 PM
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:
$qry = mysql_query("SELECT user_name FROM DB_Wsers WHERE user_name='$user_name' LIMIT 1")
change it to:
$qry = mysql_query("SELECT user_name FROM DB_Wsers WHERE user_name='$user_name' LIMIT 1");

kiwis
Apr 1st, 2004, 08:55 PM
Ok, if both are fine it add the record twice why?

kows
Apr 1st, 2004, 10:40 PM
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:
<?
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";
}
?>

kiwis
Apr 1st, 2004, 11:11 PM
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:
<?
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