By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Sep 25 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Baldaris wrote:
Hi
if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
"register" ); {
Should be
if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) == "register" ){
Without the ';'
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
Sep 25 '08 #2

P: n/a
Baldaris wrote:
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.
js*******@attglobal.net
==================

Sep 25 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.