Having Trouble with a PHP Login Form,...

User 2388388 Photo


Registered User
129 posts

Hi,

I'm working on tweaking a classifieds program I obtained a year or 2 ago but I'm having some trouble.

If anyone could so kindly bail me out on this, I'd be most appreciative!!

I have this page: http://classifieds.your-adrenaline-fix.com/add.php

and the source code (with PHP) is

<?php
include ('header.php');

//header.php has session_start() and MySQL connect data

$current_file = $_SERVER['SCRIPT_NAME'];

if(isset($_POST['Email']) && isset($_POST['Password'])){
$email = $_POST['Email'];
$password = $_POST['Password'];
$MD5pass = md5($password);

if(!empty($email) && !empty($password)){
$query = "SELECT `ID` FROM `members` WHERE `Email`='".mysql_real_escape_string($email)."' AND `Password`='".mysql_real_escape_string($MD5pass)."'";

if($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);

if($query_num_rows==0) {
echo "<span class='error'>Invalid Login Credentials</span>";
} else if ($query_num_rows==1) {
$memberID = mysql_result($query_run, 0, 'ID');
$_SESSION['memberID'] = $memberID;
}
}

} else {
echo '<span class="error">Both Fields are Required</span>';
}
}

?>

<form id='generalform' class='container' method='POST' action= '<?php echo $current_file; ?>'>
<h3>Log In</h3>
<div class="field">
<label for"Email">Login Email:</label><input type="email" class="input" id="Email" name="Email" autofocus="on">
</div>
<div class="field">
<label for"password">Password:</label>
<input type="password" class="input" id="password" name="Password" maxlength="20">
</div>
<input type="submit" name="submit" id="submit" class="button" value="Login">
<a href="register.php" title="Click Here to Register">Not Yet A Member?</a>
</form>



I believe the 2 click problem began when I added the <?php echo $current_file; ?> so as to return a visitor back to the page they were previously on.

I can't take credit for this idea of returning the visitor to the previous page but I sure like the idea and would love to see this work properly.

if anyone could so kindly show me what's askew, I'd be most appreciative and I thank you all in advance!!
User 187934 Photo


Senior Advisor
20,247 posts
Online Now

Did you try removing that part to prove your theory?:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2733 Photo


Ambassador
426 posts

I don't even know where to begin with this php. Too many gaping security holes to go over here.
Let's not get all hurt.
User 464893 Photo


Ambassador
1,611 posts

I agree the action should point to the handler script. Are you modifying the script that was part of the classified script.
I created a classified system more to learn php. What I learnt is to follow the logic which in your case a visitor could already be registered so they need a choice, log in or register. What David says is true log ins and storage of data can be tricky. I abandoned mine when I realized just how many scripts I had to do, forgotten pass info. Member account management

Most Cpanels allow Noah Classifieds to be set up free. There is backup, Payment options and everything needed in a classified setup. I went down the self creation path and truly if what you have does not hit the ground running then consider one of the industry standard systems.

You seem to be pretty well ahead so maybe if you start to post to a script and let that handle the input and then redirect back to the home page or where you want the customer to go. If you do not do it yourself you will not know what to do if you get an error. The joy of programming. Set yourself up in Wamp and get the script working line by line. That is what I did for the tricky bits.

but the action statement is wrong. You can go to a php file with html echoing the input and have a back link to the page you want. I found with php it was best to have a script and or page for each step. ie if the person is registered they get welcome page with a timed return and if new then obviously their data should be stored in a temp database until it is activated by them clicking on a link emailed or code to use. I opted for a emailed code.

I wish you success I had fun and leant heaps and not create my own classified system. That should be left to pimply kids.

let us know you solution. As a last thought the Web Form Builder can handle the log in and you can script a back end to sort the input.
The Guy from OZ



Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.