I have
$username = user_name
$firstname = first_name
$lastname = last_name
addedby = $firstname' . '$lastname
If firstname and lastname are both blank, I'd like addedby to be username.
Any help would be greatly appriciated.
Thanks.
variable is blank, how to replace with something else?
Moderator: General Moderators
-
PHP Nubsauce
- Forum Newbie
- Posts: 2
- Joined: Sat Jun 07, 2008 10:22 pm
Re: variable is blank, how to replace with something else?
Hard to tell what you are trying to accomplish but I'll post this:
a varibale is set like:
$firstname = "Bill"
$lastname = "jacobs";
or, if you're using $_POST like this: $firstname = $_POST['first_name'];
if you want to assign one variable to another you can do:
$username = $firstname';
$username now holds the value "bill";
if you want to string 2 variables together you can do:
$addedby = $firstname . $lastname;
$addedby now holds the value "billjacobs";
wow thats ugly! lets try that again.
$addedby = $firstname . " " . $lastname;
$addedby now holds the value "bill jacobs";
a varibale is set like:
$firstname = "Bill"
$lastname = "jacobs";
or, if you're using $_POST like this: $firstname = $_POST['first_name'];
if you want to assign one variable to another you can do:
$username = $firstname';
$username now holds the value "bill";
if you want to string 2 variables together you can do:
$addedby = $firstname . $lastname;
$addedby now holds the value "billjacobs";
wow thats ugly! lets try that again.
$addedby = $firstname . " " . $lastname;
$addedby now holds the value "bill jacobs";
Re: variable is blank, how to replace with something else?
Once you have the variables firstname, lastname and username you can just run and if statement. In the example, the firstname etc are being posted from a form.
John
Code: Select all
<?php
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$username = $_POST['user_name'];
if (($firstname=="") AND ($lastname=="")) {
$addedby = $username;
} else {
$addedby = $firstname . " " . $lastname;
}
?>