iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2008, 12:36 PM
brentjlaf's Avatar
WebProWorld Member
 
Join Date: Apr 2007
Location: canada
Posts: 40
brentjlaf RepRank 1
Default Retrieve Username Help

Can't seem to find the bug in here



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

// value sent from form
$email_to=$_POST['email_to'];


// retrieve password from table where e-mail = $email_to(email@home.com)
$sql="SELECT username FROM proteam WHERE email='$email_to'";
$result=mysql_query($sql);

// if found this e-mail address, row must be 1 row
// keep value in variable name "$count"
$count=mysql_num_rows($result);

// compare if $count =1 row
if($count==1){

$rows=mysql_fetch_array($result);

// keep password in $your_password
$your_password=$rows['username'];

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email_to;

// Your subject
$subject="Your username here";

// From
$header="from: your name <info@silvercup.ca>";

// Your message
$messages= "Your username for login to our website \r\n";
$messages.="Your username is $your_password \r\n";
$messages.="more message... \r\n";

// send email
$sentmail = mail($to,$subject,$messages,$header);

}

// else if $count not equal 1
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your username Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send username to your e-mail address";
}
__________________
http://www.tnerb.com
Reply With Quote
  #2 (permalink)  
Old 09-05-2008, 02:22 PM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 255
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Retrieve Username Help

The first problem is that you are not using mysql_real_escape_string() to escape your input before using it in a query.

The second problem is that your script will fail if there are two entries for the e-mail address in the database.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My site is now on first page of results ... for my username! bathrobe Google Discussion Forum 6 12-17-2006 02:47 AM
Controlled access (using username and password field) Help illfoundedmind Web Programming Discussion Forum 2 07-08-2005 08:05 PM
ASP.Net retrieve records from Access DB that start with A Adamwlad Database Discussion Forum 2 12-15-2004 06:21 PM


All times are GMT -4. The time now is 11:11 PM.



Search Engine Optimization by vBSEO 3.3.0