This php file appears correct, but is returning an 'unexpected end of file' error. Is the error somewhere in the html file. I have tried putting the tags inside print in "", removed one extra white space on the php line, added white spaces between the brackets[] and quotes'' on the variable lines, and still have the same error when I press enter to send the data to the php script. Here is the html code: http://pastebin.com/Rb62pZcy
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Your Feedback</title>
</head>
<body>
<?php // Script 3.3 handle_form.php
// This page receives the data from feedback.html
// It will receive: title, name, email, comments in $_POST
$title = $_POST [ 'title' ] ;
$name = $_POST [ 'name' ] ;
$email = $_POST [ 'email' ] ;
$comments = $_POST [ 'comments' ] ;
print "<p>Thank you, $title $name, for your comments.</p>"
"<p>You stated that you found this example to be '$response' and added:<br />$comments</p>"
?>
</body>
Instead of this:
print "<p>Thank you, $title $name, for your comments.</p>"
"<p>You stated that you found this example to be '$response' and added:<br />$comments</p>"
Use this:
echo "<p>Thank you, $title $name, for your comments.</p>";
echo "<p>You stated that you found this example to be '$response' and added:<br />$comments</p>";
I think you miss the ";" character.
------------------UPDATE-----------------------------
I try this code and works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Your Feedback</title>
</head>
<body>
<?php
if (isset($_POST['email'])){
$title = $_POST['title'];
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
}
else
{
$title = "No title arrived";
$name = "No name arrived";
$comments = "No comments arrived";
}
//$response is not defined??
$response = "Live long and prosper";
//so i defined
echo "<p>Thank you, $title $name, for your comments.</p>";
echo "<p>You stated that you found this example to be '$response' and added:<br />$comments</p>";
?>
</body>
</html>
PS: try executing this script alone...name it "handle_form.php" and put this in the nav address bar:
localhost/your_project/handle_form.php
Works on my localhost.....if your problem continue then may be the problem is in the submit page.
Saludos.
Related
I am trying to use Facebook login on my website with inserting Facebook user data on my database.
I have those files as shown below :
index.php:
session_start();
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/preload.css?ve=5"/>
<title>Myexpect</title>
</head>
<body>
<?php
if ($_SESSION['FBID']):
require_once('connections/connect.php');
?> <!-- After user login -->
<div id="warper">
<div class="logo">
<img width="150px" height="150px"src="images/Logo - Copy.png">
</div>
<div class="welcome">
<h2>Welcome to our website</h2>
</div>
<div class="preload">
<img width="50" height="50px"src="loading.gif">
</div>
</div>
<?php
echo '<meta http-equiv = "refresh" content = "3; url = games.php" />'
?>
<?php else: ?> <!-- Before login -->
<div class="container">
<div><img src="images/fb-login-btn.png" ></div>
</div>
<?php endif ?>
</body>
</html>
fbconfig.php :
<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
require 'dbconfig.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( 'xxxxxxxxxxxx','xxxxxxxxxxxxxx' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('https://xxxxx/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
$check = mysqli_query($connection,"select * from Users where Fuid='$fbid'");
$check = mysqli_num_rows($check);
if (empty($check)) { // if new user . Insert a new record
$query = "INSERT INTO Users (Fuid,Ffname,Femail) VALUES ('$fbid','$fbfullname','$femail')";
mysqli_query($connection,$query);
} else { // If Returned user . update the user record
$query = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid='$fuid'";
mysqli_query($connection,$query);
/* ---- header location after session ----*/
header("Location: index.php");
} } else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>
The problem i have is when user try to login successfully it is not redirect to index.php file but fbconfig.php with a code :
https://xxxx/fbconfig.php?code=AQAAuanQBQ9lmXsAgbCuRB3aYy3YEEhrd81VBMMjih5oHo4dK_C7zMkQPZnuX5EdVvRJ2v4ybyAQ3EZ7qTzIrK9Oo-uY0KWiA6ZjNVh_4I6J7_AZDsJ12f7LGfc8EAGwgAfWwAm2Scwkx0UON9Vpjj75SBg7TX7n....etc
when i click back it work correctly and index.php work
how can i solve this
Sorry it was variables name mistake
this code is wrong :
$query = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid='$fuid'";
i changed it to :
$query = "UPDATE Users SET Ffname='$fbfullname', Femail='$femail' where Fuid='$fbid'";
and it is work now
I have an application where I want to inject a smartBanner meta tag, but only on certain pages.
On my index page I have:
<!DOCTYPE html>
<html ng-app="ngBoilerplate" ng-controller="AppCtrl">
<head>
<title ng-bind="pageTitle"></title>
<!-- add smart banner to select pages through smartBanner directive -->
<smart-banner></smart-banner>
</head>
<body>
<ui-view></ui-view>
</body>
</html>
I have a directive:
angular.module('boh.components.smartBanner', [])
.directive('smartBanner', function(){
return {
restrict: "E",
template: '<meta name="apple-itunes-app" content="app-id=1080200000"></meta>',
replace: true
} ;
});
My question is, do I simply call the directive by injecting the directive into my other page controllers?
I discovered the best way to deal with this was to work through the PHP wrapper for the app.
I ended up with something like this:
<?php
$urls = array("/app/explore", "/app/dashboard", "app/members", "/app/account-settings", "/app/jobs");
foreach ($urls as $key => $value) {
if( $_SERVER['REQUEST_URI'] === $value ) { ?>
<meta name="apple-itunes-app" content="app-id=########">
<?php }
}
?>
I'm a bit confused how this work and how to use it. I have a page which is loaded after button is clicked. When the user is deleted I want to back to users.php page. What I tried so far and didn't work is:
<META HTTP-EQUIV="Refresh" Content="2; URL=admin/users.php">
also this:
<META HTTP-EQUIV="Refresh" Content="2; URL=users.php">
I get 404.php error. Files are in same directory. I also have in head this
<base href="http://example.com/app/admins/">
The path to users.php is example.com/app/admins/admin/users.php
Edit: flash session message
userdelete.php
if (isset($_POST)) {
$_SESSION['postIsSet'] = 'Deleted!!';
} else {
$_SESSION['postIsSet'] = false;
}
header('Location: users.php');
In users.php
if (isset($_SESSION['postIsSet'])) {
if ($_SESSION['postIsSet'] == true) {
echo $_SESSION['postIsSet'];
unset($_SESSION['postIsSet']);
} else {
echo "Post is not set - Flash Message";
}
}
else {}
In PHP you can use header() to redirect to other page.
header('Location: http://example.com');
But you can't output anything before headers. Since you want to output some message too, you can use this code:
header("refresh: 2; http://www.example.com/");
echo <<< MESSAGE
<html>
<head></head>
<body>
Some message to show
</body>
</html>
MESSAGE;
It will redirect user after 2 seconds also showing some code. If you need more complex code, you can use ob_* functions to gather any output and later output it.
Flash Message Example
[doStuff.php]
session_start();
if (isset($_POST)) {
$_SESSION['postIsSet'] = true; // or some string
} else {
$_SESSION['postIsSet'] = false;
}
header('Location: http://example.com/user.php');
[user.php]
session_start();
if (isset($_SESSION['postIsSet'])) {
if ($_SESSION['postIsSet'] == true) {
// If you set message in session, you can do `echo $_SESSION['postIsSet'];`
echo "Post is set - Flash Message";
} else {
echo "Post is not set - Flash Message";
}
unset($_SESSION['postIsSet']);
} else {
// Flash message is not set yet.
}
Works fine for me:
<!DOCTYPE html>
<html>
<head>
<base href="http://example.com/app/admins/">
<meta charset="utf-8">
<META HTTP-EQUIV="Refresh" Content="2; URL=admin/users.php">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
Try this it will work :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Refresh" Content="2; URL=http://example.com/app/admins/admin/users.php">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
After I read your comments also if you still whant to use header location instead of refresh here is what you can do. This work fine to me:
In your userDelete.php
header('Location: users.php?msg=deleted');
In your users.php
if(isset($_GET['msg'])){
echo $_GET['msg'];
}
It's work just fine
I have to display a file in HTML table format.
I tried this but I cannot get any output.
use CGI qw(:standard);
my $line;
print '<HTML>';
print "<head>";
print "</head>";
print "<body>";
print "<p>hello perl am html</p>";
print "</body>";
print "</html>";
A CGI program must output the HTTP headers before it outputs any content. At a minimum, it must supply an HTTP Content-Type header.
Add:
my $q = CGI->new;
print $q->header('text/html; charset=utf-8');
… before you output any HTML.
(You should also write valid HTML, so include a Doctype and <title>).
You should use the CGI module once you have loaded it. It makes it much simpler to follow the correct rules for an HTTP page.
As has been observed, you need to print an HTTP header before the HTML body, and you can do that with print $cgi->header which defaults to specifying a content type of text/html and a character set of ISO-8859-1, which is adequate for many simple HTML pages. It also generates a <meta> element within the HTML that contains the same information.
This short program shows the idea. I have added a trivial table that shows how you could include that in the page. As you can see, the CGI code is much simpler than the corresponding HTML.
use strict;
use warnings;
use CGI qw/ :standard /;
print header;
print
start_html('My Title'),
p('Hello Perl am HTML'),
table(
Tr([
td([1, 2, 3]),
td([4, 5, 6]),
])
),
end_html
;
output
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>My Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>Hello Perl am HTML</p><table><tr><td>1</td> <td>2</td> <td>3</td></tr> <tr><td>4</td> <td>5</td> <td>6</td></tr></table>
</body>
</html>
How about this:
use CGI;
use strict;
my $q = CGI->new;
print $q->header.$q->start_html(-title=>'MyTitle');
my $tableSettings = {-border=>1, -cellpadding=>0, -cellspacing=>0};
print $q->table($tableSettings, $q->Tr($q->td(['column1', 'column2', 'column3'])));
print $q->end_html;
Output:
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>MyTitle</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table border="1" cellspacing="0" cellpadding="0"><tr><td>column1</td> <td>column2</td> <td>column3</td></tr></table>
</body>
</html>
i have just installes wamp server 2.4 and almost everything is working good but every time i am trying to open a file with mysql code on it he just showing me a white page whith nothing on it.
this is one of my files i have tried to open 'phpmyadmin' and this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head>
<body> <?php
$connect = mysql_connect("localhost", "guycohen801", "") or die ("cant connect to the server");
$db = mysql_select_db("test", $connect) or die ("cant select database");
$query = "SELECT * FROM asd3"; $result = mysql_query($query, $connect) or die ("query failed:" . mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row['1']," "; echo $row['2']," <br>";
}
mysql_close($connect); ?>
</body> </html>
and on the local host he shows me a whilte page and when i cliced on 'view page sorce' that what was writen:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
how can i fix this problem?????????????