Jump to content

Recommended Posts

Posted

I am following one of the video tutorials but the author isn't explaining the code fully. So I am looking to understand why he is coding it in this way.

<form action="" method="post">
	<div>
		<?php  if($error['alert'] != ''){ 
			echo "<div class='alert'>" . $error['alert'] . "</div>";
		 } ?>
		<label for="username">Username: *</label>
		<input type="text" name="username" value="<?php echo $input['user']; ?>" />
		<div class="error"><?php echo $error['user']; ?></div>
		<label for="password">Password: *</label>
		<input type="password" name="password" value="<?php echo $input['pass']; ?>" />
		<div class="error"><?php echo $error['pass']; ?></div>
		<p class="required"> * required fields</p>

		<input type="submit" name="submit" class="submit" value="submit" />
	</div>
</form>

 

The question here is why use the $error['alert']? this is an array. I don't see where the $error[] comes from. The only place it is defined is in another file and it is defined as nothing

$error['alert'] = '';

 

so what I am trying to figure out is why do it this way and not this way

 

$error = '';

Posted

Rather than having individual variables for input/error messages, I just wanted to group my messages into two arrays, $error and $input. Using these arrays gave the variables a bit more context than just using $user or $pass, and I feel that they make the code slightly easier to read and understand. $error['alert'] isn't the only item in that array - it also contains $error['user'] and $error['pass']. You don't have to do it this way, but it is the way that made the most sense to me.

 

You are actually correct - $error could be initially defined as "$error = '';". Either would work. Using "$error = '';" could actually save a couple lines of code, and might be the "better" way to do things.

Posted

okay, that sounds good. I am going to follow through the tutorial and make the login system. It would be awesome if you could explain things a bit more in future video tutorials. I am trying to learn php and I am going to try out this site to see how it works compared to other sites. I have some recommendations if you are interested to improve your site here

 

P.S, ben I really like your website. It looks great. Did you ever get that company to pay you for stealing your design?

Posted
It would be awesome if you could explain things a bit more in future video tutorials.

I do my best - sometimes things that seem obvious to me may not be obvious to others. It's something I'll probably be able to improve on the more tutorials I do. If you run into any other issues where I don't explain something fully, just post - I keep an eye on the PHP section of the forums.

 

I have some recommendations if you are interested to improve your site here

Sounds good. Feel free to post them or PM me if you'd prefer.

 

ben I really like your website. It looks great. Did you ever get that company to pay you for stealing your design?

Thanks! Nope, it never worked out. I did end up modifying my design a bit so they aren't quite so alike, but there isn't much I can do unfortunately.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...