Guest User

Untitled

a guest
Sep 9th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. PHP HELP- i cant seem to get them to work?
  2. verify.php is meant to call users.php which it does but when asking it to call the database and compare the $_SESSION['company'] with the variable 'name' an error pops up . Here is the line with the error
  3.  
  4. $result = mysql_query('SELECT * FROM profile WHERE name like $_SESSION['company']');
  5.  
  6. . here are the two scripts.
  7.  
  8.  
  9. verify.php
  10.  
  11. <?php
  12. if(isset($_POST['submit'])){
  13. $dbHost = "localhost"; //Location Of Database usually its localhost
  14. $dbUser = "root"; //Database User Name
  15. $dbDatabase = "test"; //Database Name
  16.  
  17. $db = mysql_connect($dbHost,$dbUser)or die("Error connecting to database.");
  18.  
  19. mysql_select_db($dbDatabase, $db)or die("Couldn't select the database.");
  20.  
  21. $user = mysql_real_escape_string($_POST['usernam…
  22. $password = mysql_real_escape_string($_POST['passwor…
  23.  
  24. $sql = mysql_query("SELECT company,password,salt
  25. FROM company
  26. WHERE username='$user'
  27. LIMIT 1");
  28.  
  29.  
  30. if(mysql_num_rows($sql) == 1){
  31. $row = mysql_fetch_array($sql);
  32. $userData = mysql_fetch_array($row, MYSQL_ASSOC);
  33. $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
  34. session_start();
  35. $_SESSION['username'] = $row['username'];
  36. $_SESSION['company'] = $row['company'];
  37. $_SESSION['logged'] = TRUE;
  38. header("Location: users.php");
  39. exit;
  40. }else{
  41. header("Location: log_error.php");
  42. exit;
  43. }
  44. }else{
  45. header("Location: log_error.php");
  46. exit;
  47. }
  48.  
  49. ?>
  50.  
  51.  
  52.  
  53.  
  54. users.php
  55.  
  56.  
  57. <style type="text/css">
  58. <!--
  59. body {
  60. background-color: #009901;
  61. }
  62. -->
  63. </style><?php
  64. session_start();
  65. if(!$_SESSION['logged']){
  66. header("Location: login.php");
  67. exit;
  68. }
  69. echo '<h2>Welcome, '.$_SESSION['company'].' </h2>';
  70.  
  71. $con = mysql_connect("localhost","root");
  72. if (!$con)
  73. {
  74. die('Could not connect: ' . mysql_error());
  75. }
  76.  
  77. mysql_select_db("test", $con);
  78. $result = mysql_query('SELECT * FROM profile WHERE name like $_SESSION['company']');
  79. if($result==true){
  80. echo "<dl>";
  81. while($row=mysql_fetch_array($result))
  82. {
  83. echo "<dt> Address:</dt>";
  84. echo "<dd>" . $row['address'] . "</dd>";
  85. echo "<dt> Phone Number:</dt>";
  86. echo "<dd>" . $row['phoneno'] . "</dd>";
  87. echo "<dt> Company Profile<br>:</dt>";
  88. echo "<dd>" . $row['notes'] . "</dd>";
  89. }
  90. echo "</dl>";
  91. }
  92. else{
  93. echo 'invalid query:'.mysql_error();
  94. }
  95.  
  96. mysql_close($con);
  97. ?>
Add Comment
Please, Sign In to add comment