Need assist with Code

Hi,
i am trying to Edit some one elses code and trying to put my code in .
but having problem. if any one can help me please
Code for Home.php
 
<?php include('connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
session_start();
include('menu.inc.php');
 
 
 
// session start
 
//Hold session for username and password
$username = $_POST['username'] ;
$password = $_POST['password'] ;
 
// bellow 2 files quires for database connection and functions 
require("config.php");
require("functions.php");
 
// Connecting to database and table
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
 
// if user click on submit button , check the conditions
 
if($_POST['submit'])
 
{
     // bellow code will select , selective username and password for the correct user 
	$sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";
      
	  $result = mysql_query($sql);
	  $numrows = mysql_num_rows($result);
        
		
		if($numrows == 1) // if query gets any record 
		{	
			$row = mysql_fetch_assoc($result);
		   
			session_register("USERNAME"); // register the session for username
			$_SESSION['USERNAME'] = $row['username']; // register the password
								
		    header('Location: index.php'); // go to indexpage
					
		}
		else 
		{
			header("Location: " . $config_basedir . "/login.php?error=1");
		}
 
}
else
{
 
	
 
	echo "<h2>User Login</h2>";
		
	if($_GET['error']) 
		{
			echo "Incorrect login, please try again!";
		}
 
?>
 
<div id="content">
 
<!-- Bellow code is to create html base form to get username and password  -->
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
 
<table>
<tr>
	<td>Username</td>
	<td><input type="text" name="username"></td>
</tr>
<tr>
	<td>Password</td>
	<td><input type="password" name="password"></td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
 
<?php
}
 
?>
 
</div>
<br />
<div id="footer">&copy;<?=date("Y");?> Calyx Group</div>
 
</div>
</body>
</html>
 
******************************************************
Code for menu.inc
 
 
<img id="frontphoto" src="images/tagline2.jpg" width="760"  alt="electronic repair solutions for industry, service and consumers" />
<div id="menu">
<h2 class="hide">Menu:</h2>
	<ul>
		<li><a href="home.php">Home</a></li>
		<!--<li><a href="aboutus.php">About Us</a></li>-->
		<li><a href="whyrepair.php">Why Repair?</a></li>
		<?php
		$result=@mysql_query("SELECT * from categories where cat_Status =1",$db);
		while($row = @mysql_fetch_array($result))
			{
				$cid = $row['catid'];
				$cName = $row['cat_Name'];
				$pcat = $row['parent_Cat'];
				$cDesc = $row['cat_Desc'];
				if ($pcat == 0)
				{
				?>
				<li><a href="showCategories.php?CID=<?=$row['catid'];?>"><?=$cName;?></a></li>
				<?
				}
			}
		?>
	<!--	<li><a href="faqs.php">FAQs</a></li> -->
		<li><a href="ourclients.php">Our Clients</a></li>
		<li><a href="contactus.php">Contact Us</a></li>
		<li><a href="companies.php">Our Other Companies</a></li>
		<li><a href="sitemap.php">Site Map</a></li>
	</ul>
<table align="center">
<tr><td>
<img id="services" src="images/leftimage.jpg" alt="electroversal services" width="160px"/>
</td></tr>
</table>
<!-- <table align="center">
 
<tr><td><img id="scopeimage" src="images/scope.jpg" alt="scope" width="160px"/></td>
<td><img id="dvmimage" src="images/dvm.jpg" alt="digital voltmeter" width="80px"/></td></tr>
<tr><td><img id="pluginpcb" src="images/plugin.jpg" alt="pcb" width="80px"/></td>
<td><img id="hddinstimage" src="images/hdinst.jpg" alt="install" width="80px"/></td></tr>
<tr><td colspan="2" align="center"><br /><br /><img id="bsireglogo" src="images/bsi_reg_logo.gif" alt="bsi registered logo"/></td></tr>
</table> -->
 
</div>

Open in new window

homepage.GIF
LVL 29
fosiul01Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
indeed, you will have to move that also...
<?php 
  // session start, must be first
  session_start(); 
  include('connect.php'); 
 
  //Hold session for username and password
  $username = $_POST['username'] ;
  $password = $_POST['password'] ;
 
  // bellow 2 files quires for database connection and functions 
  require("config.php");
  require("functions.php");
 
  // what is the login result...
  $login_result = "";
 
  // Connecting to database and table
  $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  mysql_select_db($dbdatabase, $db);
 
 
  // if user click on submit button , check the conditions
  if($_POST['submit'])
  {
     // bellow code will select , selective username and password for the correct user 
     $sql = "SELECT * FROM users WHERE username = '{$_POST['username']}' AND password = '{$_POST['password']}';";
      
     $result = mysql_query($sql);
     $numrows = mysql_num_rows($result);
             
     if($numrows == 1) 
     { // if query gets any record       
        $row = mysql_fetch_assoc($result);
                   
        // register the session for username and password
        session_register("USERNAME"); 
        $_SESSION['USERNAME'] = $row['username']; 
                                                                
        header('Location: index.php'); // go to indexpage
     }
     else // if($numrows == 1) 
     {
        header("Location: " . $config_basedir . "/login.php?error=1");
     }
  }
  else
  {
     $login_result = "<h2>User Login</h2>";
     if($_GET['error']) 
     {
        $login_result = "Incorrect login, please try again!";
     }
  } 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
 
include('menu.inc.php');
  
// print out the results of the login result (if any)
echo $login_result;
?>
 
<div id="content">
 
<!-- Bellow code is to create html base form to get username and password  -->
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
 
<table>
<tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
</tr>
<tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
</tr>
<tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
 
 
 
</div>
<br />
<div id="footer">&copy;<?=date("Y");?> Calyx Group</div>
 
</div>
</body>
</html>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>but having problem
what kind of problem(s)?
0
 
fosiul01Author Commented:
Hi
sorry, the error was in picture
anyway, i am pasting here

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php:6) in C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php on line 17

