Forum Moderators: coopster
I'm totally new to PHP. However, I've managed a lot so far but am stuck.
I'm building a custom thank you page which passes variables via _Post method and it's working out great.
However, I need help. The thank you page lists customer name, address, totals, etc.
If a customer only enters their day time phone number and not their home phone number, I need the row saying "Home Phone" to just not pull up at all.
Here are the rows:
<tr><td>Work Phone:</td><td>$workphone</td></tr>
<tr><td>Home Phone:</td><td>$homephone</td></tr>
<tr><td>Email:</td><td>$email1</td></tr>
<tr><td>Address 1:</td><td>$address1</td></tr>
<tr><td>City:</td><td>$city</td></tr>
<tr><td>State/Province:</td><td>$state</td></tr>
<tr><td>Country:</td><td>$country</td></tr>
<tr><td>ZIP/Postal:</td><td>$zip</td></tr>
I need the second row to just not even apeark if the Home Phone number wasn't filled out in the cart.
Here's my post command: $homephone = $_POST['homephone'];
This is something I tried for the second row but I don't know if I have the wrong syntax or if I'm just totally off:
if ( $homephone = $_POST['homephone'] ) {
echo '<tr><td>Home Phone:</td><td>$homephone</td></tr>';
} else {
echo '';
}
Any help would be VERY appreciated!
Thanks...
Here's a quick example of what I have just under the <body>
<?php
$workphone = $_POST['workphone'];
$homephone = $_POST['homephone'];
"and more listed but I won't list them here"
echo"
Then my html code which provides the really nice thank you page design. All the variables pass just fine and it looks great.
Above is listed some of the code which works fine. This is what I've attempted to try in order to remove the home phone row:
<tr><td>Work Phone:</td><td>$workphone</td></tr>
if ( $homephone == $_POST['homephone'] ) {
echo '<tr><td>Home Phone:</td><td>$homephone</td></tr>';
} else {
echo '';
}
<tr><td>Email:</td><td>$email1</td></tr>
However, I now get a Parse Error for the line starting with if
But, are you saying d40, to make the code look like this?
<tr><td>Work Phone:</td><td>$workphone</td></tr>
$homephone == $_POST['homephone'];
//if homephone contains 10 or more digits
if(strlen($homephone)>=10){
echo '<tr><td>Home Phone:</td><td>$homephone</td></tr>';
}
<tr><td>Email:</td><td>$email1</td></tr>
I still get a parse error...but I feel I'm really close.
Thanks!
echo "<tr><td>Email:</td><td>$email1</td></tr>";
this snippet i gave u checks for the lenght of the phone number string that was entered. depending on what you want to do, consider using the isset() function as londrum suggested. this checks if the variable is set. but of course, even if the user left this field empty and hit submit, isset would still return true. so only use this check in addition to other methods of variable validation. when you get more into php, you'll find yourself using several functions to check your data.
Yes, the code above the if statement didn't ";. I had forgotten the ;.
So just before the if statement started:
<tr><td>Work Phone:</td><td>$workphone</td></tr>";
I had forgotten the ;
Following:
if ($homephone){
echo "<tr><td>Home Phone:</td><td>$homephone</td></tr>";
} else {
echo "";
}
echo"
<tr><td>Email:</td><td>$email1</td></tr>
and so on to the end....
Thanks everyone!