Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

problem removing image from database

images php coding issues or problems here.

Moderators: macek, egami, gesf

problem removing image from database

Postby buskyboy » Sun May 08, 2011 2:26 am

I hope someone can help me. I have a problem that I cannot solve after 3 days.

I have a form with a few text fields, into which a url is added for an image. I can get the image addresses back out of the database and display them. no problem. My problem is when I update the the form text are and try to insert nothing into the Db it always inserts a black string. i have tried to convert these stings to null values but to no avail. any thoughts would be appreciated.

Here is some of code

For inserting to DB
Code: Select all
<?php

include_once('connect_to_database.php');

if(isset($_POST['save']))
{

   $issue= $_POST['issue'];
   $title   = $_POST['title'];
   $content = nl2br($_POST['editor1']);
   $pic1 = $_POST['pic1'];
   $pic2 = $_POST['pic2'];
   $pic3 = $_POST['pic3'];

   if(!get_magic_quotes_gpc())
   {
     
       $issue = addslashes($issue);
      $title   = addslashes($title);
      $content = addslashes($content);
   }
 
 


$query="INSERT INTO `newsletter_apm` (`issue_nos` , `story_title` , `story` ,`url1` ,`url2` ,`url3` ) VALUES('$issue','$title', '$content','$pic1','$pic2','$pic3')";
   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());


   echo "Article '$title' added";
}
?>


This works fine.

Code for updating.
Code: Select all
<?php



if(isset($_POST['save']))
{

   $issue= $_POST['issue'];
   $title   = $_POST['title'];
   $content = ($_POST['editor1']);
   $pic1 = $_POST['pic1'];
   $pic2 = $_POST['pic2'];
   $pic3 = $_POST['pic3'];
   
 
   if(!get_magic_quotes_gpc())
   {
     
   $issue = addslashes($issue);
      $title   = addslashes($title);
      $content = addslashes($content);
        }
 

if ($pic2==""){ $pic2=null;}
if ($pic3==""){ $pic3=null;}
 


//$query="UPDATE `newsletter_apm` SET `issue_nos` , `story_title` , `story` ,`url1` ,`url2` ,`url3`   
 $query="UPDATE `newsletter_apm` SET issue_nos ='$issue ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());

 $query="UPDATE `newsletter_apm` SET story_title ='$title ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());

$query="UPDATE `newsletter_apm` SET story ='$content ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());


$query="UPDATE `newsletter_apm` SET url1 ='$pic1 ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());



$query="UPDATE `newsletter_apm` SET url2 ='$pic2 ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());


$query="UPDATE `newsletter_apm` SET url3 ='$pic3 ' Where id=$id";   
$result=mysql_query($query) or die("Died inserting info into db.  Error returned if any: ".mysql_error());





   echo "Article '$title' has been updated";
}
?>


This will update with new urls no problem but if I delete one leaving a blank it inserts an blank string.


code for diaplaying pics is repeating block

Code: Select all
<tr>
<td valign="top"  bgcolor="#FF0000"   ><!-- // Begin Module: Standard Preheader \ -->
                            <table width="100%" border="0" cellpadding="10" cellspacing="0" >
                              <tbody><tr>
                                <td valign="top" bgcolor="#FFFFFF" >
                                  <h4  style="color:#336699; font-size:18pt; font-style:bold;line-height;8pt;font-family:Verdana;margin:0pt;padding-bottom:0pt" ><?php echo $storyheading[$i]; ?></h4>
                                 
                                  <h2 style="font-family:Verdana; font-weight:lighter; font-style:inherit; font-size:8pt; margin:0pt;"><?php echo $story[$i] ;?></h2></td>
                               
                                <td width="200" valign="top" bgcolor="#FFFFFF" style="background-color:#336699; " >
                               
                               
                               
                               <?php
                               
                               //loop through the pics and only display if there is one in the database to make sure thet a placeholder does not show.
                               
                             
                                                       
                                if (  $pic[$i ]!= ''){   echo "<img src= $pic[$i] name='pic1' width='200'  id='logo26' /><br><br>"; }
                               
                               
                                 if (  trim($pic1[$i] !='')){   echo "<img src= $pic1[$i] name='pic1' width='200'  /><br><br>"; }
                                 
                                 
                                  if (  $pic2[$i] != ''){   echo "<img src= $pic2[$i] name='pic1' width='200'   />"; }
                                 
                                 
                     

                                                                                   
                                ?>
                                                                   
                               </td>
                               
                              </tr>


I am trying to make a dynamic mailshot with any number of stories.

you can check out a version at
http://www.pat-trick.com.au/emailshot/a ... hp?issue=1
the problem is picture placer shows in safari, chrome and most email clients.

I hope i make the issue clear.

Thanking you in advance. :)
buskyboy
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Aug 19, 2010 3:24 am
Location: Australia

Re: problem removing image from database

Postby webinfopedia » Wed May 25, 2011 10:24 am

I saw one problem in your updating PHP script
Code: Select all
$query="UPDATE `newsletter_apm` SET issue_nos ='$issue ' Where id=$id";   


See in the above code there should not be any space after your variable. It should be like this.
$query="UPDATE `newsletter_apm` SET issue_nos ='$issue' Where id=$id";

In all updating query its like that. Kindly check it. Hope that you will get solution for this problem.
Read my articles at http://www.webinfopedia.com/
User avatar
webinfopedia
New php-forum User
New php-forum User
 
Posts: 84
Joined: Sat May 21, 2011 10:26 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.