Web Design Forums

Database Systems Help

Discussion and help on database systems such as MySQL, MSSql, SQLite, PostgreSQL

Mysql Data Retrieval



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old April 11 '09, 10:14 PM (#1)
teknicalissue is offline
New Member!
 
teknicalissue's Avatar
 
Join Date: November 2008
Posts: 13
teknicalissue is an unknown quantity at this point
Mysql Data Retrieval

hey guys, i have a quick question... im trying to get into databasing with php and wrote this piece of code

PHP Code:
<?php
//set variables
$user $_POST[UserName];

$pass $_POST[Password];

$flag 0;

//checks if variables are set and passed correctly
echo "$user " $pass;

// Begins mysql connection
$con mysql_connect("localhost","root","polerty");
if (!
$con) { //if could not connect
    
die ("Connection Error: " mysql_error());//kill script and display error   
} else { //if connection succesful, display connection succesful
    
echo "<br>connection successful";    
}


mysql_select_db("users",$con); // Selects the Database we're working with and connects using var con

$results mysql_query("SELECT Usernames FROM members"); //sets var results to the mysql query command
                                                                                                                          
/* the while loop continues while it is set true (while there are rows to fetch) the rows get set to 
an array called var users and can be called by the name of array and the name of the column/index 
ie. (array[columnName])  */
while($users mysql_fetch_array($results))
{
    
//if the var user (the users input) equals the fetched array (the stored information)
    
if ($user == $users['Usernames'])
    {   
     
$flag=1;//then set the flag to one   
    
}
}
    
// if the flag is set to 1, then display error message along with the form
if ($flag == 1){
    echo 
"Username already taken <br>";
    include(
"index.html");
//if its not set to 1, then store the users input into the database    
} else {
    
//if theres an error while trying to add the username and password to the database, then display it
    
if(!mysql_query("INSERT INTO members (Usernames, Passwords) VALUES ('$user','$pass')"))
    echo 
mysql_error();
    
}

mysql_close($con); // close mysql connection
?>
i know its long im sry.. im new to this and i don't know which parts you guys need to see but i was looking around and stumbled on this piece of code

PHP Code:
$result=mysql_query("select * from users  
  where username='" 
$_SESSION['username'] . "' and password='" $_SESSION['password'] . "'"); 

// retrieve number of rows resulted 
$num=mysql_num_rows($result);  

// print login form and exit if failed. 
if($num 1){ 
  echo 
"You are not authenticated.  Please login.<br><br> 
   
  <form method=POST action=index.php> 
  username: <input type=text name=\"username\"> 
  password: <input type=password name=\"password\"> 
  <input type=submit> 
  </form>"

   
  exit; 

my question is, which script would be more efficient? the one that checks the tables to see if its in the listing or the one that uses the mysql check. any pros and cons?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 3 '09, 11:42 AM (#2)
imagn is offline
WDF Regular
 
imagn's Avatar
 
Join Date: July 2007
Location: Los Angeles
Posts: 156
imagn will become famous soon enough
I'm confused... are you trying to validate against records with duplicate usernames or authenticate a login...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » Database Systems Help

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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
Export data from mysql to word Anant Database Systems Help 4 April 8 '07 01:18 AM
mysql data move from 3 to 5 toadeny Database Systems Help 5 July 7 '06 07:30 AM
Problem Inserting MySQL Data mikaelsnavy Database Systems Help 8 September 21 '05 04:11 AM
Simple data entry from for mysql database Karl-hsj Database Systems Help 6 June 7 '04 03:59 AM

 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



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


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164