PHP - Defaulting form field value to the current date - php

I'm trying to default a value in a field to the current date, but my code:
<?php
echo '<input type="text" name="makeupassignment" size="50" value="'.date("m/d/y").'">';
?>
is only printing this:
';
?>

Looks to me that the web page is not running through the PHP interpreter. Check out the source for the web page. Do you see the PHP source code when you click "show source" in your browser?
I think what happens is that your browser parses this as follows:
open tag whose type is ?php
two fields named "echo" and "'<input"
then fields with values: type="text", name="makeupassignment", size="50", and value="'.date(", and then m/d/y").'"
then there is the closing tag >
and then the rest is output verbatim

I would guess that PHP is not enabled/installed on the webserver you're testing with. View source on that page and you'll see all your code, I bet

Basically, PHP is not parsing the page for it's code.
Is the script you are running a .html or a .php script? Make sure it's the correct suffix. I find that Firefox won't open a page that is .php (unless i'm accessing it via localhost).
Is PHP running? Check by running php -v in a console/terminal window.
Is Apache (/IIS/lighttpd etc.) running?

Related

what is basically happening in a php page

Let us consider the following html :
<!doctype html>
<html>
<body>
<form method="POST" action="submit.php">
<input name="name" placeholder="Enter your name">
<button type="submit">Submit</button>
</form>
</body>
Now to my understanding this code passes a list of arguments to a the php file which is mentioned in the action attribute of the method .
I understand that the code file is in the server system .
Now let us consider the code for submit.php as follow :
<?php
$name = $_REQUEST['name'];
?>
<!doctype html>
<html>
<body>
Hello <?php echo $name;?>
</body>
</html>
These codes are taken from an answer to my last question .
Now after the submit button is clicked . The client requests for a new page from the server .
I wanted to know what exactly is happening here . Does the server sends this code file to the browser and the php code is executed in the browser or submit.php , generates an html file according to the php code in it and that html file is sent to the client ?
Where is the code getting executed in the browser or in the server . With what I have read till now gives a feel that the code is being executed in the server but to be just sure .
Further , if the case is like the latter , i.e., the inputs are sent to server and the server based on the php code generates an html file that is sent back to the browser , then isn't it a bit inefficient in sending requests the server even for smaller changes ?
So what exactly is happening and where is the code getting executed ?
The PHP source is on the server and remains there. It is executed there, and the result (which is typically HTML, but can be anything else too), is sent as a response to the browser, so you got that right.
The advantage is that the PHP code itself is hidden to to user, and it can do advanced stuff like accessing files and databases which are hidden, and usually unaccessible directly for your website visitor.
The PHP code may be accidentally exposed when PHP is not set up properly. In that case, the code won't run but may be returned as plain text by accident. If you ever see PHP code in your browser, it's almost certainly due to an incorrect server set-up.
Even a small change should usually be done by the server. Theoretically it's inefficient to do those requests all the time, but in reality a request is not a big deal. If you only want to update the page itself, without doing anything special to the server, you could use JavaScript which can run in the browser as part of your page, and which can manipulate the loaded HTML document.
The whole process or execution life cycle can be explained in the following two steps:
Step-1:
Server-side PHP blocks enclosed in <?php ?> tags are executed and removed from the code base on the server on every request.
Step-2:
Client-side script and HTML tags left in step-1 are send for execution and display in the browser.
I hope the explanation is easily understandable now.

Run Qt generated executable (EXE) through php (LINUX)

Sorry, this question must be repeated, it already asked the following link, but the answer is not cleared.. So can anyone please solve this problem???
exe not giving output in php
I am trying to call a Qt generated executable file through PHP code which fails to run the exe.. The same exe runs on double-click and through command line..
Below is my code
<?php
$exec_cmd = exec('"./myEXE"');
?>
<html>
<body>
<form>
<input type="submit" value="RUN" onclick="$exec_cmd"/>
</form>
</body>
<html>
Thank You...
PHP is a server side language. It means that the php code is compiled and executed in the server and the output is sent to the client.
What you are trying to do is to use PHP as client-side language, like JavaScript.
The porgram is executed when the page is displayed and you want it to be displayed once the user clicks on the button, for that you must use JavaScript.
I would use AJAX to make the request to the server so it can execute the program but if you don't want to use javascript you can set the form to redirect the page with a GET or POST parameter and check in PHP if that parameter is set

Capture php variable from (Index1.php) To (Index2.html)

I try to capture the value of $app_id with the $_POST method to Index2.html with the code below and I can't.
The php code in html page don't change the color and that is the signal that the server doesn't work! I'm using Dreamweaver cs6 as editor
Index1.php:
$app_id = $_POST["appID"]
Index2.html:
<label for="appID"><?php $_POST['appID'] ?></label>
Is your server configured to run HTML files as PHP files? You're trying to run a PHP code inside a HTML file! You should rename index2.html to index2.php and run it inside an Apache server, or configure your Apache to run HTML as PHP. Also, index2 must be the action of index1 form.
UPDATE
How to parse HTML as PHP?

Automatically Print webpage with PHP

I have a php script that takes an invoice number and generates a PDF invoice with all relevant information, when the script has finished the PDF is then displayed on the screen in the users browser. I am curious to know how I can then automatically print the PDF? I realize that there probably isn't a way with php or javascript because of security/spam issues.
Unfortunately manually printing the page is not really an option because the users currently have two printers, in the current Access based system one invoice is sent to the colour and two invoices are sent to the black and white printer. This is all done automatically, but now due to certain circumstances I would like to use PHP as a large part of the system is PHP based already.
I have thought about using a Linux based machine and trying to use a python webserver to get the PDF and print it, but I have no idea what this would require or how to do it. Any feedback would be great!
IMO your best option, given what you've said, is going to be to use Linux to print it.
wget http://1.2.3.4/invoice.pdf
pdf2ps invoice.pdf invoice.ps
lpr -Pcolor invoice.ps
lpr -Pbw -#2 invoice.ps
Something like that, perhaps, should work.
Try this
php pdf library available
http://php.net/manual/en/pdf.examples-basic.php
http://sanjoyinfoworld.blogspot.in/2012/03/how-to-generate-pdf-in-php.html
refere this sites
Try to this code on java script
Click to Print This Page
You can set it to print off of an image:
<A HREF="javascript:window.print()">
<IMG SRC="print_image.gif" BORDER="0"</A>
And yes, you can set it to trigger off a button:
<FORM>
<INPUT TYPE="button" onClick="window.print()">
</FORM>
you can't getting any idea view this sites
http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Print-a-Web-Page- Using-JavaScript.htm
you can do with vbscript try this
<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>
<form>
Printing webpage without prompt window. As of now it's possible with VBScript(IE).
<br/>
<button onclick="Print()">Print Now</button>
<br/>
</form>
<script language="VBScript">
Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
If DA Then
call WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
Else
call WebBrowser1.IOleCommandTarget.Exec _
(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","","")
End If
End Sub
</script>

Why would a.php file open as if it were an html file, rather than execute?

I have a .php file that I'm trying to execute. It's referred to in the 'action' part of an html form.
For some reason when the form submits it opens the .php file in the browser as if it were an html page (a blank one).
The .php file doesn't have anything out of the ordinary in it, but I'm not sure it's getting to the point of executing it anyway.
My opening form tag looks like this: <form action="my_script.php" method="post">
What am I missing?...
In all likelihood your script is executing. By default, HTTP headers will be sent indicating that the script's content is HTML, hence that's how your browser will treat it. But if you don't actually send any output, it'll appear as a blank page.
If you want the form to do something but not open a new page, maybe you could use AJAX to submit the form data without leaving the page. Alternatively, you could just add at the end of the script
echo 'Finished :)';
so that you know it has gotten to the end, and presumably done something.
When you submit a form, your browser posts data to the URL specified by the action attribute, as part of the request for that page.
Your page at my_script.php should output some HTML.
If instead you see your PHP code when you view the source of this new page, then PHP is not configured to be parsed on the server.
euh... php
Use: http://www.apachefriends.org/en/index.html instead of opening a html file directly in your browser.

Categories