Jump to content

Please help!


Sparrow

Recommended Posts

Hello everyone,

 

Okay I am trying to create a login area for my website.  So I set up the login form the user info database and the validate.php.  However I keep on having errors in my validiate.php when I test it out.  I get past some but this one I can't get past. 

 

Here is the error:Parse error: syntax error, unexpected T_ELSE in /home/unitedai/public_html/validate.php on line 32

 

here is the php script

 

10<?php

11      session_start();

12      $db_user = ******;

13      $db_pass = *******;

14      $user_name = $_POST['user_name'];

15      $password = $_POST['password'];

16     

17      //connect to the DB and select the "dictator" database

18      $connection = mysql_connect('localhost', $db_user, $db_pass) or

19die(mysql_error());

20      mysql_select_db('dictators', $connection) or die(mysql_error());

21

22      //set up the query

23      $query = "SELECT * FROM users

24                      WHERE user_name='$user_name' AND password='$password'";

25      //run the query and get the number of affected rows

26      $result = mysql_query($query, $connection) or die('error making query');

27      $affected_rows = mysql_num_rows($result);

28      //if there's exactly one result, the user is validated. Otherwise, he's

29invalid;

30      if($affected_rows == 1);

31      {print 'validated';

32      else{print 'not valid';

33?>

 

Note: Nubers on side are just for reference  ;).  They are not part of the code.

 

Link to comment
https://forums.phpfreaks.com/topic/115357-please-help/
Share on other sites

Okay thank you guys.  That error is gone now, but now I have a new one:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/unitedai/public_html/validate.php:6) in /home/unitedai/public_html/validate.php on line 7

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/unitedai/public_html/validate.php:6) in /home/unitedai/public_html/validate.php on line 7

Access denied for user 'unitedai_uniteda'@'localhost' to database 'dictators'

 

 

Here is the full php doc:

 

<html>

<head>

<title>validate.php</title>

</head>

<body>

<?php     

      session_start();

      $db_user = ****;

      $db_pass = ****;

      $user_name = $_POST['user_name'];

      $password = $_POST['password'];

     

      //connect to the DB and select the "dictator" database

      $connection = mysql_connect('localhost', $db_user, $db_pass) or

die(mysql_error());

      mysql_select_db('dictators', $connection) or die(mysql_error());

 

      //set up the query

      $query = "SELECT * FROM users

                      WHERE user_name='$user_name' AND password='$password'";

      //run the query and get the number of affected rows

      $result = mysql_query($query, $connection) or die('error making query');

      $affected_rows = mysql_num_rows($result);

      //if there's exactly one result, the user is validated. Otherwise, he's

invalid;

      if($affected_rows == 1)

      {print 'validated';}

      else{print 'not valid';}

      $user_name = $_POST['user_name'];

      $password = $_POST['password'];

?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/115357-please-help/#findComment-593390
Share on other sites

session_start() should always be at the top of the page, before any output and whitespace.

 

Try this:

<?php
session_start();
?>
<html>
<head>
<title>validate.php</title>
</head>
<body>
<?php       
      $db_user = ****;
      $db_pass = ****;
      $user_name = $_POST['user_name'];
      $password = $_POST['password'];
      
      //connect to the DB and select the "dictator" database
      $connection = mysql_connect('localhost', $db_user, $db_pass) or
die(mysql_error());
      mysql_select_db('dictators', $connection) or die(mysql_error());

      //set up the query
      $query = "SELECT * FROM users
                     WHERE user_name='$user_name' AND password='$password'";
      //run the query and get the number of affected rows
      $result = mysql_query($query, $connection) or die('error making query');
      $affected_rows = mysql_num_rows($result);
      //if there's exactly one result, the user is validated. Otherwise, he's
invalid;
      if($affected_rows == 1)
      {print 'validated';}
      else{print 'not valid';}
      $user_name = $_POST['user_name'];
      $password = $_POST['password'];
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/115357-please-help/#findComment-593394
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.