Click here to Skip to main content
15,867,835 members

php related problem on image store table and retrive image

ashokcom asked:

Open original thread
i want to insert update and delete action performed but some body problem please give me solution and i will forward my code

XML
<?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();
?>
Tags: PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900