PHP Variable Help

Ok so i have this PHP code imbedded into an html site that i am working on, I have little knowledge of php so bare with me.
This code displays the calendar which they can choose dates from (like the travel websites). What I need is how to grab the variables FROM PHP and put them into HTML so i can use an .ASP page to send and email to myself once they hit submit.

See attached for how the website looks.
yes, i know i can do this in html fairly easy but this is an opportunity to learn php and how it can integrate into html.

[code]
Dates of Travel:

<?php
$date3_default = “2013-08-12”;
$date4_default = “2013-08-18”;
$myCalendar = new tc_calendar(“date3”, true, false);
$myCalendar->setIcon(“calendar/images/iconCalendar.gif”);
$myCalendar->setDate(date(‘d’, strtotime($date3_default))
, date(‘m’, strtotime($date3_default))
, date(‘Y’, strtotime($date3_default)));
$myCalendar->setPath(“calendar/”);
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->setAlignment(‘left’, ‘bottom’);
$myCalendar->setDatePair(‘date3’, ‘date4’, $date4_default);
$myCalendar->writeScript();
?>


to


<?php
$myCalendar = new tc_calendar(“date4”, true, false);
$myCalendar->setIcon(“calendar/images/iconCalendar.gif”);
$myCalendar->setDate(date(‘d’, strtotime($date4_default))
, date(‘m’, strtotime($date4_default))
, date(‘Y’, strtotime($date4_default)));
$myCalendar->setPath(“calendar/”);
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->setAlignment(‘left’, ‘bottom’);
$myCalendar->setDatePair(‘date3’, ‘date4’, $date3_default);
$myCalendar->writeScript();
?>


[/code] The code below is the "submit" and "check this value" buttons. They both work and when you hit "check this value" it actually pops up with "Dates select from to ".

ie. Dates select from 2013-08-12 to 2013-08-18

But that is a java.alert and not html or php. I cant use the value “button2” for the .ASP because nothing will show up as its being executed withing the html code and doesn’t assign any values to “button2”

	<p>
		<input type="submit" name="Submit" value="Submit" />
		<input type="button" name="button2" id="button2" value="Check the value" onClick="javascript:alert('Date select from '+this.form.date3.value+' to '+this.form.date4.value);">

This is my attempt at converting the variables to html so i can use them in the .asp file that sends the email to me. But all i get is “0” so its grabbing the dates but doing some mathematics or just printing “0” for “null”

<input type="hidden" name="dates_of_travel" value="<?php echo $date3 ' ' $date4;?>">


PHPHelp.JPG

No where in your code I don’t see a $date3 and $date4 variable.

[php][/php]

Now I do see the form element where you reference it.

[php]this.form.date3.value[/php]

But that’s not a php variable the’s most likely the name of your input box on the html page.

If you want to get the value into a php variable you will do this…

[php]$date3 = $_POST[“date3”]; [/php]

Now you’re taking the html element that was submitted and grabbing putting it into a variable in PHP

The $date3 and $date4 are in the first block of code. $date3 is the first portion of php before the

tags and $date4 is the second block after the
tags.

So with [php] ]$date3 = $_POST[‘date3’][/php] you are posting the user input to a php variable and then with the html it would work because there is actually data that is being populated to those variables?

That’s what I think, did you try it yet?

No but i will right now :slight_smile:

I thought
[php]$myCalendar = new tc_calendar(“date4”, true, false);[/php]
was the line that states use $date4 for user input?

But the $_POST method returns nothing when its emailed

From: [email protected] [mailto:[email protected]]
Sent: Wednesday, August 21, 2013 2:44 PM
To: Ben
Subject: Ben

Request:
Requested by: Ben
Email of Submitter: [email protected]
Traveling to: Houston, TX
Dates of Travel:

the “Dates of Travel” should show the dates that they selected.
Originally it was “0”

[php]$myCalendar = new tc_calendar(“date4”, true, false);[/php]

was the line that states use $date4 for user input?

Their is a big difference between “$date4” and “date4”, I think date4 is the name of the user input.

In order to transfer the name of the user input into a variable you need to grab it

[php]$UserInputforDate4 = $_POST[“date4”];[/php]

$Whatever = a php variable

I also don’t see all your code, you can attach the .php files.

Ok so I have attached my index.php file with the .asp file that sends the email.
I have taken out the names and IPs because this is the internet lol so if you want to play with it all together you have to modify it a bit (ip address of smtp server and “Mail.to =” address)

Website.txt = index.php
process_ACADLicense.txt = process_ACADLicense.asp

I will have to play with php more it understand the variables and how to display them in an html format.


Website.txt (4.03 KB)

process_ACADLicense.txt (2.63 KB)

[php][/php]

I did a search on the two files you uploaded on $date3, it only showed the line above. So it doesn’t contain a value, you need to set $date3 to a value before you can echo it.

If you were to type right above the line…

[php]<?php $date3 = “8-31-2013”;
$date4 = “8-31-2013”;?>
[/php]

Then you will see some results, because you assigned a date to those variables.

I have a feeling all you need to do is this.

[php]<?php $date3 = $_POST[“date3”];
$date4 = $_POST[“date4”]; ?>
[/php]

But all the mystery is in the tc_calendar.php file, in which I have no clue what that contains.

Sponsor our Newsletter | Privacy Policy | Terms of Service