PHP Help! - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HUKD, you accept our cookie and privacy policy.
Get the HUKD app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

PHP Help!

jennyrocks Avatar
8y, 3m agoPosted 8 years, 3 months ago
Hello I have just started to learn myself PHP from a book and I've just followed what it said to do and now all I get is a white page... I've checked over the book and my code is exactly like it is in the book :S so I am looking for somebody who knows some PHP to help me out please.
Thanks
jennyrocks Avatar
8y, 3m agoPosted 8 years, 3 months ago
Options

All Comments

(35) Jump to unreadPost a comment
Comments/page:
#1
Which programme you using to write it? Dreamweaver?
#2
Yeah i'm using Dreamweaver but typing in the code myself if that makes sense. Basically when I put this into the top of the PHP code I get a white page.

The code I'm trying to put in is:

$meta = &new Meta;

$meta->company_name = "My Company";
$meta->description = "This is my first PHP enabled website";
$meta->keywords2 = "PHP, MySQL, Web Development";
$meta->sitename = "My PHP Site";
$meta->slogan = "Be Patient, I'm Learning";
$meta->generator = "PHP";
#3
jennyrocks
Yeah i'm using Dreamweaver but typing in the code myself if that makes sense. Basically when I put this into the top of the PHP code I get a white page.

The code I'm trying to put in is:

$meta = &new Meta;

$meta->company_name = "My Company";
$meta->description = "This is my first PHP enabled website";
$meta->keywords2 = "PHP, MySQL, Web Development";
$meta->sitename = "My PHP Site";
$meta->slogan = "Be Patient, I'm Learning";
$meta->generator = "PHP";


thats meta tags, which only are seen by search engines, it won't show on a web page
#4
jennyrocks
Yeah i'm using Dreamweaver but typing in the code myself if that makes sense. Basically when I put this into the top of the PHP code I get a white page.

The code I'm trying to put in is:

$meta = &new Meta;

$meta->company_name = "My Company";
$meta->description = "This is my first PHP enabled website";
$meta->keywords2 = "PHP, MySQL, Web Development";
$meta->sitename = "My PHP Site";
$meta->slogan = "Be Patient, I'm Learning";
$meta->generator = "PHP";



Cant really think at mo as half asleep!! Is that all you got on the page? As you need to open and close the php script?
#5
faevilangel
thats meta tags, which only are seen by search engines, it won't show on a web page


Yeah I know that but it is on a page that has content, the page works fine without the meta code but with it just shows a white page.
#6
jennyrocks
Yeah I know that but it is on a page that has content, the page works fine without the meta code but with it just shows a white page.


i can't see the problem but try using this way of doing meta tags

echo \"n\";

using the echo command you can insert HTML tags :)
banned#7
jennyrocks
Yeah I know that but it is on a page that has content, the page works fine without the meta code but with it just shows a white page.


That PHP code in itself does nothing, it may even generate an error. Are you sure that you haven't missed a slice of code from a previous page or example?
#8
beelzebub
That PHP code in itself does nothing, it may even generate an error. Are you sure that you haven't missed a slice of code from a previous page or example?


double check you have < ?php at start and ?> at end :thumbsup:
#9
faevilangel
i can't see the problem but try using this way of doing meta tags

echo \"n\";

using the echo command you can insert HTML tags :)


Hi thanks for replying :) I have pasted this into my code and it has made the ?> not work and displayed another white screen.

The way i've done the coding so far is to have a template layout made and then my index file is just pure php that calls the template and fills it. It also calls a class file that the uses the meta data to put it in html tags. Again my code for the class is the same as the book and isn't working.

I've found the same chapter from the book online if that helps; It is http://ultimatephp.blogspot.com/2007/11/chapter-4-building-website-template.html

I've followed the code exactly and from the clsMetaContent.php it isn't working
#10
jennyrocks
Hi thanks for replying :) I have pasted this into my code and it has made the ?> not work and displayed another white screen.

The way i've done the coding so far is to have a template layout made and then my index file is just pure php that calls the template and fills it. It also calls a class file that the uses the meta data to put it in html tags. Again my code for the class is the same as the book and isn't working.

