Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:21:39+00:00 2026-06-14T01:21:39+00:00

PHP isn’t my thing but I need to set up a simple login area–so

  • 0

PHP isn’t my thing but I need to set up a simple login area–so here I am. Here’s some code I found that seems to work, but won’t redirect.

If I change the redirect to an echo it works. If I change the location to “include” instead it works. What am I doing wrong in the “location” code?

Am open to suggestions on alternately coding this. I have a single webpage that if the user enters a password an additional section on the site will appear. So I have a form on that site submitting to this code and then it’s supposed to redirect back with the new section now visible.

Here’s my code–

<?php

// error reporting
ini_set('display_errors',1); 
 error_reporting(E_ALL);

$host="localhost"; // Host name
$username="foo"; // Mysql username
$password="foo"; // Mysql password
$db_name="foo"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
header("Location: http://www.google.com/"); 

// Register $myusername, $mypassword 
// success
//session_register("myusername");
//session_register("mypassword");
}
else {
echo "Wrong Username or Password";
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:21:41+00:00Added an answer on June 14, 2026 at 1:21 am

    session_register is deprecated. Hence output already send which you could have seen had error reporting was on. Nothing can be output before header

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

php isn't really my thing but I would need to get the votes and
I'm trying to insert registration data into a database but my php code isn't
I am writing a web page that uses some php files. The php isn't
I've been testing nuSoap with codeIgniter (PHP Framework) but seems nuSoap isn't prepared to
I recently installed PHP on IIS/Windows 7, but it isn't working. I am getting
For some reason my submit button isn't centered. http://prime.programming-designs.com/test_forum/viewboard.php?board=0 #submitbutton{ margin: auto; border: 1px
Hello guys. I think it isn't possible just using PHP, but just to be
Recently a teacher said PHP isn't a real programming language, but only gave, in
The problem I'm having is that PHP isn't handling my continue correctly. My code
Possible Duplicate: Are PHP short tags acceptable to use? <?php //Some code ?> or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.