Jump to content

Recommended Posts

well im learning php and mysql i found this tutorial http://www.phpeasystep.com/workshopview.php?id=6 and i was wondering how to make the checklogin.php and main_login.php parts into the same webpage like once it sends the form information it just reloads the webpage and it registers a session and displays information from the database using the username id this is my first week into learning how to program php and mysql so feel free to educate me  :o

Link to comment
https://forums.phpfreaks.com/topic/177278-need-help-with-some-php-logic/
Share on other sites

quite easy

<form>
<!-- form stuff -->
<?php

if (isset($_POST['username'])){//whatever the username input field is
//paste your login check stuff here
}
?>

 

you can either set the action of the form to the same page, OR just don't set an action at all. If you don't set an action on the form, the action will  by default be the page of the form.

 

the isset() checks of the post variable is set. and the only way the post variable will be set is if the user filled out the form and clicked submit. then it does the check login stuff. this is actually a very common thing for people to do

<?php
if (isset($_POST['username'])
{
echo "fsaf";
}
else
{
echo "<form name="login" method="post" action="index.php">";
echo "<input name="username" type="text" id="username">";
echo "<font color="#A4A4A4"><h3><center><bold>PASSWORD</bold></center></h3></font>";
echo "<input name="password" type="password" id="password"><br>";
echo "<center><input type="submit" name="Submit" value="Login"></form></center>";
}
?>

 

whats wrong with this

The syntax highlighting shows you exactly whats wrong, you start the echo statement with a double quote, so as soon as it encouners another double quote it thinks that string is finished you need to either swap some of the quotes to single quotes or you need to escape the double quoets.

 

Example:

echo "<form name=\"login\" method=\"post\" action=\"index.php\">";

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.