Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Please help with if/then statement
Old 05-30-2008, 07:49 PM Please help with if/then statement
Experienced Talker

Posts: 46
Name: Brent
Trades: 0
So I am not really good at PHP. I can do the basic forms and it works well. Now I am trying something a little more than basic, and I don't know how to do if/then statements. I could pull something out of my butt, but I know that won't work.

The setup:
I am doing an online form for a vehicle carrier. Generally the customer only needs to input information for one vehicle. Sometimes, however, they may need to input information for a few. The vehicle infromation that is essential is 'transportation mode,' 'year,' 'make,' 'model,' 'vin #,' and 'registered owner.' 'Transportation mode' is a multi-choice radio, the rest are text boxes.

Now when you go onto the form, only one vehicle information block is show (called Vehicle #1) , the other four (Vehicles #2-5) are in hidden div tags, once you click on the "Add Another Vehicle" button at the end of one vehicle information block, the next one is shown.

The concept:
Since a client will always have to ship at least one vehicle, the required information for Vehicle #1 will be always in place (you know, if the don't fill in these specific text boxes, they cannot send the form), that part I have down fine. It's the other part that is my problem.

Obviously if they aren't going to be shipping 5 vehicles, I cannot have the form refusing to send because information was not filled out on Vehicles #2-5. I do, however, want some statement that IF the client started filling out information on vehicle 2, 3, 4, or 5, (for example picked the transport mode radio 'mode02') THEN the year, make, model, vin, and owner must be filled out on that vehicles information in order to send the form.

The problem:
I have no idea how to do that.


I hope I have been clear and consice, and I am sure that you guys here can help. I jsut hope I can understand it!

Thanks
cruizer is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-30-2008, 09:24 PM Re: Please help with if/then statement
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
It will REALLY help us if you could post the html and php code you have in place now so we don't have to re-invent the wheel - Thx!
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-30-2008, 09:36 PM Re: Please help with if/then statement
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I guess you have done BASIC, if you are calling it an if/THEN statement. There is no 'then' command in PHP, it uses C style with {} to encase the statement.

PHP Code:
if (condition) {
statement//comment

Maybe that is not very helpful, but it's a start
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-31-2008, 01:00 AM Re: Please help with if/then statement
Experienced Talker

Posts: 46
Name: Brent
Trades: 0
I am sure I am going to do something really stuipid, probably post more than you need..... But you don't need to re-invent the wheel.

And Wayfarer07, oh yeah, I had a semester of VB like 8 years ago. So please pardon the fact I don't really know what I am talking about.

Also, I guess since were here, if possible, I would really like the email the form is sending and output page only give information on the additional vehicles if they fill in those fields. For example, if they fill in the information for vehicle one, then 2,3,4 and 5 don't get sent. if they do 1 & 2, 3,4 and 5 don't get sent, etc etc. If I'm asking too much, or you think too much for my skill level, then please by all means, let me know.

FYI, you can see my test page hands on at:
http://clrauto.cgsart.com/shippingorder.html
Feel free to play with it. The emails are being sent to me, so it's OK to hit subhmit to see th output page.

HTML Code:
<table>
<tr><td>
All fields marked with an asterik (<font color="red">*</font>) <font color="red">are required.</font>
</td></tr>
<tr><td>
&nbsp;
</td></tr>
<tr><td>
<b>Part 1 - Vehicle Information and Availability</b><br />
<b>Vehicle #1</b><br />
Transportation via (select one)<font color="red">*</font>: &nbsp;&nbsp;<input type="radio" value="Open Carrier" 
name="via1">Open Carrier &nbsp;&nbsp;<input type="radio" value="Closed Carrier" name="via1">Closed Carrier &nbsp;&nbsp;<input 
type="radio" value="Professional Drive Away" name="via1">Professional Drive Away<br />
</tr><td>
<tr><td>
Is the vehicle in running condition? &nbsp;&nbsp;<input type="radio" value="Yes" name="running1">Yes &nbsp;&nbsp;<input 
type="radio" value="No" name="running1">No<br />
</tr></td>
<tr><td>
Year<font color="red">*</font>:<input type="text" class="text" name="year1" size="5">  &nbsp;&nbsp;Make<font 
color="red">*</font>:<input type="text" class="text" name="make1" size="10">  &nbsp;&nbsp;Model<font 
color="red">*</font>:<input type="text" class="text" name="model1" size="10"><br />
</tr><td>
<tr><td>
Color:<input type="text" class="text" name="color1" size="10"> &nbsp;&nbsp;license Plate# (if available):<input type="text" 
class="text" name="license1" size="6"> &nbsp;&nbsp;Vin #<font color="red">*</font>:<input type="text" class="text" 
name="vin1" size="15">
</tr></td>
<tr><td>
Registered Owner<font color="red">*</font>:<input type="text" class="text" name="reg1" size="25"> 
</tr></td>
<tr><td>
<input type="button" name="add1" value="Add Another Vehicle" onClick="showHide('show2')">
</tr><td>
</table>
 
<!-- Vehicle #2 -->
<div id="show2" style="display:none;"> 
<br />
<table>
<tr><td>
<b>Vehicle #2</b><br />
Transportation via (select one)<font color="red">*</font>: &nbsp;&nbsp;<input type="radio" value="Open Carrier" 
name="via2">Open Carrier &nbsp;&nbsp;<input type="radio" value="Closed Carrier" name="via2">Closed Carrier &nbsp;&nbsp;<input 
type="radio" value="Professional Drive Away" name="via2">Professional Drive Away<br />
</tr><td>
<tr><td>
Is the vehicle in running condition? &nbsp;&nbsp;<input type="radio" value="Yes" name="running2">Yes &nbsp;&nbsp;<input 
type="radio" value="No" name="running2">No<br />
</tr></td>
<tr><td>
Year<font color="red">*</font>:<input type="text" class="text" name="year2" size="5">  &nbsp;&nbsp;Make<font 
color="red">*</font>:<input type="text" class="text" name="make2" size="10">  &nbsp;&nbsp;Model<font 
color="red">*</font>:<input type="text" class="text" name="model2" size="10"><br />
</tr><td>
<tr><td>
Color:<input type="text" class="text" name="color2" size="10"> &nbsp;&nbsp;license Plate# (if available):<input type="text" 
class="text" name="license2" size="6"> &nbsp;&nbsp;Vin #<font color="red">*</font>:<input type="text" class="text" 
name="vin2" size="15">
</tr></td>
<tr><td>
Registered Owner<font color="red">*</font>:<input type="text" class="text" name="reg2" size="25"> 
</tr></td>
<tr><td>
<input type="button" name="add1" value="Add Another Vehicle" onClick="showHide('show3')">
</tr><td>
</table>
</div>
 
<!-- Vehicle #3 -->
<div id="show3" style="display:none;"> 
<br />
<table>
<tr><td>
<b>Vehicle #3</b><br />
Transportation via (select one)<font color="red">*</font>: &nbsp;&nbsp;<input type="radio" value="Open Carrier" 
name="via3">Open Carrier &nbsp;&nbsp;<input type="radio" value="Closed Carrier" name="via3">Closed Carrier &nbsp;&nbsp;<input 
type="radio" value="Professional Drive Away" name="via3">Professional Drive Away<br />
</tr><td>
<tr><td>
Is the vehicle in running condition? &nbsp;&nbsp;<input type="radio" value="Yes" name="running3">Yes &nbsp;&nbsp;<input 
type="radio" value="No" name="running3">No<br />
</tr></td>
<tr><td>
Year<font color="red">*</font>:<input type="text" class="text" name="year3" size="5">  &nbsp;&nbsp;Make<font 
color="red">*</font>:<input type="text" class="text" name="make3" size="10">  &nbsp;&nbsp;Model<font 
color="red">*</font>:<input type="text" class="text" name="model3" size="10"><br />
</tr><td>
<tr><td>
Color:<input type="text" class="text" name="color3" size="10"> &nbsp;&nbsp;license Plate# (if available):<input type="text" 
class="text" name="license3" size="6"> &nbsp;&nbsp;Vin #<font color="red">*</font>:<input type="text" class="text" 
name="vin3" size="15">
</tr></td>
<tr><td>
Registered Owner<font color="red">*</font>:<input type="text" class="text" name="reg3" size="25"> 
</tr></td>
<tr><td>
<input type="button" name="add1" value="Add Another Vehicle" onClick="showHide('show4')">
</tr><td>
</table>
</div>
 
<!-- Vehicle #4 -->
<div id="show4" style="display:none;"> 
<br />
<table>
<tr><td>
<b>Vehicle #4</b><br />
Transportation via (select one)<font color="red">*</font>: &nbsp;&nbsp;<input type="radio" value="Open Carrier" 
name="via4">Open Carrier &nbsp;&nbsp;<input type="radio" value="Closed Carrier" name="via4">Closed Carrier &nbsp;&nbsp;<input 
type="radio" value="Professional Drive Away" name="via4">Professional Drive Away<br />
</tr><td>
<tr><td>
Is the vehicle in running condition? &nbsp;&nbsp;<input type="radio" value="Yes" name="running4">Yes &nbsp;&nbsp;<input 
type="radio" value="No" name="running4">No<br />
</tr></td>
<tr><td>
Year<font color="red">*</font>:<input type="text" class="text" name="year4" size="5">  &nbsp;&nbsp;Make<font 
color="red">*</font>:<input type="text" class="text" name="make4" size="10">  &nbsp;&nbsp;Model<font 
color="red">*</font>:<input type="text" class="text" name="model4" size="10"><br />
</tr><td>
<tr><td>
Color:<input type="text" class="text" name="color4" size="10"> &nbsp;&nbsp;license Plate# (if available):<input type="text" 
class="text" name="license4" size="6"> &nbsp;&nbsp;Vin #<font color="red">*</font>:<input type="text" class="text" 
name="vin4" size="15">
</tr></td>
<tr><td>
Registered Owner<font color="red">*</font>:<input type="text" class="text" name="reg4" size="25"> 
</tr></td>
<tr><td>
<input type="button" name="add1" value="Add Another Vehicle" onClick="showHide('show5')">
</tr><td>
</table>
</div>
 
<!-- Vehicle #5 -->
<div id="show5" style="display:none;"> 
<br />
<table>
<tr><td>
<b>Vehicle #5</b><br />
Transportation via (select one)<font color="red">*</font>: &nbsp;&nbsp;<input type="radio" value="Open Carrier" 
name="via5">Open Carrier &nbsp;&nbsp;<input type="radio" value="Closed Carrier" name="via5">Closed Carrier &nbsp;&nbsp;<input 
type="radio" value="Professional Drive Away" name="via5">Professional Drive Away<br />
</tr><td>
<tr><td>
Is the vehicle in running condition? &nbsp;&nbsp;<input type="radio" value="Yes" name="running5">Yes &nbsp;&nbsp;<input 
type="radio" value="No" name="running5">No<br />
</tr></td>
<tr><td>
Year<font color="red">*</font>:<input type="text" class="text" name="year5" size="5">  &nbsp;&nbsp;Make<font 
color="red">*</font>:<input type="text" class="text" name="make5" size="10">  &nbsp;&nbsp;Model<font 
color="red">*</font>:<input type="text" class="text" name="model5" size="10"><br />
</tr><td>
<tr><td>
Color:<input type="text" class="text" name="color5" size="10"> &nbsp;&nbsp;license Plate# (if available):<input type="text" 
class="text" name="license4" size="6"> &nbsp;&nbsp;Vin #<font color="red">*</font>:<input type="text" class="text" 
name="vin5" size="15">
</tr></td>
<tr><td>
Registered Owner<font color="red">*</font>:<input type="text" class="text" name="reg5" size="25"> 
</tr></td>
<tr><td>
<p>If there are more than 5 vehicles to be shipped, please include the additional vehicle information in the "Additional 
Comments/Information" section at the end of the form.</p>
</tr><td>
</table>
</div>
<br />
 
PHP Code:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<
title></title>
<
link rel="stylesheet" href="sitestyle.css" type="text/css" />
</
head>
<
body>
 
 
// variables
$EmailFrom "shipping_request@clrtransport.com";
$EmailTo "bpage@cgsart.com";
$Subject "Shipping Order Form";
$via1 Trim(stripslashes($_POST['via1'])); 
$running1 Trim(stripslashes($_POST['running1']));
$year1 Trim(stripslashes($_POST['year1']));
$make1 Trim(stripslashes($_POST['make1']));
$model1 Trim(stripslashes($_POST['model1']));
$color1 Trim(stripslashes($_POST['color1']));
$license1 Trim(stripslashes($_POST['license1']));
$vin1 Trim(stripslashes($_POST['vin1']));
$reg1 Trim(stripslashes($_POST['reg1'])); 
$via2 Trim(stripslashes($_POST['via2'])); 
$running2 Trim(stripslashes($_POST['running2']));
$year2 Trim(stripslashes($_POST['year2']));
$make2 Trim(stripslashes($_POST['make2']));
$model2 Trim(stripslashes($_POST['model2']));
$color2 Trim(stripslashes($_POST['color2']));
$license2 Trim(stripslashes($_POST['license2']));
$vin2 Trim(stripslashes($_POST['vin2']));
$reg2 Trim(stripslashes($_POST['reg2'])); 
$via3 Trim(stripslashes($_POST['via3'])); 
$running3 Trim(stripslashes($_POST['running3']));
$year3 Trim(stripslashes($_POST['year3']));
$make3 Trim(stripslashes($_POST['make3']));
$model3 Trim(stripslashes($_POST['model3']));
$color3 Trim(stripslashes($_POST['color3']));
$license3 Trim(stripslashes($_POST['license3']));
$vin3 Trim(stripslashes($_POST['vin3']));
$reg3 Trim(stripslashes($_POST['reg3']));
$via4 Trim(stripslashes($_POST['via4'])); 
$running4 Trim(stripslashes($_POST['running4']));
$year4 Trim(stripslashes($_POST['year4']));
$make4 Trim(stripslashes($_POST['make4']));
$model4 Trim(stripslashes($_POST['model4']));
$color4 Trim(stripslashes($_POST['color4']));
$license4 Trim(stripslashes($_POST['license4']));
$vin4 Trim(stripslashes($_POST['vin4']));
$reg4 Trim(stripslashes($_POST['reg4']));
$via5 Trim(stripslashes($_POST['via5'])); 
$running5 Trim(stripslashes($_POST['running5']));
$year5 Trim(stripslashes($_POST['year5']));
$make5 Trim(stripslashes($_POST['make5']));
$model5 Trim(stripslashes($_POST['model5']));
$color5 Trim(stripslashes($_POST['color5']));
$license5 Trim(stripslashes($_POST['license5']));
$vin5 Trim(stripslashes($_POST['vin5']));
$reg5 Trim(stripslashes($_POST['reg5'])); 
// validations
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

if (empty($via1 )) {
echo "<div class=body><br><br><p>A <i>Transportation Mode</i> for <b>Vehicle #1</b> is required.
<br> Please choose a <i>Transportation Mode</i>.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}
if (empty($year1 )) {
echo "<div class=body><br><br><p>The <i>Year</i> for <b>Vehicle #1</b> is required.
<br> Please tell us the <i>Year</i>.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}

if (empty($make1 )) {
echo "<div class=body><br><br><p>The vehicle <i>Make</i> is required <b>Vehicle #1</b>.
<br> Please tell us the <i>Make</i> of the vehicle.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}

if (empty($model1 )) {
echo "<div class=body><br><br><p>The vehicle <i>Model</i> is required <b>Vehicle #1</b>.
<br> Please tell us the <i>Model</i> of the vehicle.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}

if (empty($vin1 )) {
echo "<div class=body><br><br><p>The <i>VIN Number</i> is required <b>Vehicle #1</b>.
<br> Please give us the <i>VIN Number</i>.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}

if (empty($reg1 )) {
echo "<div class=body><br><br><p>The <i>Registered Owner</i> is required <b>Vehicle #1</b>.
<br> Please give us the <i>Registered Owner</i>.</p></div> \n";
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}

// email body

$Body .= "-- Vehicle Information and Availability --";
$Body .= "\n";
$Body .= "-- Vehicle #1 --";
$Body .= "\n \n";
$Body .= "Transportation via: ";
$Body .= $via1;
$Body .= "\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running1;
$Body .= "\n \n";

$Body .= "-- Vehicle #2 --";
$Body .= "\n \n";
$Body .= "Transportation via: ";
$Body .= $via2;
$Body .= "\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running2;
$Body .= "\n \n";
$Body .= "Year: ";
$Body .= $year2;
$Body .= "\n \n";
$Body .= "Make: ";
$Body .= $make2;
$Body .= "\n \n";
$Body .= "Model: ";
$Body .= $model2;
$Body .= "\n \n";
$Body .= "Color: ";
$Body .= $color2;
$Body .= "\n \n";
$Body .= "License Plate #: ";
$Body .= $license2;
$Body .= "\n \n";
$Body .= "Vin #: ";
$Body .= $vin2;
$Body .= "\n \n";
$Body .= "Registered Owner: ";
$Body .= $reg2;
$Body .= "\n \n \n";

$Body .= "-- Vehicle #3 --";
$Body .= "\n \n";
$Body .= "Transportation via: ";
$Body .= $via3;
$Body .= "\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running3;
$Body .= "\n \n";
$Body .= "Year: ";
$Body .= $year3;
$Body .= "\n \n";
$Body .= "Make: ";
$Body .= $make3;
$Body .= "\n \n";
$Body .= "Model: ";
$Body .= $model3;
$Body .= "\n \n";
$Body .= "Color: ";
$Body .= $color3;
$Body .= "\n \n";
$Body .= "License Plate #: ";
$Body .= $license3;
$Body .= "\n \n";
$Body .= "Vin #: ";
$Body .= $vin3;
$Body .= "\n \n";
$Body .= "Registered Owner: ";
$Body .= $reg3;
$Body .= "\n \n \n";

$Body .= "-- Vehicle #4 --";
$Body .= "\n \n";
$Body .= "Transportation via: ";
$Body .= $via4;
$Body .= "\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running4;
$Body .= "\n \n";
$Body .= "Year: ";
$Body .= $year4;
$Body .= "\n \n";
$Body .= "Make: ";
$Body .= $make4;
$Body .= "\n \n";
$Body .= "Model: ";
$Body .= $model4;
$Body .= "\n \n";
$Body .= "Color: ";
$Body .= $color4;
$Body .= "\n \n";
$Body .= "License Plate #: ";
$Body .= $license4;
$Body .= "\n \n";
$Body .= "Vin #: ";
$Body .= $vin4;
$Body .= "\n \n";
$Body .= "Registered Owner: ";
$Body .= $reg4;
$Body .= "\n \n \n";

$Body .= "-- Vehicle #5 --";
$Body .= "\n \n";
$Body .= "Transportation via: ";
$Body .= $via5;
$Body .= "\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running5;
$Body .= "\n \n";
$Body .= "Year: ";
$Body .= $year5;
$Body .= "\n \n";
$Body .= "Make: ";
$Body .= $make5;
$Body .= "\n \n";
$Body .= "Model: ";
$Body .= $model5;
$Body .= "\n \n";
$Body .= "Color: ";
$Body .= $color5;
$Body .= "\n \n";
$Body .= "License Plate #: ";
$Body .= $license5;
$Body .= "\n \n";
$Body .= "Vin #: ";
$Body .= $vin5;
$Body .= "\n \n";
$Body .= "Registered Owner: ";
$Body .= $reg5;
$Body .= "\n \n";
$Body .= "Year: ";
$Body .= $year1;
$Body .= "\n \n";
$Body .= "Make: ";
$Body .= $make1;
$Body .= "\n \n";
$Body .= "Model: ";
$Body .= $model1;
$Body .= "\n \n";
$Body .= "Color: ";
$Body .= $color1;
$Body .= "\n \n";
$Body .= "License Plate #: ";
$Body .= $license1;
$Body .= "\n \n";
$Body .= "Vin #: ";
$Body .= $vin1;
$Body .= "\n \n";
$Body .= "Registered Owner: ";
$Body .= $reg1;
$Body .= "\n \n \n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
?>
<div class=body>
<p>
Thank you for your interest in our shipping services. <br />
We will review the information contained in this<br />
email and respond to you as soon as possible. <br />
The information you sent is detailed below. <br />
You may want to <a href="javascript:window.print()">Print this page</A> for your records.</p>
<br />

<p>
Date: <?php echo $todayis ?>
<br /><br /><br />
<b>Vehicle Information and Availability</b>
<br /><br />

<b>Vehicle #1</b>
<br />
Transportation via: <?php echo $via1 ?><br />
Is the vehicle in running condition? <?php echo $running1 ?><br />
Year: <?php echo $year1 ?><br />
Make: <?php echo $make1 ?><br />
Model: <?php echo $model1 ?><br />
Color: <?php echo $color1 ?><br />
License Plate: <?php echo $license1 ?><br />
Vin Number: <?php echo $vin1 ?><br />
Registered Owner: <?php echo $reg1 ?><br />
<br /><br />

<b>Vehicle #2</b>
<br />
Transportation via: <?php echo $via2 ?><br />
Is the vehicle in running condition? <?php echo $running2 ?><br />
Year: <?php echo $year2 ?><br />
Make: <?php echo $make2 ?><br />
Model: <?php echo $model2 ?><br />
Color: <?php echo $color2 ?><br />
License Plate: <?php echo $license2 ?><br />
Vin Number: <?php echo $vin2 ?><br />
Registered Owner: <?php echo $reg2 ?><br />
<br /><br />

<b>Vehicle #3</b>
<br />
Transportation via: <?php echo $via3 ?><br />
Is the vehicle in running condition? <?php echo $running3 ?><br />
Year: <?php echo $year3 ?><br />
Make: <?php echo $make3 ?><br />
Model: <?php echo $model3 ?><br />
Color: <?php echo $color3 ?><br />
License Plate: <?php echo $license3 ?><br />
Vin Number: <?php echo $vin3 ?><br />
Registered Owner: <?php echo $reg3 ?><br />
<br /><br />

<b>Vehicle #4</b>
<br />
Transportation via: <?php echo $via4 ?><br />
Is the vehicle in running condition? <?php echo $running4 ?><br />
Year: <?php echo $year4 ?><br />
Make: <?php echo $make4 ?><br />
Model: <?php echo $model4 ?><br />
Color: <?php echo $color4 ?><br />
License Plate: <?php echo $license4 ?><br />
Vin Number: <?php echo $vin4 ?><br />
Registered Owner: <?php echo $reg4 ?><br />
<br /><br />
<b>Vehicle #5</b>
<br />
Transportation via: <?php echo $via5 ?><br />
Is the vehicle in running condition? <?php echo $running5 ?><br />
Year: <?php echo $year5 ?><br />
Make: <?php echo $make5 ?><br />
Model: <?php echo $model5 ?><br />
Color: <?php echo $color5 ?><br />
License Plate: <?php echo $license5 ?><br />
Vin Number: <?php echo $vin5 ?><br />
Registered Owner: <?php echo $reg5 ?><br />
<br /><br />

</p>
</div>
</body>
</html>
[/php]

Last edited by cruizer; 05-31-2008 at 01:04 AM..
cruizer is offline
Reply With Quote
View Public Profile
 
Old 05-31-2008, 02:12 AM Re: Please help with if/then statement
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
I guess you have done BASIC, if you are calling it an if/THEN statement. There is no 'then' command in PHP, it uses C style with {} to encase the statement.

PHP Code:
if (condition) {
statement//comment

Maybe that is not very helpful, but it's a start
http://us3.php.net/manual/en/control-structures.if.php states otherwise, you don't need brackets for single items/lines, and if I remember right that's how C is too. Haven't used C in a while though. That PHP is based off of C has a lot to do with it I'm sure. Anyway conditional statements or control flow structures are often referred to by their nickname of if-then-else or just if-then statements, it describes how they work, BASIC was created to be very simple and went a tad further. In php this works in the order of:
if() // The if
{} // The then
else() //The else
Those who have used any professional references (sites, books etc) would be familiar with the term, those who taught themselves from help forums such as this may never have encountered the term. http://java.sun.com/docs/books/tutor...dbolts/if.html java has no 'then' but the official tutorial written by the creators calls the conditional statements by the name if-then.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-02-2008, 10:15 AM Re: Please help with if/then statement
Experienced Talker

Posts: 46
Name: Brent
Trades: 0
Anyone understand my code enough to help?

I don't know why it posted half in/ half out of the php box though.
cruizer is offline
Reply With Quote
View Public Profile
 
Old 06-02-2008, 01:39 PM Re: Please help with if/then statement
pjaj's Avatar
Average Talker

Posts: 17
Name: Peter Jennings
Location: Oxfordshire UK
Trades: 0
Let me begin by apologising, firstly I'm not a PHP programmer, but I did write C for many years and the syntax is very similar. Secondly, I'm going to lapse into pseudocode after a bit.

Instead of processing 5 different sets of data, why not put them into a set of 10 arrays:-

$via[1] = Trim(stripslashes($_POST['via1']));
$running[1] = Trim(stripslashes($_POST['running1']));
$year[1] = Trim(stripslashes($_POST['year1']));
$make[1] = Trim(stripslashes($_POST['make1']));
$model[1] = Trim(stripslashes($_POST['model1']));
$color[1] = Trim(stripslashes($_POST['color1']));
$license[1] = Trim(stripslashes($_POST['license1']));
$vin[1] = Trim(stripslashes($_POST['vin1']));
$reg[1] = Trim(stripslashes($_POST['reg1']));
$via[2] = Trim(stripslashes($_POST['via2']));
$running[2] = Trim(stripslashes($_POST['running2']));
$year[2] = Trim(stripslashes($_POST['year2']));

and so on.

Then you can use a loop construct "for" to process each potential vehicle
This way you only have to write the code once, not 5 times and it's far easier to maintain.

/* pseudocode */
create start of email;
for ($i=1; $i<=5; $i++)
{
/* do we have a valid "ith" vehicle */
if ($via[$i] through reg[$i] are all empty)
{
do nothing;
/* no data for ith vehicle */
}
else
{
validate 6 mandatory values;
if (validate OK)
{
/* build section of email */
$Body .= "-- Vehicle ".$i." --\n\n";
$Body .= "Transportation via: ".$via[$i]."\n \n";
$Body .= "Is the vehicle in running condition? ";
$Body .= $running[$i]."\n\n";
etc. etc.
}
else
{
/* this only has to be done once if you put it here */
die ("<input type='button' value='Back' onClick='history.go(-1)'>");
}
}
}
append rest of email;
send email;

The HTML echo of the data for the optional printed page can be generated in a similar manner.
pjaj is offline
Reply With Quote
View Public Profile
 
Old 06-02-2008, 11:20 PM Re: Please help with if/then statement
Experienced Talker

Posts: 46
Name: Brent
Trades: 0
I'm not sure what pseudocode is, but I will look into this and see if I can understand it.
Thanks.
cruizer is offline
Reply With Quote
View Public Profile
 
Old 06-03-2008, 05:20 AM Re: Please help with if/then statement
pjaj's Avatar
Average Talker

Posts: 17
Name: Peter Jennings
Location: Oxfordshire UK
Trades: 0
Quote:
Originally Posted by cruizer View Post
I'm not sure what pseudocode is, but I will look into this and see if I can understand it.
Thanks.
From Wikipedia:

Quote:
Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but typically omits details that are not essential for the understanding of the algorithm, such as subroutines, variable declarations and system-specific code. The programming language is augmented with natural language descriptions of the details, where convenient, or with compact mathematical notation. The purpose of using pseudocode is that it may be easier for humans to read than conventional programming languages, and that it may be a compact and environment-independent description of the key principles of an algorithm. No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program.
So for example
"if($via[$i] through reg[$i] are all empty)"
stands for something like
if(empty($via[$i]) && empty($running[$i]) && empty($year[$i]) && empty($make[$i]) && empty($model[$i]) && empty($color[$i]) && empty($license[$i]) && empty($vin[$i]) && empty($reg[$i]))

Note the use of && rather than "and" - see your PHP manual for "
Operator Precedence"
BTW, in my previous post, when I said 10 arrays, I miscounted, should have been 9.

Not got a PHP manual? Have a look at http://www.w3schools.com/PHP/php_if_else.asp for more if / else / elseif help

Last edited by pjaj; 06-03-2008 at 05:29 AM..
pjaj is offline
Reply With Quote
View Public Profile
 
Old 06-03-2008, 07:16 PM Re: Please help with if/then statement
Experienced Talker

Posts: 46
Name: Brent
Trades: 0
Excellent! Thank you!
I haven't had a chance to look at it yet, but I will tomorrow.
cruizer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Please help with if/then statement
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45519 seconds with 12 queries