| | |
retrieving data from MySQL
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 22
Reputation:
Solved Threads: 0
hi for all the expert here, i am now facing a minor problem on retrieving data here. MySQL do contain all the variables defined with data inside it. However, i juz need to know how to loop through the array to get all the data in a row?
Below is the php code i used:
especially at the function, i dunnoe why i can see the Thanks for login even no username entered. Can anyone help? By the way, php redirect cannot use more than once? Thanks for help....
Below is the php code i used:
PHP Syntax (Toggle Plain Text)
<?php mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("userlist") or die(mysql_error()); //session_start(); $query = "SELECT * FROM user"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); if($_POST['name'] == $row['username']) { echo "Thanks for logging in."; header("http://www.google.com"); } else { echo "Sorry, your username and password does not match."; //header("http://www.yahoo.com"); } $_SESSION['name']=$_POST['name']; $_SESSION['password']=$_POST['password']; $_SESSION['status']=$_POST['status']; ?>
Last edited by eparse; Mar 17th, 2008 at 9:23 am.
Instead of
will give you an error because you can't output anything before header function. Either echo a message or redirect the user.
$row = mysql_fetch_array($result) use, while($row = mysql_fetch_array($result)) { AND•
•
•
•
echo "Thanks for logging in.";
header("http://www.google.com");
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Mar 2008
Posts: 22
Reputation:
Solved Threads: 0
thanks for the solution, however i still facing the problem using while loop...
it keeps showing this on the page:
Sorry! Wrong name!!Sorry! Wrong name!!Sorry! Wrong name!!
when i use while loop..
below is the modified code:
and it only manage to get the 1st row of the data...any silly mistakes i'd done?
it keeps showing this on the page:
Sorry! Wrong name!!Sorry! Wrong name!!Sorry! Wrong name!!
when i use while loop..
below is the modified code:
PHP Syntax (Toggle Plain Text)
<?php mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("userlist") or die(mysql_error()); $query = "SELECT * FROM user"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ($_POST['name']==$row['username'] && $_POST['password']==$row['password']) { echo "Login successfully!!!"; } else { echo "Sorry! Wrong name!!"; } } $name=$_POST['name']; $password=$_POST['password']; $status=$_POST['status']; ?>
and it only manage to get the 1st row of the data...any silly mistakes i'd done?
Last edited by eparse; Mar 17th, 2008 at 11:20 am.
When the user types username and password, why not check if that exists in the table, rather than get all records and then check ?
Then check if this returns more than 1 row. If it does, then the username and password is valid. Else, invalid username and pass.
php Syntax (Toggle Plain Text)
$name=$_POST['username']; $password=$_POST['password']; Ie., $query = "select * from user where username='$name' and password='$password'";
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
It displays thrice because its looping three times. You can do it this way.
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("userlist") or die(mysql_error()); $name=$_POST['name']; $password=$_POST['password']; $query = "SELECT * FROM user where username='$name' && password='$password'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0){ echo "Success!"; } else { echo "Sorry! Wrong name!!"; } ?>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Yeah..possible.. check this link ! http://www.tizag.com/javascriptT/javascriptredirect.php
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- retrieving a single cell of data from a MySQL database (PHP)
- Help with data grid please (VB.NET)
- problem with entering data in datagrid (VB.NET)
- Need help to finish datagrid problem (VB.NET)
- need help in mysql query.... (PHP)
- PHP newbie, project feasibility (PHP)
Other Threads in the PHP Forum
- Previous Thread: displaying images
- Next Thread: Generate static html page
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date development directory display download dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql structure syntax system table thesishelp tutorial update upload url validation validator variable video web xml youtube






