Jump to content
#StayAtHome ×

Archived

This topic is now archived and is closed to further replies.

sqlnoob

problem: php variable to search sql table

Recommended Posts

OK I'm a noob at this, but I recently got a website. The SQL tables are in PHPadmin. I've been trying to use a php variable that I get with a POST from a form on a different htm page called login.htm. The php variable I use in a page called settings.php to check wether the person has entered the correct password.

 

I know the php part is correct in such a way that it doesn't cause syntax error or what else and I also know that I do connect to the sql table.

 

Somehow though I am doing something wrong and I'm too much of a noob to figure out what I'm doing wrong, so please help me if you can.

 

-> The WHERE clause for some reason doesn't do anything with my php variable. <-

 

I know the connector is right, I know the table is right, I know the password is right, yet I still get the wrong echo i.e. it echoes I put incorrect password, when infact I have used the correct one. I also checked wether I've mistakenly misplaced the if-else, but that's not it either.

Share this post


Link to post
Share on other sites

Here is what the files and my table look like:

 

LOGIN.HTM

 

<HTML>

<HEAD>

<TITLE>SHUGO</TITLE>

<META NAME="keywords" CONTENT="login">

<link rel="stylesheet" type="text/css" href="shugostyle.css"/>

</HEAD>

<BODY><H1>LOGIN</H1>

<div align="center"><FORM method="Post" action="settings.php">

<P>Enter your password <INPUT type="userpass" size=8 maxlength="8" name="password">

Choose your clan <SELECT size=1 name="player">

<OPTION value="Akita">Akita</OPTION>

<OPTION value="Amako">Amako</OPTION>

<OPTION value="Arima">Arima</OPTION>

<OPTION value="Asakura">Asakura</OPTION>

<OPTION value="Chiba">Chiba</OPTION>

<OPTION value="Chosokabe">Chosokabe</OPTION>

<OPTION value="Hatakeyama">Hatakeyama</OPTION>

<OPTION value="Hatano">Hatano</OPTION>

<OPTION value="Hojo">Hojo</OPTION>

<OPTION value="Hosokawa">Hosokawa</OPTION>

<OPTION value="Imagawa">Imagawa</OPTION>

<OPTION value="Ishida">Ishida</OPTION>

<OPTION value="Isshiki">Isshiki</OPTION>

<OPTION value="Ito">Ito</OPTION>

<OPTION value="Jinbo">Jinbo</OPTION>

<OPTION value="Kikkawa">Kikkawa</OPTION>

<OPTION value="Kikuchi">Kikuchi</OPTION>

<OPTION value="Kono">Kono</OPTION>

<OPTION value="Maeda">Maeda</OPTION>

<OPTION value="Matsudaira">Matsudaira</OPTION>

<OPTION value="Miyoshi">Miyoshi</OPTION>

<OPTION value="Mori">Mori</OPTION>

<OPTION value="Nagao">Nagao</OPTION>

<OPTION value="Oda">Oda</OPTION>

<OPTION value="Otomo">Otomo</OPTION>

<OPTION value="Ouchi">Ouchi</OPTION>

<OPTION value="Shimazu">Shimazu</OPTION>

<OPTION value="Shoni">Shoni</OPTION>

<OPTION value="Takeda">Takeda</OPTION>

<OPTION value="Uesugi">Uesugi</OPTION>

<OPTION value="Urakami">Urakami</OPTION>

<OPTION value="Yamana">Yamana</OPTION>

</SELECT>

<INPUT type="Submit" value="Login" name="login">

</form></div>

</BODY>

</HTML>

Share this post


Link to post
Share on other sites

SETTINGS.PHP

 

<?php

$pass = $_POST["userpass"];

$group = $_POST["player"];

 

