0% found this document useful (0 votes)
81 views

Share Improve This Question: Can I Link This PHP File To The Other One?" ?

The document describes a login form created with HTML and CSS that displays username and password fields. The user has also created a separate PHP file to handle form submission. When the form is submitted, it is not properly connecting to the PHP file and is displaying errors. The user is looking for help connecting the two files and handling form submission and validation.

Uploaded by

blessing
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Share Improve This Question: Can I Link This PHP File To The Other One?" ?

The document describes a login form created with HTML and CSS that displays username and password fields. The user has also created a separate PHP file to handle form submission. When the form is submitted, it is not properly connecting to the PHP file and is displaying errors. The user is looking for help connecting the two files and handling form submission and validation.

Uploaded by

blessing
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

OK, so I have a entry form login page saved as a .

php file, its content is displayed in html and


css. It displays a few things and then a log in form with 2 fields: Username, Password and then a
'Log in' button.

I have created a separate .php file which looks like this:

<?php

$username = $_POST ['Username'];


$password = $_POST['Password'];

if ($username && $password)


{

$connect = mysql_connect("localhost", "root", "root") or die ("couldn't connect");

mysql_select_db("sportsday") or die ("couldn't find db");

else
die("Please enter a username and password");

?>
I believe this code is now connected to my other page (http://jsfiddle.net/6yw8a2ue/) It shows
some errors next to the fields in browser: "Notice: Undefined indiex: Username in
G:\xampp\htdocs\Sportsday\entryformlongon.php"...

and once i enter a username and password it goes through to blank page with the error:
"Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the
future: use mysqli or PDO instead in G:\xampp\htdocs\Sportsday\login.php on line 11"
phphtmlcssxampp

share  improve this question  follow 


edited Oct 23 '14 at 18:02
asked Oct 23 '14 at 17:37

Charley Baker
4711 gold badge11 silver badge55 bronze badges
 2
This if ($username&&£$password) - remove the £ - if ($username &&
$password) that's where the parse error originates from. Now, what do you mean by "How
can I link this php file to the other one?" ? – Funk Forty Niner Oct 23 '14 at 17:39 
 well i was following a log in tutorial (youtube.com/watch?v=y7ae_cZahPs) and they used two
separate php files and it connected fine. but for me its not – Charley Baker Oct 23 '14 at 17:45
 @Fred-ii- i need the code show in the screenshot to be used for my log in page
basically – Charley Baker Oct 23 '14 at 17:45
 So, why not show us what you're using then, or is that your entire code? – Funk Forty Niner Oct
23 '14 at 17:45
 1
You have completely changed the original question so that nearly all the answers you have
received are no longer relevant (as @Fred-ii- pointed out). If you have a different question
you need to ask a new question rather than updating this one to the point of being
unrecognizable from what was originally asked which was how to include the files
correctly. – Ian Oct 24 '14 at 5:16 
show 9 more comments
7 Answers

Active OldestVotes

1
Please look over this documentation. http://php.net/manual/en/function.require-once.php

You can require the file in any page needed.


share  improve this answer  follow 
answered Oct 23 '14 at 17:44

iamcutler
3111 silver badge11 bronze badge
add a comment
0
point your form action atribute to the php file.

<form method="post" action="phpsubmit.php">


form stuff
</form>
share  improve this answer  follow 
answered Oct 23 '14 at 17:46

danielson317
2,58422 gold badges1818 silver badges3434 bronze badges
add a comment
0
Require at the top of the page to be included. require 'filename';

http://www.w3schools.com/php/php_includes.asp
share  improve this answer  follow 
answered Oct 23 '14 at 17:46

Mark Hulbrock
10155 bronze badges
add a comment
0
header('Location: http://www.example.com/');
exit;
I assume by link to other php file, you mean forward to another page once complete.
share  improve this answer  follow 
answered Oct 23 '14 at 17:47

Adrian Stride
5966 bronze badges
add a comment
0
There are 4 options to include the file into the main document.

include
include_once
require
require_once
include doc, include_once doc, require doc, require_once doc

Each of these will add the code to your main file and do essentially the same
thing. include and require will include the file as many times as the line of code is called
(which can cause issues if you just need it called once). include_once and require_once will
import the file to the document only one time regardless of whether or not that line of code is
called multiple times.

A big difference between include and require lies in the type of error you will get. include will


return a warning error if the file isn't found but your code will continue to execute (with
errors). require will produce a fatal error which will kill the program then and there.

So if you have form.php and want to include it it would look something like this for each option.

include 'form.php';
include_once 'form.php';
require 'form.php';
require_once 'form.php';
Depending on where the document lies that you are trying to include you will need to get the
correct directory first (ie if you are trying to include from from /path/file.php from
/path/path/file.php). Unlike normal HTML '/'does not result in your site root. It results in your
server root.

So if you have a file that exists at website.com/path/file.php you couldn't just do include
'/path/file.php' because that would actually look for the file at the root of the server which would
not exist.

To get around this you will want to utilize $_SERVER['DOCUMENT_ROOT'] which will then grab the
root of your document from the server which might look something like the following (depending
on your setup):

/var/www/html/website.com

And so rather than having to figure that out, you can just add the document root line to the
include statements

include $_SERVER['DOCUMENT_ROOT'] . '/path/file.php';


include_once $_SERVER['DOCUMENT_ROOT'] . '/path/file.php';
require $_SERVER['DOCUMENT_ROOT'] . '/path/file.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/path/file.php';
share  improve this answer  follow 
answered Oct 23 '14 at 18:01

Ian
2,78044 gold badges2525 silver badges3535 bronze badges
 I have edited the original question – Charley Baker Oct 23 '14 at 18:03
add a comment
0
You can redirect to other page when fields are empty or inputs are not matching.Can simply do

$username=$row["username"];
$password=$row["password"];
header("location:page_to_link.php?u=".$username);
}
else{
header("location:page you want to redirect");
}
you have to start session on the page you redirecting(linking) them by session_start().

Hope that helps


share  improve this answer  follow 
edited Oct 23 '14 at 18:03
answered Oct 23 '14 at 17:52

Salim Khan
5311 silver badge1212 bronze badges
 I have edited the original question, im looking for something else – Charley Baker Oct 23 '14 at
18:04
add a comment
0
You have forgotten to check if the form is submitted add the floowing in the beginning of your
code:

if(isset($_POST ['Username']) && isset($_POST ['Password'])){

and off course, don't forget to place a close bracket at the end
share  improve this answer  follow 
answered Oct 23 '14 at 18:34

jsp
1
add a comment
Not the answer you're looking for? Browse other questions tagged php html css xampp or ask
your own question.

You might also like