Jump to content

Files not working


vinoindiamca

Recommended Posts

When i Try to Update the records Unidentified Offset Error is arised please help me over this....

 

Create a db called emp

Create a table called emp

fields are  empid int, empno varchar,empname varchar

 

Thanks in advance

 

<?php

$dbhost = 'localhost';

$dbuser = 'root';

$dbpass = 'xxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

//echo "Connected to MySQL<br />";

$dbname = 'emp';

mysql_select_db($dbname);

?>

 

Login Page Save it as index.php

<html>
<head>
<title>PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #8295E3;
}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
.tableright
{
border-left: 1px #D5D9F9 solid;
border-right: 1px #D5D9F9 solid;
border-bottom: 1px #D5D9F9 solid;
border-top: 1px #D5D9F9 solid;
}
.style9 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #000000; }
-->
</style>
</head>

<script language="javascript">
function goto()
{
document.form1.action="index.php";
document.form1.submit();
}
</script>
<script language="javascript">


</script>
<body>
<?php
function insert()
{
include 'connectmysql.php';


     if(($_POST["uname"] == "") || ($_POST["pass"] == "")) 
				{

				header("Location :index.php");
				echo "<script language='javascript' type='text/javascript'>";
				echo " alert('Invalid User Name & Password');";
				echo "window.location='index.php'";
				echo "</script>";
			    
				 echo"<form name='form1' method='post'>";
				 echo "<table border='0'>";
				 echo "<input type='button' name='Submit' value='Back To Login' onClick='goto()'>";
				 echo "</table>";

				 echo "</form>";

				exit;
				}


				$username=$_POST["uname"];
				$password=$_POST["pass"];

				$query = "select uname,pass from user_mgmt where uname='$username' and pass='$password'";



				$result = mysql_query($query) or die(mysql_error());
				echo "<script language='javascript' type='text/javascript'>";
				echo " alert('Invalid User Name & Password');";
				echo "window.location='index.php'";
				echo "</script>";
				if(mysql_num_rows($result)==1) 
					{

				setcookie("Allow_Users","1",0,"/","",0);
				header("Location:http://localhost/PHP/select.php");

					}

				else 
					{
				setcookie("Denie_Users","2",0,"/","",0);
				header("Location :index.php");
					}
}


function form()
{

?>
<form name="form1" method="post">


<table width="98%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="33%"> </td>
    <td width="30%"> </td>
    <td width="37%"> </td>
  </tr>
  <tr>
    <td colspan="3"><table width="96%" height="31"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="8%"> </td>
        <td width="1%" bgcolor="#D3D7F8"> </td>
        <td width="91%" bgcolor="#D3D7F8"><span class="style9"> PHP </span><span class="style9"></span></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="3"> </td>
    </tr>
  <tr>
    <td colspan="2"> </td>
    <td><table width="87%"  border="0" cellpadding="0" cellspacing="0" class="tableright">
      <tr>
        <td height="204">
          <table width="98%" height="198"  border="0" align="center" cellpadding="0" cellspacing="0">
            <tr bgcolor="#EDEEFC">
              <td height="19" colspan="4"><div align="center"><span class="style1"> </span></div></td>
            </tr>
            <tr bgcolor="#EDEEFC">
              <td height="19" colspan="4"><div align="center"><span class="style1">Login</span></div></td>
              </tr>
            <tr bgcolor="#EDEEFC">
              <td width="28%" height="19" class="style6"><div align="right">Username</div></td>
              <td width="2%" height="19"><div align="left">:</div></td>
              <td height="19" colspan="2"><input name="uname" type="text" size="25" maxlength="30"></td>
            </tr>
            <tr bgcolor="#EDEEFC">
              <td height="19" class="style6"><div align="right">Password</div></td>
              <td height="19"><div align="left">:</div></td>
              <td height="19" colspan="2"><input name="pass" type="text" size="25" maxlength="30"></td>
            </tr>
            <tr bgcolor="#EDEEFC">
              <td height="19">  </td>
              <td height="19"> </td>
              <td height="19" colspan="2"> </td>
            </tr>
            <tr bgcolor="#EDEEFC">
              <td height="19" bgcolor="#EDEEFC"> </td>
              <td height="19"> </td>
              <td width="11%" height="19">  </td>
              <td width="59%" height="19"><input type="submit" name="add" value="Login" id="add"  ></td>
            </tr>
            <tr bgcolor="#EDEEFC">
              <td height="19"> </td>
              <td height="19"> </td>
              <td height="19" colspan="2"> </td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
<input type="hidden" name="login">
</form>
<?php
}
if (isset($_POST['add'])){
	insert();
	}else{
	form();
	}

