plz plz plz somebody help me :( :(

here is the code .. what i want is to link the emailid with a page named update.php...in which i can edit the particular emailid's row in databse ...or one can also tell to create a button EDIT .. but then i hav to use checkbox property..(of course 4 dat 2 i need the code :| )......... plz sombody help me :(

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<?php
include("config.php");

$sql="SELECT * FROM contact";
$result=mysql_query($sql);

echo "<form method=post action=''>"; 
echo "<table border='0' cellspacing='5' cellpadding='0' width='600' align='center'>"; 
echo"<tr bgcolor='#ffffff'>";
echo"<td>&nbsp;</td>";
echo"<td align='center' bgcolor='#FFFFFF'><strong>emailid</strong></td>";
echo"<td align='center' bgcolor='#FFFFFF'><strong>forwarding</strong></td>";
echo"<td align='center' bgcolor='#FFFFFF'><strong>autoresponse</strong></td>";
echo"<td align='center' bgcolor='#FFFFFF'><strong>company</strong></td>";
echo"<td align='center' bgcolor='#FFFFFF'><strong>Password</strong></td>";
echo"<td align='center' bgcolor='#FFFFFF'>&nbsp;</td></tr>";
while($rows=mysql_fetch_array($result)){

echo"<tr bgcolor='#ffffff'>";
echo"<td>";
echo"<input type = 'checkbox' name='box[]' value=\"".$rows['emailid']."\"'</td>";
echo"<td bgcolor='#FFFFFF'>".$rows['emailid']."</td>";
echo"<td bgcolor='#FFFFFF'>".$rows['forwarding']."</td>";
echo"<td bgcolor='#FFFFFF'>".$rows['autoresponse']."</td>";
echo"<td bgcolor='#FFFFFF'>".$rows['company']."</td>";
echo"<td bgcolor='#FFFFFF'>".$rows['password']."</td>";
echo"<td bgcolor='#FFFFFF'>&nbsp;</td></tr>";
}

?>
<tr><td colspan =6 align=center><input type="submit" value="Delete" name="delete">
<input type="button" name="new" value="new" onClick="window.location.href='second.php'" />

</form></td></tr></table>
<?php
if(isset($_POST['delete'])){//check to see if the delete button has been pressed

   if(isset($_POST['box'])){ //check to see if any boxes have been checked 
        $num = 0;//used to count the number of rows that were deleted
        $box = $_POST['box'];
        while (list ($key,$val) = @each ($box)) { //loop through all the checkboxes
              $num++;
              $sqldel="DELETE FROM contact WHERE emailid='$val'";//delete any that match id
              $resdel=mysql_query($sqldel);//send the query to mysql
        }
        //print the logs that were deleted
       echo"$num record(s) have been deleted.";
	   echo "<meta http-equiv=\"refresh\" content=\"0;URL=eg2.php\">";
	   //<META HTTP-EQUIV=Refresh CONTENT="3; URL=eg2.php">
   }
   else{ //no boxes checked
   echo "No records selected.";
   }
}
?>

</center>

</div>
</body> 
</html>

Set up your link something like this...

<a href="update.php?emailid=<?=$rows['emailid']?>">Edit</a>

Update.php then displays a form and handles the edit on a submit.

Here my code might help you

manageItem.php

<?php
$con=mysql_connect("localhost", "root", "rootwdp")or die("cannot connect");
mysql_select_db("student",$con)or die("cannot select DB");
$id=$_REQUEST['id'];
if(isset($_REQUEST['btnSave']))
{
	$iName=$_REQUEST['txtIName'];
	$iImg=basename($_FILES['fImg']['name']);
	$iPrice=$_REQUEST['txtIPrice'];
	if($id=="")
	{
		move_uploaded_file($_FILES['fImg']['tmp_name'],'upload/'.$iImg);
		$qry=mysql_query("INSERT INTO `item`(`id`, `item_name`,`item_image_name`,`item_price`) VALUES(NULL , '$iName', '$iImg', '$iPrice');");			
	}
	else
	{
		$qry=mysql_fetch_array(mysql_query("select `item_image_name` from `item` where `id`='$id'"));
		unlink("upload/".$qry['item_image_name']);
		move_uploaded_file($_FILES['fImg']['tmp_name'],'upload/'.$iImg);
		$qry=mysql_query("UPDATE `item` set `item_name` = '$iName', `item_image_name` = '$iImg', `item_price` = '$iPrice' where id=$id");
	}
	header("location:manageItem.php");
}
if($_REQUEST['mode']=="del")
{
	$qry=mysql_fetch_array(mysql_query("select `item_image_name` from `item` where `id`='$id'"));
	unlink("upload/".$qry['item_image_name']);
	$qry=mysql_query("delete from item where id='$id'");
	header("location:manageItem.php");
}
if($_REQUEST['mode']=="delsel")
{
	$chk1=$_POST['chk1'];
	foreach($chk1 as $id)
	{
		$qry=mysql_fetch_array(mysql_query("select `item_image_name` from `item` where `id`='$id'"));
		unlink("upload/".$qry['item_image_name']);
		$qry=mysql_query("delete from item where id='$id'");
	}
	header("location:manageItem.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="CSS/style1.css" />
<script type="text/javascript" src="scripts/val.js"></script>
</head>

<body>
<form method="post" name="frm2" action="manageItem.php?mode=delsel">
<table align="center" border="0" width="60%">
	<tr>
    	<td width="5%" align="center"><input type="checkbox" name="selecta" onclick="selectall(this)" /></td>
        
        <td width="20%">
        	<input type="submit" name="btnDelSel" value="Delete Selected" style="background:#FFFFFF; border:none; cursor:pointer; color:#666666" /></td>
        
    	<td colspan="4"><a href="edititem.php">Add Items</a></td>
    </tr>
    
<? $qry=mysql_query("select * from item order by id");
if(mysql_num_rows($qry))
	{
?>
	<tr><td colspan="6" style="border-bottom:solid 1px"></td></tr>
<?
		while($x=mysql_fetch_array($qry))
		{ ?>
    <tr>
		<td width="5%" id="brt" style="border-left:solid 1px #EDAEEF">
        	<input type="checkbox" name="chk1[]" value="<? echo $x['id'];?>" onclick='sa()' /></td>
        <td width="20%" id="brt">
        	<img src="upload/<? echo $x['item_image_name']?>" width="100" height="100" /></td>
		<td width="35%" id="brt"><? echo $x['item_name'] ?></td>
		<td width="20%" id="brt"><? echo '$ '.$x['item_price']?></td>
        <td width="10%" id="brt"><a href="manageItem.php?id=<? echo $x['id'];?>&mode=del">Delete</a></td>
        <td width="10%" id="brt"><a href="editItem.php?id=<? echo $x['id'];?>">Edit</a></td>
  </tr>
  <tr>
  	<td colspan="6"><div style="border-bottom:solid 1px"></div></td>
  </tr>
<?		}
	} ?>
</table>
</form>
</body>
</html>

editItem.php

<?php
require_once("db_connect.php");
$id=$_REQUEST['id'];
$qry=mysql_query("select * from item where id='$id'");
$x=mysql_fetch_array($qry)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="scripts/val.js"></script>
</head>

<body>
<table align="center" width="35%" border="0" cellspacing="0" cellpadding="5" style="border:solid 1px #DDD">
<form method="post" name="frm1" action="manageItem.php?id=<? echo $id; ?>" enctype="multipart/form-data" onsubmit="return check(this);">
  <tr>
    <td width="25%" align="right">Item Name</td>
    <td width="5%" align="center">:</td>
    <td width="70%" align="left"><input type="text" name="txtIName" value="<? echo $x['item_name']; ?>" /></td>
  </tr>
  <tr>
    <td align="right">Item Image</td>
    <td align="center">:</td>
    <td align="left"><input type="file" name="fImg"  value="<? echo $x['item_image_name']; ?>" /></td>
  </tr>
  <tr>
    <td height="34" align="right">Item Price</td>
    <td align="center">:</td>
    <td align="left"><input type="text" name="txtIPrice" value="<? echo $x['item_price']; ?>" /></td>
  </tr>
  <tr>
    <td align="right"></td>
    <td align="center"></td>
    <td align="left"></td>
  </tr>
  <tr>
    <td height="42" colspan="2" align="right"><input type="reset" name="btnCancel" value="Cancel" /></td>
    <td align="left"><input type="submit" name="btnSave" value="Save" /></td>
  </tr>
  <tr>
      <td height="37" colspan="3" align="center"><div id="divError" style="color:#FF0000"></div></td>
  </tr>
  </form>
</table>
</body>
</html>

Create a folder named 'scripts' for 'val.js'

// JavaScript Document
function check(x)
{
	if(x.txtIName.value=="")
	{
		document.getElementById('divError').innerHTML="Enter item name";
		return false;
	}
	if(x.fImg.value=="")
	{
		document.getElementById('divError').innerHTML="Browse an image";
		return false;
	}
	if(x.txtIPrice.value=="")
	{
		document.getElementById('divError').innerHTML="Enter item price";
		return false;
	}
}
function selectall(x)
{
	var chkobj = document.frm2['chk1[]'];
	var l=chkobj.length;var i=0;
	if(x.checked==true)
		for(i=0;i<l;i++)
			chkobj[i].checked=true;
	else
		for(i=0;i<l;i++)
			chkobj[i].checked=false;
}
function sa()
{
	var chkobj = document.frm2['chk1[]'];
	var l=chkobj.length;
	var b=true;
	var i=0;
	for(i=0;i<l;i++)
		if(chkobj[i].checked == false){
			b=false;
			break;
			}
	document.frm2.selecta.checked=b;
}

Create a folder named 'upload' for saving of images of products.
And create a database named 'student' and a table named 'item' with fields names
'id','item_name','item_image_name','item_price'
Update the php code with mysql servername, username and password
Mine is 'localhost', 'root', 'rootwdp' respectively.

If you want to edit multiple items then, instead of edit link create a submit button
and show all the information of items in a html-form with loop in php script with the help of 'id' field.

Hope this help you.

Thank U !!! going 2 try dis :)

hey ... Mahavir and madcoder .. thanx .. i did dat successfully :) :) .. now tell me ... what is wrong here :/ :/ .. in da swtich case section... is anything wrong?? :( as in databse in uid field... "uid" is appearing x-( .. plz tell me no .. thanx in advance and post thanx 2 :)

<?php 
include("config.php"); 
?>
<?php
$id=$_REQUEST['emailid'];
echo "email id :$id";
$forwarding=$_REQUEST['forwarding'];
echo "forwarding to: $forwarding";
$autoresponse=$_REQUEST['response'];
echo "With auto response : $autoresponse is inserted";
$company=$_REQUEST['company'];
echo "$company"; 
$password=$_REQUEST['repassword'];
echo "$password"; ?>
<?php
switch ($company)
{
	case "jks":
		$uid=1;
		break;
	case "kks":
		$uid=2;
		break;
	case "bucati":
		$uid=3;
		break;
	default:
		echo "Sorry";
		break;
}
?>
<?php
// update data in mysql database 
$sql="UPDATE contact SET uid='$uid',emailid='$id', forwarding='$forwarding', autoresponse='$autoresponse', company='$company',password='$password' WHERE emailid='$id'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='eg3.php'>Back to main page</a>";}

else {
echo "ERROR";
}

?>

how dat smiley came there in code :-o .. i dont knw :|

i replaced switch case to 'else if' its working.. but wat the hell was wrong wid cases??? :O

I don't see anything semantically wrong with the switch statement you had above. (Except that it will be hard to maintain since code must be edited and tested every time a new company is needed.)

The smiley face earlier appeared because you didn't use CODE blocks surrounding your PHP code ie CODE=php surrounded by square brackets [].

In the switch statement, the comparison will be case sensitive, so that might have been a factor. Also, you did not initialize $uid or set it to something invalid like 0 in the default case.

ok:)

