Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page login system moved here to the side but fails
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
buch78 is on a distinguished road
 
Posts: 13
Join Date: Jun 2011
Default login system moved here to the side but fails - 06-04-2011, 06:23 AM

I really need help. I have previously driven a login system on another server but I can not get it to work here ..

I checked not about who is logged in. .. yet

adforbind.php
<?
$mysql_host = "mysql7.000webhost.com";
$mysql_database = "login";
$mysql_user = "a8915655_geo";
$mysql_password = "****";
mysql_connect("$mysql_host","$mysql_user","$mysql_ password") or die(mysql_error());
mysql_select_db("$mysql_database")or die;
?>


indskrivperson.php
<?php
include "adforbind.php";
?>
<form action="<? echo $PHP_SELF; ?>" method="POST">
<font size="5">Indtast oplysninger</font>
<br>
<table>
<tr>
<td>Brugernavn</td>
<td><input type="text" name="bruger" size="20"> </td>
</tr>
<tr>
<td>kode</td>
<td><input type="text" name="pass" size="20"></td>
</tr>
<tr>
<td>Rang </td>
<td>
<select name="rang" >
<option value = bruger>bruger</option>
<option value = admin>admin</option>
</table>
<br>
<input type="submit" name="Gem" value="Gem data" />
<br><br>
</form>
<?php
if (isset($_POST['Gem']))
{
if (mysql_result(mysql_query("SELECT bruger FROM login WHERE bruger=$_POST[bruger]"),0) > 0)
{
echo 'Brugernavnet findes allerede!';
}
else
{
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST[bruger]',MD5('$_POST[pass]'),'$_POST[rang]')") or die(mysql_error());
echo 'Brugeren er blevet tilføjet!';
}
}
?>

Database a8915655_geo
Table structure for table login
Field Type Null Default Comments
bruger varchar(20) Yes NULL
pass varchar(32) Yes NULL
rang char(20) Yes NULL

Dumping data for table login
bruger pass rang
admin 21232f297a57a5a743894a0e4a801fc3 admin
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 06-04-2011, 12:02 PM

The input form does not look like a login system, it's rather registration form.
If this is a login form, there is no need to make insert query as quoted below.
Quote:
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST[bruger]',
MD5('$_POST[pass]'),'$_POST[rang]')")
Is it necessary to insert/save data whenever a user is logged in?
What do you mean "I can not get it to work here"? What kind of error
message did you get?

