Help with mysql and php?

April 7, 2009 at 06:10:52
Specs: Windows XP
First off hello,

Ok, I’m new to mysql and php. I’m trying to create a registration form. I already have it to where the use can submit information. But I would like a way that they could review that information from my mysql database. I created a simple one to test. The database has 4 fields in it, first_name, last_name, email, and pass. I know there has to be a way that I can let the user type in there email and password and view just there information, not every ones. I have tried many different things and failed many times. Any help would be appreciated.

Thanks
Aaron


See More: Help with mysql and php?

Report •


#1
April 7, 2009 at 06:19:28
Sorry forgot to mention I'm using php5.2, mysql 5.1, and appache 2,2.

Report •

#2
April 7, 2009 at 12:20:00
As a basic test, how about

$res = mysql_query("select * from tbl_name where
email='" . $_POST["email"] . "' and pass='" .
$_POST["pass"] . "' limit 1;") or
die(mysql_error());

if(mysql_num_rows($res) == 1) {
   while($row = mysql_fetch_assoc($res)) {
      foreach($row as $key => $val) {
          echo $key . " = " . $val . "<br>";
      }
   }
}

You'd need to check the $_POST vars for valid input first and such, but hopefully, the above will work for you.

HTH


Report •

#3
April 8, 2009 at 05:16:20
Im getting these error messages:

Notice: Undefined index: email in C:\wamp\www\lookatme.php on line 16

Notice: Undefined index: pass in C:\wamp\www\lookatme.php on line 17

email and pass are the variables of my text boxes from the form. Thats what goes after post right?

Heres the HTML code for my form:

<h2>View Registration info</h2>
<FORM ACTION="view.php" METHOD="get" NAME="contact_form">
<TABLE>
<TR>
<TD>Email:</TD>
<TD> <input name="email" type=text id="email" size="30" maxlength="20"></TD>
</TR>
<TR>
<TD>Password:</TD>
<TD><input type=password name="pass" id="pass"></TD>
</TR>
<TR>
<TD><input type="submit" value="Go" name="view" id="view"></TD>
<TD><input type="reset" value="Reset" name="Reset"></TD>
</TR>
</TABLE>
</FORM>

So, after $_POST you had it right. I just leave them email and pass right?


Report •

Related Solutions

#4
April 8, 2009 at 05:31:55
Thanks for your help, shutat.
I'm slow but I figured it out now!
I really appreciate you taking the time to help me.


again, Thanks
Airun


Report •

#5
April 8, 2009 at 13:07:42
Hello; I didn't realize you were using the get method. If you're able to use the post method, then I strongly encourage you to use it instead. With get, anything visitors submit appears as a query string upon submission, shows up in server logs, and can be cached.

If you have to use get, change $_POST to $_GET["email"] and $_GET["pass"]. $_GET itself is usually set when you submit something, so you'd want to check your vars for being empty.

<?php

   if(!empty($_GET["email"]) && !empty($_GET["pass"])) {
       // check the database
   } else {
?>
put form code here
<?php
}?>

Hope that helps.


Report •

#6
April 9, 2009 at 10:37:43
Awesome!!!
That did it!
And your way so much more simpler than the other way my friend try to show me.
Thank a bundle.
I really appreciate it.

thank you
Airun


Report •


Ask Question