?>

</body>
</html>


SELECT and DELETE PAGE save it as insert.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--

.tabletop5{
    
    font-family:'arial ',helvetica,sans-serif;
    font-size:84%;
    font-weight:bold;
    background-color:#D0DCF4;
    border-color:#D0DCF4;

 border-bottom:3px #ffffff solid;
     border-right:1px #D0DCF4 solid;
 border-top: 1px #D0DCF4 solid;
 border-left: 1px #D0DCF4 solid;
}
.tableheader2{
	color:#464646;
   
    font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 
    font-size:84%;
    font-weight:;
    background-color:#EAF0FB;
    border-width: 1px;
border-style: thin;
border-color:#B6AC8A;
    filter:progid:DXImageTransform.Microsoft.Gradient
      (GradientType=0,StartColorStr='#EAF0FB',EndColorStr='#EAF0FB');
 border-bottom: 1px #EAF0FB solid;
     border-left:1px #EAF0FB solid;
 border-top: 1px #EAF0FB solid;
 border-right:1px #EAF0FB solid;
     
}
.tableheaderA {

    font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 
    font-size:75%;
    background-color:#EAF0FB;

   
  }
.tableright{
    
     font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 
     font-size:84%;
     
     border-left:1px #E1E1E1 solid;
 border-bottom: 1px #E1E1E1  solid;
 border-right:1px #E1E1E1 solid;

}
.tableright1{
     color:#1A1A1A;
     font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 
     font-size:84%;
     
     border-left:1px #BDCFF0 solid;
 border-bottom: 1px #BDCFF0  solid;


}
.bottomborder
{ 
color:#1A1A1A;
font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 
font-size:84%;
border-bottom: 1px #D5DFF7  solid;

border-right:1px #FFFFFF solid;

}
.bottomborder2
{ 
color:#1A1A1A;
font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; 

font-size:84%;
border-bottom: 1px #D5DFF7  solid;

border-right:1px #D5DFF7 solid;

}
.style8 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style9 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; background-color: #D0DCF4; border-color: #D0DCF4; border-bottom: 3px #ffffff solid; border-right: 1px #D0DCF4 solid; border-top: 1px #D0DCF4 solid; border-left: 1px #D0DCF4 solid; }
.style12 {color: #1A1A1A; font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; border-left: 1px #BDCFF0 solid; border-bottom: 1px #BDCFF0 solid; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style13 {color: #1A1A1A; font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; border-bottom: 1px #D5DFF7 solid; border-right: 1px #FFFFFF solid; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style14 {color: #1A1A1A; font: 11px Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; border-bottom: 1px #D5DFF7 solid; border-right: 1px #D5DFF7 solid; font-family: Verdana, Arial, Helvetica, sans-serif; }
-->
</style>
</head>
<script language="javascript">
function goto()
{
document.form1.action="select.php";
document.form1.submit();
}
function edit(val)
{
  //  alert(val)
//	win=window.open("","mywin","scrollbars,resizable,static,depedent")
document.form1.target="_self";
document.form1.action="update.php";
document.form1.cid.value=val;
document.form1.submit();
}
</script>
<body >

<?php

include 'connectmysql.php';

//mysql_query($query);
//}
$rowsPerPage = 10;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$query  = "SELECT * FROM emp LIMIT $offset, $rowsPerPage";
//$result = mysql_query("SELECT * FROM emp");
$result = mysql_query($query) or die('Error, query failed');
$count=mysql_num_rows($result);
?>
<form name="form1" method="post" >
<input type="hidden" name="cid" value="<?php  echo $row['empid'] ; ?>">
<table width="98%" border="0">
  <tr>
	<td width="11%"> </td>
	<td width="81%"> </td>
	<td width="8%"> </td>
  </tr>
  <tr>
    <td colspan="3">
	<table width="98%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4" class="style9"><div align="left"><strong>Employee Details </strong></div></td>
      </tr>
      <tr class="tableheaderA">
        <td width="10%" class="style8">S.No</td>
        <td width="8%" class="style8"><input name="delete" type="submit" id="delete" value="Delete"></td>
        <td width="47%" class="style8">  Employee Number </td>
        <td width="35%" class="style8">  Employee Name </td>
      </tr>
      <?php
  while($row = mysql_fetch_array($result))

     {
  ?>
      <tr>
        <td class="style12">
            <?php  echo $row['empid'] ?>
        </td>
        <td class="style12"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['empid']; ?>"></td>
        <td class="style13">               <a href="javascript:edit('<?php  echo $row['empid'] ; ?>')" class="style2"> <?php  echo $row['empno'] ; ?>  </a>        </td>
        <td class="style14">               <?php  echo $row['empname'] ; ?>        </td>
      </tr>
      <?php
  }

  ?>
    </table>
  <span class="style8">	  </span></td>
    </tr>
  <tr>
    <td colspan="3"><span class="style8">
      <?php
  
$query = "SELECT COUNT(*) AS numrows FROM emp";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
	$nav .= " $page ";   // no need to create a link to current page
}
else
{
	$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}		
}

if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";

$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
//echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
echo $first . $prev . $nav . $next . $last;

?>
    </span></td>
<?php
// Check if delete button active, start this

if(isset($_POST['delete'])){
   if (!empty($_POST['checkbox'])) {
      foreach($_POST['checkbox'] as $v) {
         $del_id = mysql_real_escape_string($v);
         $sql = "DELETE FROM emp WHERE empid ='$del_id'";
         mysql_query($sql);
	 echo "<script language='javascript' type='text/javascript'>";

				echo "window.location='insert.php'";
				echo "</script>";

      }
   }
}

// if successful redirect to delete_multiple.php

mysql_close();
?>
    </tr>
  <tr>
    <td> </td>
    <td><input type="button" name="Submit" value="Back to Insert"  onClick="goto()"></td>
    <td> </td>
  </tr>
</table>

</form>
</body>
</html>

INSERT PAGE save it as select.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
.style9 {font-size: 10px}
.style10 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function save()
{
alert(document.form1.savehid.value);
document.form1.target="_self";
document.form1.action="insert.php";
document.form1.savehid.value;
document.form1.submit();
}
function goto()
{
document.form1.action="select.php";
document.form1.submit();
}
</script>
<body>
<?php

function insert()
{
include 'connectmysql.php';

$id = $_POST['empid'];
$empno1 = $_POST['empno'];
$empname1 = $_POST['empname'];


//if(empty($id)) error_message("You need to enter some text in news box!");
//if($id=$ss['empid'])
//{
$query = "INSERT INTO emp (empno,empname) VALUES ('$empno1','$empname1')";

if (!mysql_query($query))
  {
echo"<form name='form1' method='post'>";
   echo "<table border='0'>";
  echo "<input type='button' name='Submit' value='Back to Insert' onClick='goto()'>";
  echo "</table>";
  echo "</form>";
  die('Error, Empid Already Exists Please insert Correctly');
  }
header("Location:insert.php"); 
//header("Location:http://localhost/insert.php"); 
	}
