473,486 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
2 1746
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2230
by: Brian Murphy | last post by:
<?php /* I need your help. I'd be very thankfull if write me this script.I need a script that displays a list of categories and subcategories like this: <select name="category"> <option...
6
1769
by: Christopher Benson-Manica | last post by:
I have some markup like the following: <form> <table> <script> <!-- Write the table markup //--> </script> </table> <form>
3
1590
by: Christopher Benson-Manica | last post by:
I appreciate all the responses to my earlier post about accessing named elements. However, I'm still wondering about my actual problem, which is that I need to initialize some arrays of named...
6
1565
kestrel
by: kestrel | last post by:
Hey, I need a script that will disable all scripts after a certain point. Is that possible? See, the problem is, my friend has a site, hosted free by a website where he bought the domain...
4
4789
by: karthiknd | last post by:
hi everyone , i need a script which copy folder from one system and has to be replaced in server folder which is in another system. This java script has to be called in asp.net...
0
1316
by: alcan-rally | last post by:
Please need Classified script with payment option I am looking for MojoScripts or delata script or 68classifieds or GeoClassifieds Thanks
1
1465
by: Phydeux | last post by:
I've got a folder area on our file server (Win 2003) where our copiers deposit scans so users can pick them up. The structure is ..\Scanned Files\Username\ where the username is that user's name. ...
1
2057
by: traceable1 | last post by:
I created a new database instance, but I forgot to script out the scheduled jobs before I wiped out the original database instance. I have attached the original msdb database as msdb_old onto the...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.