...

View Full Version : Would need fast help for my php script



byllan
04-28-2012, 08:54 AM
Hello i have been working for hours to make this script working. I want it check so the username, name, mail and code is true. If all is true it will show the password from the user and if not it will show a message like Something is wrong!

That's the site with the script apelsinen.com/?p=lostpassword
This is the script

<b>Forgot Password</b>
<?php
if (isset($_POST['submit'])){
$user = $_POST['user'];
$email = $_POST['email'];
$name = $_POST['name'];
$code = $_POST['code'];
$pass = $_GET['pass'];
$sql = "SELECT * FROM users WHERE email='$email' AND name='$name' AND code='$code' AND
user='$user' AND pass='$pass'";
if(!mysql_query($sql))
{
echo "Något är fel! ".mysql_error();
}
else
{
echo "Ditt lösenord är ".$pass."!";
}}
?>
<html>
<body>
<tr>
<form action="?p=lostpassword" method="post">
<td><br>Username:<br></td>
<td><input type="text" input type="text" name="user" value=""></td>
</tr>
<tr>
<td><br>Mail:<br></td>
<td><input type="text" name="email" value=""></td>
</tr>
<tr>
<td><br>Name:<br></td>
<td><input type="text" name="name" value=""></td>
</tr>
<tr>
<td><br>Secret Code:<br></td>
<td><input type="text" name="code" value=""></td>
</tr>
<tr>
<td>
<tr>
<br>
<input type="submit" name="submit" value="Get Password">
</td>
</tr>

</table>
</form>
<br>
<br>
</html>
</body>

This is the errors

Notice: Undefined index: pass in C:\xampp\htdocs\pages\lostpassword.php on line 8
Your Password is !

abduraooft
04-28-2012, 09:15 AM
Notice: Undefined index: pass in C:xampphtdocspageslostpassword.php on line 8
That's obvious from the line $pass = $_GET['pass']; , as ther won't be any such variable in $_GET

Your Password is !
I don't understand how the above script output the above string as there's only one line,

echo "Ditt lösenord är ".$pass."!"; in the else condition. Are you sure that you are debugging the right file?

PS: You need to fetch the values from mysql result set, returned by mysql_query().
Check http://php.net/mysql_query and http://php.net/mysql_fetch_assoc

I've checked your site and you've an error in the query. Check the output of

echo $sql = "SELECT * FROM users WHERE email='$email' AND name='$name' AND code='$code' AND
user='$user' AND pass='$pass'";

You don't need AND pass='$pass' there as there's no way of getting it from user.

byllan
04-28-2012, 09:34 AM
Im noob in php and need my script done i was read that you post but don't understand that! but this i understand with pass and that im done so fair right now!


<b>Forgot Password</b>
<?php
if (isset($_POST['submit'])){
$user = $_POST['user'];
$email = $_POST['email'];
$name = $_POST['name'];
$code = $_POST['code'];
$pass = $_POST['pass'];
$sql = "SELECT * FROM users WHERE email='$email' AND name='$name' AND code='$code' AND
user='$user'";
if(!mysql_query($sql))
{
echo "Något är fel! ".mysql_error();
}
else
{
echo "Ditt lösenord är ".$pass."!";
}}
?>
<html>
<body>
<tr>
<form action="?p=lostpassword" method="post">
<td><br>Username:<br></td>
<td><input type="text" input type="text" name="user" value=""></td>
</tr>
<tr>
<td><br>Mail:<br></td>
<td><input type="text" name="email" value=""></td>
</tr>
<tr>
<td><br>Name:<br></td>
<td><input type="text" name="name" value=""></td>
</tr>
<tr>
<td><br>Secret Code:<br></td>
<td><input type="text" name="code" value=""></td>
</tr>
<tr>
<td>
<tr>
<br>
<input type="submit" name="submit" value="Get Password">
</td>
</tr>

</table>
</form>
<br>
<br>
</html>
</body>

Error

Notice: Undefined index: pass in C:\xampp\htdocs\pages\lostpassword.php on line 8
Ditt lösenord är !

abduraooft
04-28-2012, 09:39 AM
Add an echo before $sql, like

echo $sql = "SELECT * FROM users WHERE email='$email' AND name='$name' AND code='$code' AND
user='$user'"; and post the output

byllan
04-28-2012, 09:42 AM
Now i got this

error
Notice: Undefined index: pass in C:\xampp\htdocs\pages\lostpassword.php on line 8
SELECT * FROM users WHERE email='' AND name='' AND code='' AND user=''Ditt lösenord är !

abduraooft
04-28-2012, 10:01 AM
if(!mysql_query($sql))
{
echo "Något är fel! ".mysql_error();
}
else
{
echo "Ditt lösenord är ".$pass."!";
}
Chang the above to

$result=mysql_query($sql);
if(!$result)
{
echo "Något är fel! ".mysql_error();
}
else
{
if(mysql_num_rows($result)){
$row=mysql_fetch_assoc($result);
echo "Ditt lösenord är ".$row['pass'];
}
else{
echo "No matches found for the given input"
}
}

firepages
04-28-2012, 02:18 PM
the error suggests simply that $_POST['pass'] does not exist e.g. the form sending to this page does not have a form field named 'pass' ..



<input type="text" name="pass" .... etc


does it ? and what use is it to you in this page anyway ?

byllan
04-29-2012, 02:05 AM
fixed thanks !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum