Connecting Tech Pros Worldwide Help | Site Map

Need help with php script --***********Caution Newbie***********

Baldaris
Guest
 
Posts: n/a
#1: Sep 25 '08
Hi
I am using Xampp , Php 5.2.6 and phpedit for wiriting code.

i am trying to add the content's from user form and then add then
into the data base.

It check's if submit is clicked or not , Then if any of the field's
are empty -- It should show an error , it shold check if user name is
there in the data base or not...if yes show error message otherwise
insert into database.
I am getting error if any can help me figure what i am doing wrong

if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
"register" ); {
if ( $_POST['username'] != "" && $_POST['password'] != "" &&
$_POST['first_name'] != "" && $_POST['last_name'] != "" &&
$_POST['email'] != "" ) {
$query = "SELECT username from user_info WHERE username = " .
$_POST['username'] . " ;";
$result = mysql_query( $query ) or die( mysql_error() );

if ( mysql_num_rows != 0 ) {
echo $_POST['username'] . "already in use";

?>
<form action="register.php" method="POST">
<?php
form_display(); -- a function to display text box for
username , password m first name,last name , city ,state

?>
<?php
} else {
$query = "INSERT INTO user_info
(username,password,email,first_name,last_name,city ,state) " . "VALUES
('" . $_POST['username'] . "' ,' " . $_POST['password'] . "','" .
$_POST['email'] . "' , ' " . $_POST['first_name'] . "',' " .
$_POST['last_name'] . "
' , ' " . $_POST['city'] . "',' " . $_POST['state'] . "' );";
$result = mysql_query( $query ) or die( mysql_error() );
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['user_password'];
?>
<p>
Thank you, <?php echo $_POST['first_name'];
?for Registering<br>
</p>
<?php
header( "refresh:0 ;URL=index.php" );
die();
}
} else {

?>
<b>The username , Password , Email ,First Name , Last name are
required</b>
<form action="register.php" method="POST">
<?php
form_display();
}

?>
<?php } else { -- i am getting an error in this line.

?>
<p>Welcome to the Registration Page
<form action="register.php" method="POST">
<?php
form_display();--a function to display text box for username ,
password m first name,last name , city ,state

?>
</p>
<?php
}

?>
</body>
</html>

i have been trying to get it work , if anyone can tell me what i am
doing wrong i would really appreciate it.
Thank's in advance
Baldaris

Floortje
Guest
 
Posts: n/a
#2: Sep 25 '08

re: Need help with php script --***********Caution Newbie***********


Baldaris wrote:
Quote:
Hi
Quote:
if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
"register" ); {
Should be
if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) == "register" ){
Without the ';'
Quote:
i have been trying to get it work , if anyone can tell me what i am
doing wrong i would really appreciate it.
Thank's in advance
You could also try to clean up your code. Seperate the logic from the
layout for example or create a few funtions. A verry simple one would be:

function CheckEmptyPostFields(array('username','pass','etc' ));
$aEmptyFields = array;

foreach($aArray as $sField){

if(empty($_POST[$sField])){
array_push($aEmptyFields,$sField);
}

}
return $aEmptyField;
}


$aEmptyFields = CheckEmptyPostFields(array('username','pass','etc' ));

Floortje


Jerry Stuckle
Guest
 
Posts: n/a
#3: Sep 25 '08

re: Need help with php script --***********Caution Newbie***********


Baldaris wrote:
Quote:
Hi
I am using Xampp , Php 5.2.6 and phpedit for wiriting code.
>
i am trying to add the content's from user form and then add then
into the data base.
>
It check's if submit is clicked or not , Then if any of the field's
are empty -- It should show an error , it shold check if user name is
there in the data base or not...if yes show error message otherwise
insert into database.
I am getting error if any can help me figure what i am doing wrong
>
if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
"register" ); {
if ( $_POST['username'] != "" && $_POST['password'] != "" &&
$_POST['first_name'] != "" && $_POST['last_name'] != "" &&
$_POST['email'] != "" ) {
$query = "SELECT username from user_info WHERE username = " .
$_POST['username'] . " ;";
$result = mysql_query( $query ) or die( mysql_error() );
>
if ( mysql_num_rows != 0 ) {
echo $_POST['username'] . "already in use";
>
?>
<form action="register.php" method="POST">
<?php
form_display(); -- a function to display text box for
username , password m first name,last name , city ,state
>
?>
<?php
} else {
$query = "INSERT INTO user_info
(username,password,email,first_name,last_name,city ,state) " . "VALUES
('" . $_POST['username'] . "' ,' " . $_POST['password'] . "','" .
$_POST['email'] . "' , ' " . $_POST['first_name'] . "',' " .
$_POST['last_name'] . "
' , ' " . $_POST['city'] . "',' " . $_POST['state'] . "' );";
$result = mysql_query( $query ) or die( mysql_error() );
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['user_password'];
?>
<p>
Thank you, <?php echo $_POST['first_name'];
?for Registering<br>
</p>
<?php
header( "refresh:0 ;URL=index.php" );
die();
}
} else {
>
?>
<b>The username , Password , Email ,First Name , Last name are
required</b>
<form action="register.php" method="POST">
<?php
form_display();
}
>
?>
<?php } else { -- i am getting an error in this line.
>
?>
<p>Welcome to the Registration Page
<form action="register.php" method="POST">
<?php
form_display();--a function to display text box for username ,
password m first name,last name , city ,state
>
?>
</p>
<?php
}
>
?>
</body>
</html>
>
i have been trying to get it work , if anyone can tell me what i am
doing wrong i would really appreciate it.
Thank's in advance
Baldaris
>
>
"I am getting error if any can help me figure what i am doing wrong" is
not very descriptive. What error are you getting?

One thing I do see right off hand -

if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) == "register" ); {

There should NOT be a semicolon at the end of this.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Closed Thread