if ($con = @mysql_connect('localhost', 'shugonl', 'password')) {

mysql_select_db('shugonl', $con);

 

$tabpass = mysql_query ("SELECT Password FROM persons WHERE Clan='$group';");

 

if ($pass == $tabpass) {

$Allowlogin = 1;

setcookie("person", $_POST['clan'], time()+7200);

}

else {

$Allowlogin = 0;

}

?>

<HTML>

<HEAD>

<TITLE>shugo</TITLE>

<META NAME="keywords" CONTENT="settings">

<style type="text/css">

h1,h2,h3,p {font-family: verdana;}

h1,h2,h3,p {text-align: center}

body {background-color: #2F7B3A;}

a:link {color: #80FFFF}   

a:visited {color: #FF80C0}

a:hover {color: #FFFF80} 

a:active {color: #80FFFF}

</style>

</HEAD>

<BODY><H1>Welcome</H1>

<P>

<?php

if ($Allowlogin == 1) {

echo "<a href='daimyo.htm'>Continue</A>";

}

else {

echo "incorrect password please try again";

echo "<BR><a href='index.htm'>back</A>";

}

 

} else {

echo 'connection failed';

}

?>

</BODY>

</HTML>

Share this post


Link to post
Share on other sites

<?php

 

if ($con = @mysql_connect('localhost', 'shugonl', 'password')) {

mysql_select_db('shugonl', $con);

echo 'connected to the database';

} else {

echo 'connection failed';

}

 

mysql_select_db("shugonl", $con);

$sqlpersons = "CREATE TABLE persons

(

Password varchar(8),

Clan varchar(10),

Username varchar(20),

Coffer int(8),

Taxheight int(1),

Yari int(6),

Dachi int(5),

Yumi int(5),

Daisho int(5),

Honjin int(2),

Taxyear int(2),

Attackp int(1),

Lastyear int(2)

)";

mysql_query($sqlpersons,$con);

 

$startday = idate("d");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Akita', 'unused', '0', '2', '0', '0', '0', '0', '2', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Amako', 'unused', '0', '2', '0', '0', '0', '0', '44', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Arima', 'unused', '0', '2', '0', '0', '0', '0', '59', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Asakura', 'unused', '0', '2', '0', '0', '0', '0', '18', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Chiba', 'unused', '0', '2', '0', '0', '0', '0', '14', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Chosokabe', 'unused', '0', '2', '0', '0', '0', '0', '56', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Hatakeyama', 'unused', '0', '2', '0', '0', '0', '0', '32', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Hatano', 'unused', '0', '2', '0', '0', '0', '0', '49', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Hojo', 'unused', '0', '2', '0', '0', '0', '0', '13', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Hosokawa', 'unused', '0', '2', '0', '0', '0', '0', '33', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Imagawa', 'unused', '0', '2', '0', '0', '0', '0', '17', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Ishida', 'unused', '0', '2', '0', '27', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Isshiki', 'unused', '0', '2', '0', '0', '0', '0', '50', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Ito', 'unused', '0', '2', '0', '0', '0', '0', '63', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Jinbo', 'unused', '0', '2', '0', '0', '0', '0', '19', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Kikkawa', 'unused', '0', '2', '0', '0', '0', '0', '43', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Kikuchi', 'unused', '0', '2', '0', '0', '0', '0', '61', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Kono', 'unused', '0', '2', '0', '0', '0', '0', '54', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Maeda', 'unused', '0', '2', '0', '0', '0', '0', '22', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Matsudaira', 'unused', '0', '2', '0', '0', '0', '0', '25', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Miyoshi', 'unused', '0', '2', '0', '0', '0', '0', '53', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Mori', 'unused', '0', '2', '0', '0', '0', '0', '37', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Nagao', 'unused', '0', '2', '0', '0', '0', '0', '3', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Oda', 'unused', '0', '2', '0', '0', '0', '0', '28', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Otomo', 'unused', '0', '2', '0', '0', '0', '0', '57', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Ouchi', 'unused', '0', '2', '0', '0', '0', '0', '46', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Shimazu', 'unused', '0', '2', '0', '0', '0', '0', '65', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Shoni', 'unused', '0', '2', '0', '0', '0', '0', '62', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Takeda', 'unused', '0', '2', '0', '0', '0', '0', '9', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp)

VALUES ('demo', 'Uesugi', 'unused', '0', '2', '0', '0', '0', '0', '11', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Urakami', 'unused', '0', '2', '0', '0', '0', '0', '39', '$startday', '0', '$startday')");

 

mysql_query("INSERT INTO persons (Password, Clan, Username, Coffer, Taxheight, Yari, Dachi, Yumi, Daisho, Honjin, Taxyear, Attackp, Lastyear)

VALUES ('demo', 'Yamana', 'unused', '0', '2', '0', '0', '0', '0', '42', '$startday', '0', '$startday')");

 

Share this post


Link to post
Share on other sites

I didn't know where else to put this. So please show some mercy, if I for some reason have done something wrong in the placing.

 

I'm only new at this and English isn't my native tongue.

Share this post


Link to post
Share on other sites

First, a couple things....

1) When posting code, please use the code button on the toolbar (it's the one with a # sign)

2) You shouldn't post usernames/passwords that are in your code. Replace them with *s

3) You posted this in the MSSQL area, but you are looking for PHP/MySQL

 

Nonetheless, I have 2 recommendations. First, remove the semicolon in this line:

$tabpass = mysql_query ("SELECT Password FROM persons WHERE Clan='$group';");

should be:

$tabpass = mysql_query ("SELECT Password FROM persons WHERE Clan='$group'");

 

You are using the return value from mysql_query incorrectly. You need to use a mysql_fetch_* function to get data from the query. The updated settings.php file should look like:

 

<?php
$pass = $_POST["userpass"];
$group = $_POST["player"];

if ($con = @mysql_connect('localhost', 'shugonl', 'password')) {
mysql_select_db('shugonl', $con);

$result = mysql_query ("SELECT Password FROM persons WHERE Clan='$group'");
$row = mysql_fetch_assoc($result);
$tabpass = $row['Password'];

if ($pass == $tabpass) {
$Allowlogin = 1;
setcookie("person", $_POST['clan'], time()+7200);
}
else {
$Allowlogin = 0;
}
?>
<HTML>
<HEAD>
<TITLE>shugo</TITLE>
<META NAME="keywords" CONTENT="settings">
<style type="text/css">
h1,h2,h3,p {font-family: verdana;}
h1,h2,h3,p {text-align: center}
body {background-color: #2F7B3A;}
a:link {color: #80FFFF}   
a:visited {color: #FF80C0}
a:hover {color: #FFFF80} 
a:active {color: #80FFFF}
</style>
</HEAD>
<BODY><H1>Welcome</H1>
<P>
<?php
if ($Allowlogin == 1) {
echo "<a href='daimyo.htm'>Continue[/url]";
}
else {
echo "incorrect password please try again";
echo "<BR><a href='index.htm'>back[/url]";
}

} else {
echo 'connection failed';
}
?>
</BODY>
</HTML>

Share this post


Link to post
Share on other sites

3) You posted this in the MSSQL area, but you are looking for PHP/MySQL

 

yeah but that's non-posting. That's why I said, that I'm sorry that I did it here, but I couldn't do it there.

 

Anyway thanks for the help. I'll look into it and hopefully it will work now. :)

Share this post


Link to post
Share on other sites

Use this for your settings.php and let me know what the output is:

 

<?php
$pass = $_POST["userpass"];
$group = $_POST["player"];

if ($con = @mysql_connect('localhost', 'shugonl', 'password')) {
mysql_select_db('shugonl', $con);

$result = mysql_query ("SELECT Password FROM persons WHERE Clan='$group'")
  or die("Query failed");
$row = mysql_fetch_assoc($result);
print_r($row);
$tabpass = $row['Password'];
print "Entered pass: {$pass}<br>Table pass: {$row['Password']}";
exit;

if ($pass == $tabpass) {
$Allowlogin = 1;
setcookie("person", $_POST['clan'], time()+7200);
}
else {
$Allowlogin = 0;
}
?>
<HTML>
<HEAD>
<TITLE>shugo</TITLE>
<META NAME="keywords" CONTENT="settings">
<style type="text/css">
h1,h2,h3,p {font-family: verdana;}
h1,h2,h3,p {text-align: center}
body {background-color: #2F7B3A;}
a:link {color: #80FFFF}   
a:visited {color: #FF80C0}
a:hover {color: #FFFF80} 
a:active {color: #80FFFF}
</style>
</HEAD>
<BODY><H1>Welcome</H1>
<P>
<?php
if ($Allowlogin == 1) {
echo "<a href='daimyo.htm'>Continue[/url]";
}
else {
echo "incorrect password please try again";
echo "<BR><a href='index.htm'>back[/url]";
}

} else {
echo 'connection failed';
}
?>
</BODY>
</HTML>

Share this post


Link to post
Share on other sites

oh wait lol  ;D

 

this is what I did wrong

 

<INPUT type="userpass" size=8 maxlength="8" name="password">

 

I mixed the input type with the input name. hahaha silly me

 

anyway it works now! :)

 

thanks alot for the help

 

Share this post


Link to post
Share on other sites

×
×
  • 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.