Extracting from a database.

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Alright I have this script that I'm making from another one of my scripts. But this one won't work for some reason. It wont extrack row 'rank'

PHP Code: [ Select ]
 
//header
 
require("db_info.php");
 
  $dbnews = @mysql_connect("$host", "$db_user", "$db_password");  
 
  if (!$dbnews) {
 
   
 
    echo( "<p>Unable to connect to the " .          
 
     "database server at this time.</p>"
 
    );    
 
    exit();  
 
 
 
  }  
 
 
 
  // Select the database
 
     
 
  if (! @mysql_select_db("$db_name") ) {    
 
 
 
    echo( "<p>Unable to locate the database " .          
 
     "at this time.</p>"
 
    );    
 
    exit();  
 
 
 
  }
 
 
 
 
 
  $result = @mysql_query("SELECT * FROM members WHERE username = '$user'");
 
  $row = mysql_fetch_array($result);
 
  extract($row);
 
 
 
$rank = $row[rank];
 
$email = $row[email];
 
$aim = $row[aim];
 
$steam_id = $row[steam_id];
 
$quote = $row<div class="quoteHeader"><strong>Quote</strong>:</div><div class="quoteBody">;
$recruiter = $row[recruiter];
$recruited_on = $row[recruited_on];
 
//functions
function DisConsole() {
 
if($rank == 0) {
echo("
We are sorry but you have not loged into the site.
");
}
 
if($rank == 1) {
echo("
<table width='330' border='1' cellpadding='0' cellspacing='0' bordercolor='#666666'>
  <tr>
    <td colspan='2' align='center'><strong>] Welcome To Your Console
      [</strong></td>
  </tr>
  <tr>
    <td width='173' align='center'>Username:</td>
    <td width='151' align='center'>$username</td>
........
 
//console.php
if(!$user) {
   $user = $usercook;
   $pass = $passcook;
}
setcookie("usercook", "$user");
setcookie("passcook", "$pass");
 
require("functions.php");
include("header.php");
 
DisConsole();
 
//not sure if you need this
//login.php
require("db_info.php");
  $dbnews = @mysql_connect("$host", "$db_user", "$db_password");
  @mysql_select_db("$db_name")
?>
<?php
$user = ($_POST[user]);
$pass = ($_POST[pass]);
$checkuser = mysql_query("SELECT * FROM members WHERE username = '$user' and password = '$pass'");
if(mysql_num_rows($checkuser) <1) {
     $output = "You have entered an invalid password/username.<br>
        <form action='login.php' method='post'>
<input name='user' type='text'>
<input name='pass' type='password'>
<input type=submit value=Login>
</form>";
} else {
     $output = "You have been successfully logged in.<br><a href='console.php'>Click here to go to your console</a>";
     }
     
setcookie("usercook", "$user", time()+3600, "/");  //line 20
setcookie("passcook", "$pass", time()+3600, "/"); //line 21
 
      echo $output;  
 
  1.  
  2. //header
  3.  
  4. require("db_info.php");
  5.  
  6.   $dbnews = @mysql_connect("$host", "$db_user", "$db_password");  
  7.  
  8.   if (!$dbnews) {
  9.  
  10.    
  11.  
  12.     echo( "<p>Unable to connect to the " .          
  13.  
  14.      "database server at this time.</p>"
  15.  
  16.     );    
  17.  
  18.     exit();  
  19.  
  20.  
  21.  
  22.   }  
  23.  
  24.  
  25.  
  26.   // Select the database
  27.  
  28.      
  29.  
  30.   if (! @mysql_select_db("$db_name") ) {    
  31.  
  32.  
  33.  
  34.     echo( "<p>Unable to locate the database " .          
  35.  
  36.      "at this time.</p>"
  37.  
  38.     );    
  39.  
  40.     exit();  
  41.  
  42.  
  43.  
  44.   }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.   $result = @mysql_query("SELECT * FROM members WHERE username = '$user'");
  51.  
  52.   $row = mysql_fetch_array($result);
  53.  
  54.   extract($row);
  55.  
  56.  
  57.  
  58. $rank = $row[rank];
  59.  
  60. $email = $row[email];
  61.  
  62. $aim = $row[aim];
  63.  
  64. $steam_id = $row[steam_id];
  65.  
  66. $quote = $row<div class="quoteHeader"><strong>Quote</strong>:</div><div class="quoteBody">;
  67. $recruiter = $row[recruiter];
  68. $recruited_on = $row[recruited_on];
  69.  
  70. //functions
  71. function DisConsole() {
  72.  
  73. if($rank == 0) {
  74. echo("
  75. We are sorry but you have not loged into the site.
  76. ");
  77. }
  78.  
  79. if($rank == 1) {
  80. echo("
  81. <table width='330' border='1' cellpadding='0' cellspacing='0' bordercolor='#666666'>
  82.   <tr>
  83.     <td colspan='2' align='center'><strong>] Welcome To Your Console
  84.       [</strong></td>
  85.   </tr>
  86.   <tr>
  87.     <td width='173' align='center'>Username:</td>
  88.     <td width='151' align='center'>$username</td>
  89. ........
  90.  
  91. //console.php
  92. if(!$user) {
  93.    $user = $usercook;
  94.    $pass = $passcook;
  95. }
  96. setcookie("usercook", "$user");
  97. setcookie("passcook", "$pass");
  98.  
  99. require("functions.php");
  100. include("header.php");
  101.  
  102. DisConsole();
  103.  
  104. //not sure if you need this
  105. //login.php
  106. require("db_info.php");
  107.   $dbnews = @mysql_connect("$host", "$db_user", "$db_password");
  108.   @mysql_select_db("$db_name")
  109. ?>
  110. <?php
  111. $user = ($_POST[user]);
  112. $pass = ($_POST[pass]);
  113. $checkuser = mysql_query("SELECT * FROM members WHERE username = '$user' and password = '$pass'");
  114. if(mysql_num_rows($checkuser) <1) {
  115.      $output = "You have entered an invalid password/username.<br>
  116.         <form action='login.php' method='post'>
  117. <input name='user' type='text'>
  118. <input name='pass' type='password'>
  119. <input type=submit value=Login>
  120. </form>";
  121. } else {
  122.      $output = "You have been successfully logged in.<br><a href='console.php'>Click here to go to your console</a>";
  123.      }
  124.      
  125. setcookie("usercook", "$user", time()+3600, "/");  //line 20
  126. setcookie("passcook", "$pass", time()+3600, "/"); //line 21
  127.  
  128.       echo $output;  
  129.  

Now when I log in and go to the console, I get

Quote:
We are sorry but you have not loged into the site.


Only reason I could see for the reason would be that non of the informations is being extracked, but I dont know why that is.

Help please.[/url]
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

This is what the sql section of the page should look like (after your select statement)
PHP Code: [ Select ]
 
 if ($row = mysql_fetch_array($result)) {
 
     $rank = $row['rank'];
 
    $email = $row['email'];
 
    $aim = $row['aim'];
 
    $steam_id = $row['steam_id'];
 
    $quote = $row['quote'];
 
    $recruiter = $row['recruiter'];
 
    $recruited_on = $row['recruited_on'];
 
  }else{
 
   echo "error extracting record - please check your username";
 
  }
 
 
  1.  
  2.  if ($row = mysql_fetch_array($result)) {
  3.  
  4.      $rank = $row['rank'];
  5.  
  6.     $email = $row['email'];
  7.  
  8.     $aim = $row['aim'];
  9.  
  10.     $steam_id = $row['steam_id'];
  11.  
  12.     $quote = $row['quote'];
  13.  
  14.     $recruiter = $row['recruiter'];
  15.  
  16.     $recruited_on = $row['recruited_on'];
  17.  
  18.   }else{
  19.  
  20.    echo "error extracting record - please check your username";
  21.  
  22.   }
  23.  
  24.  


remove the @ symbol in fornt of mysql_query for now - you might get a useful error message
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Well Rabid Dog that didn't fix it. Im not getting the error message you put in but i am still getting the "We are sorry but you have not loged into the site."
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

how is the variable $user getting set?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

PHP Code: [ Select ]
if(!$user) {
 
   $user = $usercook;
 
   $pass = $passcook;
 
}
 
setcookie("usercook", "$user");
 
setcookie("passcook", "$pass");
 
 
  1. if(!$user) {
  2.  
  3.    $user = $usercook;
  4.  
  5.    $pass = $passcook;
  6.  
  7. }
  8.  
  9. setcookie("usercook", "$user");
  10.  
  11. setcookie("passcook", "$pass");
  12.  
  13.  


its being set from the login page

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.