I've found the same chapter from the book online if that helps; It is http://ultimatephp.blogspot.com/2007/11/chapter-4-building-website-template.html

I've followed the code exactly and from the clsMetaContent.php it isn't working


ok whats your reason for using php ? unless your using MYsql or for security , it has not much use........

you can write most of the php stuff using html .......

e.g.

include the html tags here ........

?>

i use php as no one can steal your code when its php, as its not stored locally...... (stored on the server)

i too have learnt php from a book but prefer using [url]www.w3schools.com/php[/url]
#11
Well I plan to make a turn based PHP, MySQL game (when I know how lol!) like http://www.monstersgame.co.uk/
It will take some time to learn everything I know but I am quite good at various programming languages once I've got the hang of them.
banned#12
I found this particular chapter online (pdf form) and in my opinion it's poorly written, very easy to get confused.
#13
Is that piece of code meant to be an array? If so Ive never seen an array constructed like that before, however im no PHP expert.
#14
jennyrocks
Well I plan to make a turn based PHP, MySQL game (when I know how lol!) like http://www.monstersgame.co.uk/
It will take some time to learn everything I know but I am quite good at various programming languages once I've got the hang of them.


ahhh ok, i can help you with the php coding if you need,........ you would want a login form? a database to store users data, their "level" etc...... its tough to make in php but its fun :-D
#15
razta
Is that piece of code meant to be an array? If so Ive never seen an array constructed like that before, however im no PHP expert.


no they are meta tqags - they show a search engine what the site is about ..... its a easy way to get google to notice your content and get a better ranking
#16
faevilangel
ahhh ok, i can help you with the php coding if you need,........ you would want a login form? a database to store users data, their "level" etc...... its tough to make in php but its fun :-D


Thanks that would be great, Sounds like you've made one yourself?
Yeah login form, database, file handling etc.
My favourite programming language is vb.net :) I'm learning Java atm which is useful. What's your favourite language?
Do you know of any good PHP books? I think the fastest way of learning a prog language is by following really simple tutorials and evolving them into your own.
#17
jennyrocks
Thanks that would be great, Sounds like you've made one yourself?
Yeah login form, database, file handling etc.
My favourite programming language is vb.net :) I'm learning Java atm which is useful. What's your favourite language?
Do you know of any good PHP books? I think the fastest way of learning a prog language is by following really simple tutorials and evolving them into your own.


i only use web based languages (and preferably not made by microsoft)

i know php, javascript, c++, css, html, ajax, some C, im going to learn ASP soon though:thumbsup:
#18
I'm looking to learn ajax if I find a use for it to be implemented in to my site.

I don't get what's going on with it now, I've just made a simple sign up form and when I add validation code it gives me the white screen instead of the sign up form! I've found that it so far is when i put the following code...

$error = true;
$errors .= "Form Input Errors:"."\n\n"

Is that the right format etc? It's the first instance of both vars so have I created them correctly?
Thanks again
#19
jennyrocks
I'm looking to learn ajax if I find a use for it to be implemented in to my site.

I don't get what's going on with it now, I've just made a simple sign up form and when I add validation code it gives me the white screen instead of the sign up form! I've found that it so far is when i put the following code...

$error = true;
$errors .= "Form Input Errors:"."\n\n"

Is that the right format etc? It's the first instance of both vars so have I created them correctly?
Thanks again


