473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Check if Input was filled, if not - continue with script

Hiya. I have a script that is run by a <form> which basically allows u to write into inputs the fields username, new username, password, repeat password, comment etc,

The problem is that I want the script to work in a way that, if a field, like the 'new username' has not been touched (no value), then the username wont be changed.

The same kind of rule would go for the other inputs, so that only parts of a user can be edited at a time, without affecting other data.

Im using this script:

Expand|Select|Wrap|Line Numbers
  1. // EDIT USERNAEME
  2.  
  3.  if ((strlen($username)!==0)||(UserInDB($_POST["username"])))
  4.    //if(empty($_POST["newusername"]))
  5.    {
  6.     if (!(UserInDB($_POST["newusername"])))
  7.      {
  8.         mysql_query("UPDATE Users SET login='".$_POST["newusername"]."' WHERE login='".$username."'");
  9.         $oldname=$_POST["username"];
  10.         $newname=$_POST["newusername"];
  11.         echo $user_edited_name=' <b> The user <font color="#FFFFFF"><u>" '.$oldname.' "</u></font> was renamed to <font color="#FFFFFF"><u>" '.$newname.' "</u></font> in the user database.</b> ';
  12.         //echo '<meta http-equiv="Refresh" content="2; url=index.php"> ';
  13.      }
  14.    }
where
Expand|Select|Wrap|Line Numbers
  1.  if ((strlen($username)!==0)||(UserInDB($_POST["username"])))
Is supposed to check if the field newusername has been used,
and the function

Expand|Select|Wrap|Line Numbers
  1. if (!(UserInDB($_POST["newusername"])))
Checks if the user (from input "username") exists in the database.

The only problem is that the 'check if field was used' string doesnt work at all. If I want to update a different field, like "comment", I only input the username and leave newusername empty, but the user still gets renamed into " " (nothing).
You also see signs of trying the empty() function, which didnt help.
At least not how I tried it.


So how do I fix this?
Thanks
Dec 9 '09 #1
3 3666
code green
1,726 Expert 1GB
Where does $username come from
Expand|Select|Wrap|Line Numbers
  1. if ((strlen($username)!==0
Do you have register globals switched on?
It looks like if $username is empty.
Dec 10 '09 #2
Oh yeah, how silly. That could be the error.

Edit: I checked my file and I actually have $username defined at the top, because it is used other places in the script.

I'm very new to PHP still, so could it be some character or symbol error in there?

This error is something that also occurs for different fields, like 'comment'.
So I cant simply update individual data on a user, since it just updates with the empty fields.

I really need some help to fix this :(
Dec 11 '09 #3
kovik
1,044 Expert 1GB
You are using "empty()" inside of your failing if-statement...

Using empty() is like checking if the variable is set and if it is non-empty and nonzero. The data you are checking is from a posted form, right? Then you only need to check in the $_POST array.

First, check if the $_POST array is non-empty. If so, then the form has been submitted. Secondly, check for the entry in the $_POST array that you are interested in. If it is non-empty, then it was successfully filled and submitted.

Also, $username should have no effect on the outcome, so I'm not sure why you are checking it...
Dec 12 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gleep | last post by:
Hi PHP coders, I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows. In each row there is a check box - then 4 input fields. I already have the code...
2
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head>...
5
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab...
3
by: frizzle | last post by:
Hi there, I'm building a multi-language PHP/mySQL -site. I'm also building a CMS for the site. There are 5 languages. In the CMS fields for e.g. english bodytext are called (id=)...
5
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
5
by: Clive Backham | last post by:
I'm having trouble with Instant Payment Notification on PayPal. One of the forms that they generate, which invokes one of my scripts, has a submit button with a blank name. The HTML fragment is...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the...
2
by: jackson2005 | last post by:
OK, I need to do three different things. On the ONLOAD event I would like a popup box to open. In this popup box I need two text boxes. One for the UserName and one for the BillingTo name. ...
14
by: ankitmathur | last post by:
Hi, I'm facing a pretty peculiar problem. In one of my pages I print the number of rows depending upon the number of Qty I got filled in my previous page i.e. If Qty is filled in as 3 in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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,...
0
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...

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.