function form(){

?>
<form method="post" name="form1">
<table width="98%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"> </td>
    </tr>
  <tr>
    <td colspan="2"> </td>
    <td width="29%"><a href="../index.php" class="style8 style10">Log Off</a> </td>
  </tr>
  <tr>
    <td width="12%"><span class="style8">Empno</span></td>
    <td colspan="2"><input name="empno" type="text" id="empno"></td>
    </tr>
  <tr>
    <td><span class="style8">Empname</span></td>
    <td colspan="2"><input name="empname" type="text" id="empname"></td>
    </tr>
  <tr>
    <td colspan="3"><span class="style9"></span><span class="style9"></span></td>
    </tr>
  <tr>
    <td><span class="style9"></span></td>
    <td colspan="2"><input name="add" type="submit" value="add" id="add" ></td>
    </tr>
</table> 
<input type="hidden" name="savehid" value="add">
</form>

<?php
}
if (isset($_POST['add'])){
	insert();
	}else{
	form();
	}

?>
</body>
</html>

UPDATE PAGE save it as update.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
.style9 {font-size: 10px}
.style10 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">
function save()
{
alert(document.form1.savehid.value);
document.form1.target="_self";
document.form1.action="insert.php";
document.form1.savehid.value;
document.form1.submit();
}
function goto()
{
document.form1.action="insert.php";
document.form1.submit();
}
</script>
<body>
<?php

function insert()
{
include 'connectmysql.php';

$cid=$_POST['cid'];
$empno1 = $_POST['empno'];
$empname1 = $_POST['empname'];



//if(empty($id)) error_message("You need to enter some text in news box!");
//if($id=$ss['empid'])
//{

$query = "UPDATE  emp set empno='$empno1',empname='$empname1' where empid=$cid";
echo $query;
if (!mysql_query($query))
  {
echo"<form name='form1' method='post'>";
   echo "<table border='0'>";
  echo "<input type='button' name='Submit' value='Back to Insert' onClick='goto()'>";
  echo "</table>";
  echo "</form>";
  die('Error, Empid Already Exists Please insert Correctly');
  }
header("Location:insert.php"); 
//header("Location:http://localhost/insert.php"); 
	}
function form(){
include 'connectmysql.php';
$cid=$_POST['cid'];
$sql  = "SELECT * FROM emp where empid='$cid'";
//$result = mysql_query("SELECT * FROM emp");
$result1 = mysql_query($sql) or die('Error, query failed');
$row = mysql_fetch_array($result1);

?>
<form method="post" name="form1">
<input type="hidden" name="cid" value="<?php echo $cid ?>">
<table width="98%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"> </td>
    </tr>
  <tr>
    <td width="12%"> </td>
    <td width="59%"> </td>
    <td width="29%"><a href="../index.php" class="style8 style10">Log Off</a> </td>
  </tr>
  <tr>
    <td><span class="style8">Empno</span></td>
    <td colspan="2"><input name="empno" type="text" id="empno" value="<?php  echo $row['empno'] ; ?> "></td>
    </tr>
  <tr>
    <td><span class="style8">Empname</span></td>
    <td colspan="2"><input name="empname" type="text" id="empname" value="<?php  echo $row['empname'] ; ?> "></td>
    </tr>
  <tr>
    <td colspan="3"><span class="style9"></span><span class="style9"></span></td>
    </tr>
  <tr>
    <td><span class="style9"></span></td>
    <td colspan="2"><input name="add" type="submit" value="add" id="add" ></td>
    </tr>
</table> 
<input type="hidden" name="savehid" value="add">
</form>

<?php
}
if (isset($_POST['add'])){
	insert();
	}else{
	form();
	}

?>
</body>
</html>

 

(edited by kenrbnsn to add


for readability)

 

Link to comment
https://forums.phpfreaks.com/topic/136216-files-not-working/
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.