Click here to Skip to main content
13,097,230 members (62,505 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
i want to insert update and delete action performed but some body problem please give me solution and i will forward my code

<?php
 
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("prediqnous");
 
if($_POST["hdnCmd"] == "Add")
{
    if(copy($_FILES["fileUpload"]["tmp_name"],"shotdev/".$_FILES["fileUpload"]["name"]))
    {
        $strSQL = "INSERT INTO user1 ";
        $strSQL .="(id,name,description,GallaryName,picture) ";
        $strSQL .="VALUES ";
        $strSQL .="('".$_POST["txtAddid"]."','".$_POST["txtAddname"]."','".$_POST["txtAdddescription"]."','".$_POST["txtGallaryName"]."' ";
        $strSQL .=",'".$_FILES["fileUpload"]["name"]."')";
        $objQuery = mysql_query($strSQL);
            if(!$objQuery)
            {
                echo "error Add[".mysql_error()."]";
            }
    }
 
}
if($_POST["hdnCmd"] == "Update")
{
     if(copy($_FILES["fileUpload"]["tmp_name"],"shotdev/".$_FILES["fileUpload"]["name"]))
     {
 
      $strSQL = "UPDATE user1 SET ";
      $strSQL .="id = '".$_POST["txtEditid"]."' ";
      $strSQL .=",name = '".$_POST["txtEditname"]."' ";
      $strSQL .=",description = '".$_POST["txtEditdescription"]."' ";
      $strSQL .=",GallaryName = '".$_POST["txtEditGalleryName"]."' ";
      $strSQL .=",picture = '".$_FILES["Name"]."' ";
      $strSQL .="WHERE id = '".$_POST["hdnEditid"]."' ";
      $objQuery = mysql_query($strSQL);
      print_r($strSQL);
      }
}
if($_GET["Action"] == "Del")
{
     if(copy($_FILES["fileUpload"]["tmp_name"],"shotdev/".$_FILES["fileUpload"]["name"]))
     {
       $strSQL = "DELETE FROM user1 ";
       $strSQL .="WHERE id = '".$_GET["id"]."' ";
       $objQuery = mysql_query($strSQL);
     }
}
$strSQL = "SELECT * FROM user1";
$objQuery = mysql_query($strSQL) or die(mysql_error());
?>
<form name="frmMain" method="post" enctype="multipart/form-data"   action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table border="2">
<tr>
<th>id</th>
<th>name</th>
<th>description</th>
<th>GallaryName</th>
<th>picture</th>
<th>edit</th>
<th>delete</th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
    if($objResult['id'] == $_GET['id'] and $_GET['Action'] == 'Edit')
    {
 
?>
<tr>
<td>
       <input type="text" name="txtEditid" size="5" value="<?php echo $objResult["id"];?>" />
       <input type="hidden" name="hdnEditid" size="5" value="<?php echo $objResult["id"];?>" />
</td>
<td>
<input type="text" name="txtEditname" value="<?php echo $objResult['name']; ?>" /></td>
<td>
<input type="text" name="txtEditdescription" value="<?php echo $objResult['description']; ?>" /></td>
<td>
<input type="text" name="txtEditGallaryName" value="<?php echo $objResult['GallaryName']; ?>"/></td>
<input type="file" name="fileUpload" value="<?php echo $objResult['picture']; ?>" /></td>
<td>
      <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
      <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?php echo $_SERVER["PHP_SELF"];?>';">
</td>
</tr>
 <?php
    }
  else
    {
  ?>
 
  <tr>
  <td><?php echo $objResult['id']; ?></td>
  <td><?php echo $objResult['name']; ?></td>
  <td><?php echo $objResult['description']; ?></td>
  <td><?php echo $objResult['gallaryName']; ?></td>
  <td><?php echo $objResult['picture']; ?></td>
  <td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&id=<?php echo $objResult["id"];?>">Edit</a></td>
  <td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&id=<?php echo $objResult["id"];?>';}">Delete</a></td>
 </tr>
 <?php
    }
  ?>
    <?php
    }
  ?>
<tr>
<td><input type="text" name="txtAddid" >
</td>
<td><input type="text" name="txtAddname" />
</td>
<td>
<input type="text" name="txtAdddescription">
</td>
<td>
<input type="text" name="txtAddgallaryName">
<input type="file" name="fileUpload"></td>
 
<td colspan="2" align="right"><div align="center">
      <input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
    </div></td>
</tr>
</table>
</form>
 
<?php
    if(copy($_FILES["fileUpload"]["tmp_name"],"shotdev/".$_FILES["fileUpload"]["name"]))
    {
            mysql_connect("localhost","root","") or die (mysql_error());
            mysql_select_db("prediqnous");
            $strSQL = "INSERT INTO user1 ";
            $strSQL .="(GalleryName,Picture) VALUES ('".$_POST["txtGalleryName"]."','".$_FILES["fileUpload"]["name"]."')";
            mysql_query($strSQL);
            mysql_close();
    }
?>
 
    <?php
        mysql_connect("localhost","root","") or die(mysql_error());
        mysql_select_db("prediqnous");
        $strSQL = "SELECT * FROM user1";
        $objQuery = mysql_query($strSQL);
    ?>
    <table width="200" border="1">
    <tr>
    <th width="200"> <div align="center">Gallery Name </div></th>
    </tr>
    <?php
        while($objResult = mysql_fetch_array($objQuery))
        {
    ?>
    <tr>
    <td><center><img src="shotdev/<?php echo $objResult["Picture"];?>" height="100" width="200">
    <br><?php echo $objResult["GalleryName"];?></center></td>
    </tr>
    <?php
        }
    ?>
    </table>
</body>
</html>
<?php
mysql_close();
?>
Posted 28-Apr-13 20:53pm
Comments
Prasad Khandekar 29-Apr-13 2:59am
   
Hello Ashok,

Please provide more information on the problem.
Oso Oluwafemi Ebenezer 29-Apr-13 6:31am
   
What you are asking is unclear!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100