why is this error coming

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

why is this error coming

Post by rami »

i have just started php and i have successfully modified(coded) register page but when i try login page it gives error

Notice: Undefined index: user_id in c:\program files\easyphp1-8\www\html\login.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\html\login.php:37) in c:\program files\easyphp1-8\www\html\login.php on line 37

what is the error
user_id is primary key .Does it need to be index ...as i have forgetten it to make index will
create index....command work...
i tried but it didnt.

and next line erro i have read some where that before header the data should not be sent to browser how can i solve this problem.

Code: Select all

<?php 
ob_start(); 
//require_once ('includes/config.inc'); 
  $page_title = 'Login'; 
if (isset($_POST['submit'])) { 
     require_once ('../mysql_connect1.php'); 
                     if (empty($_POST['username'])) { 
                   $u = FALSE; 


                  echo '<p><font color="red" size="+1">You forgot to enter your 

                username!</font></p>'; 
} else { 
$u = escape_data($_POST['username']); 
} 

    if (empty($_POST['password'])) { 
    $p = FALSE; 
    echo '<p><font color="red" size="+1">You forgot to enter your 

    password!</font></p>'; 
     } else { 
    $p = escape_data($_POST['password']); 
    } 

if ($u && $p) { // If everything's OK. 

// Query the database. 


$query = "SELECT user_id,name FROM students WHERE username='$u' AND password=PASSWORD('$p')"; 
$result = @mysql_query ($query); 
$row = mysql_fetch_array ($result, MYSQL_NUM); 

if ($row) { 

   $_SESSION['name'] = $row[1]; 
   $_SESSION['user_id'] = $row[0]; 
   ob_end_clean(); 
     header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/view.php?uid={$row['user_id']}"); 
exit(); 



    } else { // No match was made. 
echo '<p><font color="red" size="+1">The username and password entered do 
not match those on file.</font></p>'; 
} 


mysql_close(); 

} else { 
echo '<p><font color="red" size="+1">Please try again.</font></p>'; 
} 

} 
?> 
<h1>Login</h1> 
<p>Your browser must allow cookies in order to login.</p> 
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<fieldset> 
<p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if 

(isset($_POST['username'])) echo $_POST['username']; ?>" /></p> 
<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p> 
<div align="center"><input type="submit" name="submit" value="Login" /></div> 
</form><!-- End of Form -->

in second linked page from login
error is
Parse error: parse error, expecting `','' or `';'' in c:\program files\easyphp1-8\www\html\view.php on line 37
if i make line 37 as remarks
than
error
Parse error: parse error, expecting `','' or `';'' in c:\program files\easyphp1-8\www\html\view.php on line 23

complete code
view.php

Code: Select all

<?php. 
require_once ('includes/config.inc'); 
require_once ('../mysql_connect1.php'); 
$page_title = 'view'; 
if (!isset($_SESSION['first_name'])) { 

              header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/login.php"); 
           exit(); 
           
} else { 

if (isset($_GET['uid'])) { 
$query = "SELECT * FROM students WHERE user_id = {$_GET['uid']}"; 
$result=@mysql_query($query); 
              if (mysql_affected_rows()==1) 
                { 
                   echo 'Name{$row[‘name’]}<br>'; 
                   echo 'Email{$row[‘email’]}<br>'; 
                   echo 'Address{$row[‘address’]}<br>'; 
                   echo 'phone{$row[‘phone’]}<br>'; 
                   echo "<a href=\"results.php?uid1={$row['user_id']}\">results</a>";
                             } 
                                   else
               { 
                 echo ‘No such records’; 
                 } 
} 

else 
{ 
echo ‘system error’; 
} 
} 
mysql_close(); 
?>
please help .......
by the way how to get those codes in to the scroll box while posting .I Used code bbcode but didnt help...
its long agian...
any way please help about that php
thanks
rami
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Take out the MYSQL_NUM clause on the mysql_fetch_array() function call.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

For your first error take a look at this:

http://us2.php.net/manual/en/ref.errorf ... lay-errors

For your second error

use single or double quotes not hashes `

Code: Select all

echo ‘system error’;
Should be:

Code: Select all

echo 'system error';
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

Post by rami »

Jenk wrote:Take out the MYSQL_NUM clause on the mysql_fetch_array() function call.
u really are developer i took out that mysql_num all error gone really nice
if i had gone to that link may be it would have taken me lots of time

by the way now its says
Forbidden
You don't have permission to access /html"view.php on this server.
--------------------------------------------------------------------------------

Apache/1.3.33 Server at localhost Port 80

how can i solve it developer.....

another problem is also quite solved.
thanks for your replies.
thanks
rami
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

That's a configuration setting in your Apache server httpd.conf file, or the .htaccess file.

I can't remember the lines that need changing, or what they should be, but it is probably the webserver denying you access to either the folder or the file extension :)
Post Reply