if you check thei picture you will understand

and the error is under the picture

Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php:6) in C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php on line 60
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ok, change the code like this, moving the line "session_start()" to be the very first line in your page:
<?php 
session_start();
include('connect.php'); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
include('menu.inc.php');
 
<....rest of page code...>

Open in new window

0
 
fosiul01Author Commented:
HI, as you said, i did,
check the picture please and code aswell

the Error on top of the picture is gone
now its below of the picture

<?php session_start(); ?>
<?php include('connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
 
include('menu.inc.php');
 
 
 
// session start
 
//Hold session for username and password
$username = $_POST['username'] ;
$password = $_POST['password'] ;
 
// bellow 2 files quires for database connection and functions 
require("config.php");
require("functions.php");
 
// Connecting to database and table
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
 
// if user click on submit button , check the conditions
 
if($_POST['submit'])
 
{
     // bellow code will select , selective username and password for the correct user 
        $sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";
      
          $result = mysql_query($sql);
          $numrows = mysql_num_rows($result);
        
                
                if($numrows == 1) // if query gets any record 
                {       
                        $row = mysql_fetch_assoc($result);
                   
                        session_register("USERNAME"); // register the session for username
                        $_SESSION['USERNAME'] = $row['username']; // register the password
                                                                
                    header('Location: index.php'); // go to indexpage
                                        
                }
                else 
                {
                        header("Location: " . $config_basedir . "/login.php?error=1");
                }
 
}
else
{
 
        
 
        echo "<h2>User Login</h2>";
                
        if($_GET['error']) 
                {
                        echo "Incorrect login, please try again!";
                }
 }
?>
 
<div id="content">
 
<!-- Bellow code is to create html base form to get username and password  -->
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
 
<table>
<tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
</tr>
<tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
</tr>
<tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
 
 
 
</div>
<br />
<div id="footer">&copy;<?=date("Y");?> Calyx Group</div>
 
</div>
</body>
</html>

Open in new window

phperror2.GIF
0
 
fosiul01Author Commented:
Hi,
i did what you said, except 1 ( which i didnot understand)

// what is the login result...
  $login_result = "";
 

When user are typing username and password, if its correct , page will go to another page which is   under
if($_POST['submit']) = this code

eader('Location: index.php'); // go to indexpage

are you saying, i will have to move whole code  here ??

// what is the login result...
  $login_result = ""; ----------------------------------------------------------- ??
 
  // Connecting to database and table
  $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  mysql_select_db($dbdatabase, $db);

and out put of the page is massed up now , check the picture please
<?php 
session_start();
 include('connect.php'); 
 $username = $_POST['username'] ;
$password = $_POST['password'] ;
 
// bellow 2 files quires for database connection and functions 
require("config.php");
require("functions.php");
 
// Connecting to database and table
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
 
// if user click on submit button , check the conditions
 
if($_POST['submit'])
 
{
     // bellow code will select , selective username and password for the correct user 
        $sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";
      
          $result = mysql_query($sql);
          $numrows = mysql_num_rows($result);
        
                
                if($numrows == 1) // if query gets any record 
                {       
                        $row = mysql_fetch_assoc($result);
                   
                        session_register("USERNAME"); // register the session for username
                        $_SESSION['USERNAME'] = $row['username']; // register the password
                                                                
                    header('Location: index.php'); // go to indexpage
                                        
                }
                else 
                {
                        header("Location: " . $config_basedir . "/login.php?error=1");
                }
 
}
else
{
 
        
 
        echo "<h2>User Login</h2>";
                
        if($_GET['error']) 
                {
                        echo "Incorrect login, please try again!";
                }
 }
 
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
 
include('menu.inc.php');
 
 
 
// session start
 
//Hold session for username and password
 
?>
 
<div id="content">
 
<!-- Bellow code is to create html base form to get username and password  -->
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
 
<table>
<tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
</tr>
<tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
</tr>
<tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
 
 
 
</div>
<br />
<div id="footer">&copy;<?=date("Y");?> Calyx Group</div>
 
</div>
</body>
</html>

Open in new window

phperror3.GIF
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you try the code exactly as I posted it above?
0
 
fosiul01Author Commented:
ok bellow is my final code ( it has error only , when i am submitting the button its saying

Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php:8) in C:\Inetpub\wwwroot\electroversal\www\serviceloan\user\home.php on line 57


One of my previous question, some one told me, i have to put   if($_POST['submit']) and all below code to top of page,
but here if i do that, problem is, its unable to get database connection

i can try what you said,
but problem is,
i didnot understand what you mean by
// what is the login result...
  $login_result = ""; ??

if login is succesful it will go to index page, if fail it will stay to same page
but what code i will wirte  here > $login_result = ""; ??

<?php 
session_start();
 include('connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="test,diagnosis,repair,service,electronic,manufacturer,photocopier,fax,scanner,printer,starwriter,monitor,crt,tft,vending,warranty,retrofit,refurbish" />
<meta name="description" content="Electroversal is a provider of electronic service and repair solutions for copier,fax,scanner,printer,monitor,vending,EPOS,power supply" />
<title>electroversal &gt; Home</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="shortcut icon" href="favicon.ico" />
</head>
 
<body><div id="wrap">
 
 
<?php
 
include('menu.inc.php');
 
 
 
// session start
 
//Hold session for username and password
$username = $_POST['username'] ;
$password = $_POST['password'] ;
 
// bellow 2 files quires for database connection and functions 
require("config.php");
require("functions.php");
 
// Connecting to database and table
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
 
// if user click on submit button , check the conditions
 
if($_POST['submit'])
 
{
     // bellow code will select , selective username and password for the correct user 
        $sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";
      
          $result = mysql_query($sql);
          $numrows = mysql_num_rows($result);
        
                
                if($numrows == 1) // if query gets any record 
                {       
                        $row = mysql_fetch_assoc($result);
                   
                        session_register("USERNAME"); // register the session for username
                        $_SESSION['USERNAME'] = $row['username']; // register the password
                                                                
                    header('Location: index.php'); // go to indexpage
                                        
                }
                else 
                {
                        header("Location: " . $config_basedir . "/login.php?error=1");
                }
 
}
else
{
 
        
 
        echo "<h2>User Login</h2>";
                
        if($_GET['error']) 
                {
                        echo "Incorrect login, please try again!";
                }
 }
?>
 
<div id="content">
 
<!-- Bellow code is to create html base form to get username and password  -->
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
 
<table>
<tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
</tr>
<tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
</tr>
<tr>
        <td></td>
        <td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
 
 
 
</div>
<br />
<div id="footer">&copy;<?=date("Y");?> Calyx Group</div>
 
</div>
</body>
</html>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I guess I confused ..

  // what is the login result...
  $login_result = "";

  is the initial value, for example, in case you come to this page initially (without post)


  then, later, in the else part of the if (

  if($_POST['submit']) {
    <...>
  }
  else
  {
     $login_result = "<h2>User Login</h2>";
     if($_GET['error'])
     {
        $login_result = "Incorrect login, please try again!";
     }
  }

  I fill in the error ...

and only very later, I use that

// print out the results of the login result (if any)
echo $login_result;


to explain:
session_start()  and  header()  functions need to be used BEFORE you print/echo/ <html code> anything that would be returned to the user browser.

so, all the code must be in the initial <?php ... ?> part, without having returned ANY html code.
but, you can fill in some variables already, containing the html to be shown, later in the code, if needed.





0
 
fosiul01Author Commented:
Welll !! You could of tell me that you wrote the full code for me in prevous answer !!! you should of say, just " copy my code and past in your programm"""


i thought, you told me to write the code, so i was confused, how to write the code as you said!!

then  i just copied and past your code to my programm, its seems to be working!!!

let me adjust the following page, then will reply you

5 mins!!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>i thought, you told me to write the code, so i was confused, how to write the code as you said!!
sorry again if I confused you by not being 100% clear ...
main point is if it works!
0
 
fosiul01Author Commented:
Thankssssssssss!!

I am happy with this code!!!
i will close this question now!!
0
All Courses

From novice to tech pro — start learning today.