Last edited by grace1004; 06-04-2011 at 12:08 PM.
Reply With Quote
(#3 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,521
Join Date: Jul 2009
Location: Spain
Default 06-04-2011, 12:23 PM

Hi, There are some errors in your code.

1. The name of the database can not login. The name of the database always includes the name of the user. Is the name of your database "a8915655_login?
adforbind.php
PHP Code:
<?php
$mysql_host 
"mysql7.000webhost.com";
 
// Begin code incorrect
$mysql_database "login";  // End code incorrect
$mysql_user "a8915655_geo";
$mysql_password "****";
mysql_connect($mysql_host,$mysql_user,$mysql_password) or die(mysql_error());
mysql_select_db($mysql_database)or die;
?>
2. To access the contents of the variable $ _POST array should quote the name of the variable.
You write the following:
PHP Code:
bruger=$_POST[bruger
And it would be more correct to write:
PHP Code:
bruger=$_POST['bruger'

PHP Code:
<?php 
if (isset($_POST['Gem'])) 
    {
    if (
mysql_result(mysql_query("SELECT bruger FROM login WHERE bruger=$_POST['bruger']"),0) > 0
        {
        echo 
'Brugernavnet findes allerede!';
        } 
    else 
        {
        
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST['bruger']',MD5('$_POST['pass']'),'$_POST['rang']')") or die(mysql_error());
        echo 
'Brugeren er blevet tilføjet!';
        }
    } 
?>


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma

Last edited by d3iti; 06-04-2011 at 12:26 PM.
Reply With Quote
(#4 (permalink))
Old
Junior Member
buch78 is on a distinguished road
 
Posts: 13
Join Date: Jun 2011
Default 06-05-2011, 05:17 PM

sorry wait time
It is part of a login system ..
problemert is to use pure zero is placed ..
and this code is only out to create new users ..
I am convinced of this works if I can get the rest to work ..
my database looks like this
»MySQL Database» MySQL User 'MySQL Host
a8915655_geo a8915655_geo mysql7.000webhost.com
Login
----
Full Text's user pass rank

I changed the code for this
<?php
if (isset($_POST['Gem']))
{
if (mysql_result(mysql_query("SELECT bruger FROM login WHERE bruger=$_POST['bruger']"),0) > 0)
{
echo 'Brugernavnet findes allerede!';
}
else
{
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST['bruger']',MD5('$_POST['pass']'),'$_POST['rang']')") or die(mysql_error());
echo 'Brugeren er blevet tilføjet!';
}
}
?>
but the error I get now is
"
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, Expecting T_STRING or T_VARIABLE or T_NUM_STRING in / home/a8915655/public_html/test/admin/indskrivperson.php on line 31 "

line 31 = if ( mysql_result ( mysql_query ( "SELECT bruger FROM login WHERE bruger=$_POST['bruger']" ), 0 ) > 0 )
Reply With Quote
(#5 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 06-05-2011, 06:51 PM

How about changing your query more simple as follows:

$result = mysql_query("SELECT bruger FROM login WHERE bruger='$_POST['bruger']'");
$row = mysql_num_rows($result);
if($row > 0 ) {
echo " ";
}
Reply With Quote
(#6 (permalink))
Old
Junior Member
buch78 is on a distinguished road
 
Posts: 13
Join Date: Jun 2011
Default 06-05-2011, 07:16 PM

like this
if (isset($_POST['Gem']))
{
if ($result = mysql_query("SELECT bruger FROM login WHERE bruger='$_POST['bruger']'");
$row = mysql_num_rows($result);
if($row > 0 ) {
echo "Bruger navnet findes i forvejen";
}
else
{
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST[bruger]',MD5('$_POST[pass]'),'$_POST[rang]')") or die(mysql_error());
echo 'Brugeren er blevet tilføjet!';
}
}
?>
but the error I get now is
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a8915655/public_html/test/admin/indskrivperson.php on line 31
Reply With Quote
(#7 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 06-06-2011, 12:13 AM

Please try the following code as it is (do not change anything).

Quote:
if (isset($_POST['Gem']))
{
$bruger = $_POST['bruger']; //newly added to make the variable shorter.

$result = mysql_query("SELECT bruger FROM login WHERE bruger='$bruger'");
$row = mysql_num_rows($result);
if($row > 0 ) {
echo "Bruger navnet findes i forvejen";
}
else
{
mysql_query("INSERT INTO login (bruger,pass,rang) VALUES ('$_POST[bruger]',MD5('$_POST[pass]'),'$_POST[rang]')") or die(mysql_error());
echo 'Brugeren er blevet tilføjet!';
}
}
?>
If the echo syntax were in English, it would have been better to help you.
In your code quoted later, there should not be if in front of $result=mysql_query . . .
if($row) > 0) means that the value for $_POST['bruger'] already exists in 'login' table,
so the echo systax in English should be similar to below:

echo "The same user_id already exists, please use other user_id";

Last edited by grace1004; 06-06-2011 at 01:15 AM.
Reply With Quote
(#8 (permalink))
Old
Junior Member
buch78 is on a distinguished road
 
Posts: 13
Join Date: Jun 2011
Default 06-08-2011, 06:55 PM

it works now so I can create users ..
but my login page does not work the detector is not even an error
It is as if something is not supported in php more
index.php
<CENTER>
<p align="center"><b><font size="7">login</font></b></p>
<br><br>
<form name="form" method="post" action="login-test.php">
<TABLE>
<TR><table border="1" >
<TD>Brugernavn:</TD>
<TD><input name="bruger" type="text" id="bruger" ></TD>
</TR>
<TR>
<TD>Kode:</TD>
<TD><input name="pass" type="password" id="pass" > </TD>
</TR>
</TABLE>
<br>
<input name="Submit" type="submit" id="Submit" value="Login">
</form>
<br><br>
</a>
</CENTER>



login-test.php
<?
$pass = MD5($_POST[pass]);

include "forbind.php"; // opretter forbindelse til serveren (mysql)
$resultat = mysql_query("SELECT bruger FROM login WHERE bruger = '$_POST[bruger]' AND pass = '$pass'");
$number = mysql_num_rows($resultat);
if($number == 1)
{
$get_id = mysql_fetch_array($resultat);
$q = mysql_query ("SELECT * FROM login WHERE bruger='".$get_id['bruger']."'");
while ($r = mysql_fetch_array($q))
{
session_start();
$rang = $r["rang"];
$_SESSION['login'] = $rang;
}
if ($rang == 'admin')
{
header("Location: \admin\index.htm");
}
if ($rang == 'bruger')
{
header("Location: \bruger\index.htm");
}
}
else
{
header("Location: \loginfejl.php");
}
mysql_close();
?>
Reply With Quote
(#9 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 735
Join Date: Dec 2010
Default 06-08-2011, 09:18 PM

Please try the following code:

Code:
while ($r = mysql_fetch_array($q)) 
{ 
session_start();
$rang = $r["rang"];
$_SESSION['login'] = $rang; 
} 
if ($rang == 'admin') 
{ 
header("Location: /admin/index.htm");
} 
else if ($rang == 'bruger') 
{ 
header("Location: /bruger/index.htm");
}
}
else 
{ 
header("Location: /loginfejl.php");
}
Reply With Quote
(#10 (permalink))
Old
Junior Member
buch78 is on a distinguished road
 
Posts: 13
Join Date: Jun 2011
Default 06-10-2011, 05:38 PM

no unfortunately it seems not .. I just get sent to loginfejl.php

<?
$pass = MD5($_POST[pass]);

include "forbind.php"; // opretter forbindelse til serveren (mysql)
$resultat = mysql_query("SELECT bruger FROM login WHERE bruger = '$_POST[bruger]' AND pass = '$pass'");
$number = mysql_num_rows($resultat);
if($number == 1)
{
$get_id = mysql_fetch_array($resultat);
$q = mysql_query ("SELECT * FROM login WHERE bruger='".$get_id['bruger']."'");
while ($r = mysql_fetch_array($q))
{
session_start();
$rang = $r["rang"];
$_SESSION['login'] = $rang;
}
if ($rang == 'admin')
{
header("Location: /admin/index.htm");
}
else if ($rang == 'bruger')
{
header("Location: /bruger/index.htm");
}
}
else
{
header("Location: /loginfejl.php");
}
mysql_close();
?>

How can I get a result on the screen of what the check up on sql ..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com