you have a dot in there and you don't have an end ; on the second line
all php code needs to finish with a ;
#20
the .= is on all of the $errors :S
added the ; I know all lines apart from { need to be ;'d from java just always miss one out lol!
Still white screen tho... is it something to do with declaring the vars? I'm lost at this point!!
#21
jennyrocks
the .= is on all of the $errors :S
added the ; I know all lines apart from { need to be ;'d from java just always miss one out lol!
Still white screen tho... is it something to do with declaring the vars? I'm lost at this point!!


whats the full code you have ?
#22

include $_SERVER['DOCUMENT_ROOT'].'/layout1.php';

switch($_REQUEST['req']){

case "process";
myheader("Become a Member!!");

//Validate all required fields were posted
if(!$_POST['first_name'] ||
!$_POST['last_name'] ||
!$_POST['email_address'] ||
!$_POST['email_address2'] ||
!$_POST['username'] ||
!$_POST['password'] ||
!$_POST['password2'] ||
!$_POST['bio'] ||){

$error = true;
$errors .= "Form Input Errors:"."\n\n;"

if(!$_POST['first_name']){
$errors .= "Missing First Name\n";
}
if(!$_POST['last_name']){
$errors .= "Missing Last Name\n";
}
if(!$_POST['email_address']){
$errors .= "Missing Email Address\n";
$email_error = true;
}
if(!$_POST['email_address2']){
$errors .= "Missing Email Address2\n";
$email_error = true;
}
if(!$_POST['username']){
$errors .= "Missing Username\n";
}
if(!$_POST['password']){
$errors .= "Missing Password\n";
$password_error = true;
}
if(!$_POST['password2']){
$errors .= "Missing Password Verification\n";
$password_error = true;
}
if(!$_POST['bio']){
$errors .= "Missing Bio\n";
}
}

//If both emails were posted, validate they match
if($email_error == false){
if($_POST['email_address'] != $_POST['email_address2']){
$error = true;
$errors .= "Email addresses do not match!\n\n";
$email_error = true;
}
}

//If both passwords were posted, validate they match
if($password_error == false){
if($_POST['password'] != $_POST['password2']){
$error = true;
$errors .= "Passwords do not match!\n\n";
$password_error = true;
}
}

if($email_error == false){
// Verify if email address has been used already
$ecount = mysql_result(mysql_query("SELECT COUNT(*) AS ecount FROM members WHERE
email_address = '[$_POST['email_address'])'"),0;

// If email exists, genorate error and message
if($ecount > 0){
$error = true;
$errors .= "This email has already ".
"been used ".
"please reset your password.\n\n";
}
}

// Verify if username has been used already
$ucount = mysql_result(mysql_query("SELECT COUNT(*) AS ucount FROM members WHERE
username = '[$_POST['username'])'"),0;

// If username exists, genorate error and message
if($ucount > 0){
$error = true;
$errors .= "Username already exists, ".
"please choose another.\n\n";
}
}

// If $error is TRUE, then include the signup form
// and display the errors
if($error == true){
$errors = nl2br($errors);
include $_SERVER['DOCUMENT_ROOT'].'/html/forms/signup.html';
footer();
exit();
}

// All checks have passed, insert user to database

// Email User

// Email Admin

break;

default:
myheader("Become a Member!");
include $_SERVER['DOCUMENT_ROOT'].'/html/forms/signup.html';
footer();
break;

}
?>
#23
jennyrocks

include $_SERVER['DOCUMENT_ROOT'].'/layout1.php';

switch($_REQUEST['req']){

case "process";
myheader("Become a Member!!");

//Validate all required fields were posted
if(!$_POST['first_name'] ||
!$_POST['last_name'] ||
!$_POST['email_address'] ||
!$_POST['email_address2'] ||
!$_POST['username'] ||
!$_POST['password'] ||
!$_POST['password2'] ||
!$_POST['bio'] ||){

$error = true;
$errors .= "Form Input Errors:"."\n\n;"

if(!$_POST['first_name']){
$errors .= "Missing First Name\n";
}
if(!$_POST['last_name']){
$errors .= "Missing Last Name\n";
}
if(!$_POST['email_address']){
$errors .= "Missing Email Address\n";
$email_error = true;
}
if(!$_POST['email_address2']){
$errors .= "Missing Email Address2\n";
$email_error = true;
}
if(!$_POST['username']){
$errors .= "Missing Username\n";
}
if(!$_POST['password']){
$errors .= "Missing Password\n";
$password_error = true;
}
if(!$_POST['password2']){
$errors .= "Missing Password Verification\n";
$password_error = true;
}
if(!$_POST['bio']){
$errors .= "Missing Bio\n";
}
}

//If both emails were posted, validate they match
if($email_error == false){
if($_POST['email_address'] != $_POST['email_address2']){
$error = true;
$errors .= "Email addresses do not match!\n\n";
$email_error = true;
}
}

//If both passwords were posted, validate they match
if($password_error == false){
if($_POST['password'] != $_POST['password2']){
$error = true;
$errors .= "Passwords do not match!\n\n";
$password_error = true;
}
}

if($email_error == false){
// Verify if email address has been used already
$ecount = mysql_result(mysql_query("SELECT COUNT(*) AS ecount FROM members WHERE
email_address = '[$_POST['email_address'])'"),0;

// If email exists, genorate error and message
if($ecount > 0){
$error = true;
$errors .= "This email has already ".
"been used ".
"please reset your password.\n\n";
}
}

// Verify if username has been used already
$ucount = mysql_result(mysql_query("SELECT COUNT(*) AS ucount FROM members WHERE
username = '[$_POST['username'])'"),0;

// If username exists, genorate error and message
if($ucount > 0){
$error = true;
$errors .= "Username already exists, ".
"please choose another.\n\n";
}
}

// If $error is TRUE, then include the signup form
// and display the errors
if($error == true){
$errors = nl2br($errors);
include $_SERVER['DOCUMENT_ROOT'].'/html/forms/signup.html';
footer();
exit();
}

// All checks have passed, insert user to database

// Email User

// Email Admin

break;

default:
myheader("Become a Member!");
include $_SERVER['DOCUMENT_ROOT'].'/html/forms/signup.html';
footer();
break;

}
?>


ok try something, works for me :) on your includes change them to

include ('filename.php');
#24
I've just changed it and still white page, when I have this code it works.


include ('layout1.php');

switch($_REQUEST['req']){
case "process";
myheader("Become a Member2!");

echo $_POST['username'];

//Validate all required fields were posted
if(!$_POST['first_name'] ||
!$_POST['last_name'] ||
!$_POST['email_address'] ||
!$_POST['email_address2'] ||
!$_POST['username'] ||
!$_POST['password'] ||
!$_POST['password2'] ||
!$_POST['bio']){

//$error = true;
//$errors .= "Form Input Errors:"."\n\n;"

if(!$_POST['first_name']){
$errors .= "Missing First Name\n";
}
if(!$_POST['last_name']){
$errors .= "Missing Last Name\n";
}
if(!$_POST['email_address']){
$errors .= "Missing Email Address\n";
$email_error = true;
}
if(!$_POST['email_address2']){
$errors .= "Missing Email Address2\n";
$email_error = true;
}
if(!$_POST['username']){
$errors .= "Missing Username\n";
}
if(!$_POST['password']){
$errors .= "Missing Password\n";
$password_error = true;
}
if(!$_POST['password2']){
$errors .= "Missing Password Verification\n";
$password_error = true;
}
if(!$_POST['bio']){
$errors .= "Missing Bio\n";
}
}





break;

default:
myheader("Become a Member!");
include ('signup.html');
footer();
break;
}
?>

Stripped down version and $error / $errors commented out
#25
With the Stripped down version it works with just $errors commented out so it must be something to do with that var?
#26
jennyrocks
I've just changed it and still white page, when I have this code it works.


include ('layout1.php');

switch($_REQUEST['req']){
case "process";
myheader("Become a Member2!");

echo $_POST['username'];

//Validate all required fields were posted
if(!$_POST['first_name'] ||
!$_POST['last_name'] ||
!$_POST['email_address'] ||
!$_POST['email_address2'] ||
!$_POST['username'] ||
!$_POST['password'] ||
!$_POST['password2'] ||
!$_POST['bio']){

//$error = true;
//$errors .= "Form Input Errors:"."\n\n;"

if(!$_POST['first_name']){
$errors .= "Missing First Name\n";
}
if(!$_POST['last_name']){
$errors .= "Missing Last Name\n";
}
if(!$_POST['email_address']){
$errors .= "Missing Email Address\n";
$email_error = true;
}
if(!$_POST['email_address2']){
$errors .= "Missing Email Address2\n";
$email_error = true;
}
if(!$_POST['username']){
$errors .= "Missing Username\n";
}
if(!$_POST['password']){
$errors .= "Missing Password\n";
$password_error = true;
}
if(!$_POST['password2']){
$errors .= "Missing Password Verification\n";
$password_error = true;
}
if(!$_POST['bio']){
$errors .= "Missing Bio\n";
}
}





break;

default:
myheader("Become a Member!");
include ('signup.html');
footer();
break;
}
?>

Stripped down version and $error / $errors commented out


how old is that book :whistling: what php does it cover e.g. 4.3???

php is now nearing version 6 :? i would reccomend using [url]www.w3schools.com/php[/url] to learn from ..... its up to date, (unlike a lot of books) also use [url]www.php.net[/url] to help with any errors
#27
lol the book is from 2003 and covers 4.3.x

I assumed it would be the same coding :( I've got PHP 5.2.6 installed.

Does this makes loads of difference?? :O
1 Like #28
jennyrocks
lol the book is from 2003 and covers 4.3.x

I assumed it would be the same coding :( I've got PHP 5.2.6 installed.

Does this makes loads of difference?? :O


a lot of commands from php 4 is now defunct in 5.2

some of the commands are the same but many are not...... thats why i use web pages :-D
#29
Glad I found this out now and not after a few weeks haha I'm gonna just read everything on the w3schools site like I did with html lol.
Thanks for your help, gonna get some kip and then try again tomorrow :D.
Will post in this thread again if I get stuck, if you don't mind would you drop in again and see if you can find anything i'm doing wrong if I get stuck agian please?
#30
jennyrocks
Glad I found this out now and not after a few weeks haha I'm gonna just read everything on the w3schools site like I did with html lol.
Thanks for your help, gonna get some kip and then try again tomorrow :D.
Will post in this thread again if I get stuck, if you don't mind would you drop in again and see if you can find anything i'm doing wrong if I get stuck agian please?


im around too much so course i will, or just pm me ;-) so i can feel loved :whistling::p
#31
TBH if you are doing a lot of logic rather than front end, you'd be better off using a IDE (as it will show synatactic errors in code).
Netbeans is a pretty good IDE - and recently has added support for PHP.
http://www.netbeans.org/kb/docs/php/php-editor-screencast.html
Also if you are designing a database backend, take some time to plan it out before you begin coding, as it can be a pain in the ass. I wouldn't recommend using PHP to set up the tables, instead use a specialised tool like MySQLAdmin to begin with
#32
MoneySavingG
TBH if you are doing a lot of logic rather than front end, you'd be better off using a IDE (as it will show synatactic errors in code).
Netbeans is a pretty good IDE - and recently has added support for PHP.
http://www.netbeans.org/kb/docs/php/php-editor-screencast.html
Also if you are designing a database backend, take some time to plan it out before you begin coding, as it can be a pain in the ass. I wouldn't recommend using PHP to set up the tables, instead use a specialised tool like MySQLAdmin to begin with


i use php to write my tables & it works well....... mysqladmin is trash compared to PHPmyadmin :p
#33
faevilangel;2870281
i use php to write my tables & it works well....... mysqladmin is trash compared to PHPmyadmin :p


Lol yeah, I always get those two mixed up. I'm usually do my stuff in postgresql, because I'm so used to it now.
Really, I don't like all those DB admin tools. It's a lot better to sit down with a pen and paper, and draw up the database as a entity-relationship model. Then you can work directly with the database shell by using it's native commands.
#34
I've done a bit more of PHP now and can understand it more but this Meta script it still not working :|

I've found out that certain lines are making the page show a white screen but cannot see what is wrong with the lines in question :S

$meta = new Meta;
< ?php echo $meta->metadata($ptitle); ?>

Can anybody see anything wrong with these two lines? The first is in a different < ?php ?> so it is closed etc without the two lines the page works fine and displays the page correctly.

I want to move on and learn more but this is really bugging me lol.
#35
you have an outdated book so gonna be hard for ya :|

here is the code to do it right (i think) (i had to google this)

$tpTitle="Helping you to improve your web site";
$pgHeading="Site-Report.com - Helping you to improve your web site";
$pgDesc="Helping you to improve your web site";
$pgKeywords="site-report";
?>

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!