473,549 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with php script --***********Caut ion 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="registe r.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,passw ord,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="registe r.php" method="POST">
<?php
form_display();
}

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

?>
<p>Welcome to the Registration Page
<form action="registe r.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 1753
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 CheckEmptyPostF ields(array('us ername','pass', 'etc'));
$aEmptyFields = array;

foreach($aArray as $sField){

if(empty($_POST[$sField])){
array_push($aEm ptyFields,$sFie ld);
}

}
return $aEmptyField;
}
$aEmptyFields = CheckEmptyPostF ields(array('us ername','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="registe r.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,passw ord,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="registe r.php" method="POST">
<?php
form_display();
}

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

?>
<p>Welcome to the Registration Page
<form action="registe r.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*******@attgl obal.net
=============== ===

Sep 25 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2236
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 value="1">Main</option> <option value="2">Main > Computers</option> <option value="4">Main > Computers > Hardware </option>
6
1773
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
1596
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 elements when the document is loaded so they can be used by other functions used as event handlers. What I have now is that every function that...
6
1569
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 name. but they put their own script at the bottom of everypage, that places their banner at the top, im looking for a way to stop that script, Let...
4
4794
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 page. Each time when asp.net page refresh the script function is to be called and has to be replaced all files in server folder.
0
1325
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
1471
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. Unfortunately not everyone cleans up after themselves, so I need a script that can prune out all the files older than 30 days but leave the folders. ...
1
2070
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 new instance, but I need a script to pull out the require information from sysjobs, etc. to recreate the jobs. Please help! Thanks, trace
0
7459
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
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 we have to send another system
0
772
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.