Jump to content

Recommended Posts

Just recently I watched a video tutorial on created a php database and log in and registration page. I created all the php pages along with the code, I thought I was finished but when I went to style the page as we want it things began to get really confusing. Now I am trying to put the php code information in to the html pages I am making and I getting so many errors I don't know where to begin. Is there anyone out there that I can get to look at the files I created with php and see how I am putting them in the html. I attached the index file we wanted to create for our webpage to include the login and registration php.

 

Eliana Hebrew

index.php

Link to comment
https://forums.phpfreaks.com/topic/272750-help-with-code-errors/
Share on other sites

People here will almost never download attached files, as they are a security error. And if you post your whole code, it's usually too much to go through to guess which errors you are finding.

 

Post the first error, and the line of code on which it is appearing, as well as a few lines of code before that point (as errors generally exist higher up in the file than the line shown in the error).

Oh okay, thanks. But that's just it, I only see one error in my dreamweaver and its on line 117 the code is as follows:

 

<?php

if (isset($_GET['success']) && empty ($_GET['success'])){

echo'You\'ve been registered successfully! Please check your email to activate your account';

 

} else {

if(empty($_POST)=== false && empty($errors) === true){

 

$register_data = array(

'username' =>$_POST['username]'],

'password' =>$_POST['password]'],

'first_name' =>$_POST['first_name'],

'last_name' =>$_POST['last_name]'],

'email' =>$_POST['email]'],

'email_code' =>md5($_POST['username']+ microtime())

);

register_user($register_data);

header('Location: register.php? success');

exit();

}else{ if (empty($errors) === false) {

echo output_errors($errors);}

}

?>

Your code is missing one or more closing } (that closes the else { on about line 100.) has a bunch of miss-matched opening and closing {}

 

The error message you should be getting, which you didn't post so that someone here could more directly find the cause of the problem, concerns a syntax error/unexpected end of file, which is php's way of telling you that you have something that is not terminated by the time php reached the end of your code.

 

A tutorial for a registration script assumes that you already know enough of the basic php language so that you are not lost on what the php code syntax is or what the code is doing and that you just want to see/learn what a registration script would look like. You need to learn the basics of the php language before you attempt to use it for something like a registration script.

Edited by PFMaBiSmAd

You're going to need to stop using Dreamweaver, probably get some books on PHP and start from the beginning. Us telling you which bracket is out of place (which it's hard to tell without fixing the spacing, indenting, etc) won't help in the long run. 

 

You have a } at the end of a line which make it hard to spot. Did the tutorial go over indenting?

Well... since I can't start over and get books on php that is not an option. If you can't help I understand but maybe there is someone else on the forum that can better assist me with trying to figure this out. All I am asking for is if you understand the php code to help me learn it through practical application since I already have the code all I need is someone who is patient enough to walk through it with me. If there isn't enough time on the form I can communicate via email. what ever works.

No one here is going to help you find where you mis-typed some characters in your code. That isn't learning, that's just you following along with something you saw.

 

If you haven't read a basic php book or tutorial so that you know what the opening and closing {} mean, so that you can identify where they should be at in your code, you need to do that before you try to use a registration tutorial.

 

Also, look at it this way, we have identified what the problem in the code is - missing/mis-matched {}. If you cannot take that information and fix up the code to correct that problem, you will not be able to write any code that does what you want.

With the code indented and formatted a bit better, it's much easier to see where these problems are:

 

<?php
if (isset($_GET['success']) && empty ($_GET['success'])) {
echo'You\'ve been registered successfully! Please check your email to activate your account';

} else {
if(empty($_POST)=== false && empty($errors) === true) {

	$register_data =  array(
	'username' =>$_POST['username]'],
	'password' =>$_POST['password]'],
	'first_name' =>$_POST['first_name'],
	'last_name' =>$_POST['last_name]'],
	'email' =>$_POST['email]'],
	'email_code' =>md5($_POST['username']+ microtime())
	);
	register_user($register_data);
	header('Location: register.php? success');
	exit();
} else { 
	if (empty($errors) === false) {
	echo output_errors($errors);
	}
}
?>

Agreed. If you want to code any language, the most important thing is proper formatting (aka indentation). It makes things like this so much easier to debug, as you can see missing (or extra) parentesis and brackets very easily. When the code is not properly formatted, it is difficult to see (as you are finding out).

 

There are different ways of formatting, and usually they are arbitrary (depending on the language), but the most important thing is consitency. Pick a style and always use it. You will then learn to see your code more clearly, and also your code will be more clear to others that you may show it to. Inconsistent formatting/indentation is something you should seek to eliminate right away.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.