Computing.Net > Forums > Web Development > Help with mysql and php?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with mysql and php?

Reply to Message Icon

Name: Airun
Date: April 7, 2009 at 06:10:52 Pacific
OS: Windows XP
Subcategory: PHP
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Airun
Date: April 7, 2009 at 06:19:28 Pacific
Reply:

Sorry forgot to mention I'm using php5.2, mysql 5.1, and appache 2,2.


0

Response Number 2
Name: shutat
Date: April 7, 2009 at 12:20:00 Pacific
Reply:

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


0

Response Number 3
Name: Airun
Date: April 8, 2009 at 05:16:20 Pacific
Reply:

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?


0

Response Number 4
Name: Airun
Date: April 8, 2009 at 05:31:55 Pacific
Reply:

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


0

Response Number 5
Name: shutat
Date: April 8, 2009 at 13:07:42 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Airun
Date: April 9, 2009 at 10:37:43 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Help with mysql and php?

MySQL and PHP problems www.computing.net/answers/webdevel/mysql-and-php-problems/941.html

MySQL and PHP question www.computing.net/answers/webdevel/mysql-and-php-question/981.html

cannot work with mysql using php www.computing.net/answers/webdevel/cannot-work-with-mysql-using-php/4294.html