can u help me in log in page for this databse :|

ok:)

can u help me in log in page for this databse

Sure, what do you have in mind?

Try this login page.

Just scribble some thing just now but should word fine.

myCon();//database connection
				  myDb(); //database selection
	// your work on post variables
	$uName=strip_tags(addslashes(trim($_POST['uName'])));
	$password=strip_tags(addslashes(trim($_POST['password'])));
	$remember=strip_tags(addslashes(trim($_POST['remember'])));
	$logIn=$_POST['logIn'];
	 $password=sha1($password);
	
	if($_GET['logout']==1){ // logout part
		session_unset();  // and unset session
		echo " You just logout";// logout notice
		header("location:/index.php"); //and direct to what ever page
	}
	
	
	        //Check for post array
			
			
	if($_POST){
		$count=0;
		          //DATABASE CONNECTION
				  
				  $query="SELECT * FROM register WHERE(UNAME='$uName' AND PASSWORD='$password' AND CONFIRM=1)";
				  $result=mysql_query($query) or die( mysql_error());
				  $row=mysql_fetch_array($result);
				     $_SESSION['regId']=$row['RED_ID']; // put id for future use
				  //CHECK EMPTY STUFF
		if(empty($uName) || empty($password)){
			echo "<div class='error' style='margin-left:120px;'>";
				echo "<h3>Oops error</h3>";
				echo "Please enter your user name and password.</div><br/><br/>";
			include_once("user-includes/logForm.php"); // form for entering username and password to login.
		}
		
		  
				
		elseif(!mysql_num_rows($result)){
		 // check if the use does not exists
		      	echo "<div class='error'style='margin-left:120px;'>";
				echo "<h3>Oops error</h3>";
				echo "Wrong user name and password.</div><br/><br/>";
				include_once("user-includes/logForm.php");
		      }
			  else{

// if the user exists, do this fo future use.
			  	session_regenerate_id();
				session_register($uName);
				$_SESSION['logIn']=1;
				$_SESSION['password']=$password;
				$_SESSION['uName']=$uName;
				
			  header("location:https://account.getcert.biz/account-login");//
locate to the user page.
			  }
                
		
		   
		   	   			
		
		
		
		
		
		
	}
	
	      else{
	      	include_once("user-includes/logForm.php");// log for should be the login form input where you enter username and password . 
	      }

ok i see this :-o

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.