Hello everybody,
I've been working on programming a simple news script. My idea was to put default images for every category of the news. And when the news is added, all images (for each category) are in the list with a radio button on their side. If selected, that certain image will be used for the news.

Now, how do I save the image choice on the mySQL database?

Your help is greatly appreciated.
Thank you

    well, you could save the image information in a table within the database. Then, just use the image ID as the radio button value, and when they select the image, save the image ID. Then, when you need to call the information back, just join the tables on the image IDs.

    ~Brett

      Yep, that's exactly what I did. But now, whenever I want to edit a news, the selection of the image is not remembered. What can I do so that it is?

        What is your query for updating/inserting? Give us some code so we can help...

        ~Brett

          <?
          include("config.php");
          if($_POST[date] !="" and $_POST[title] !=""){
          MYSQL_QUERY("INSERT INTO `news` (`date`, `title`, `image`, `post`) VALUES ('$_POST[date]', '$_POST[title]', '$_POST[image]', '$_POST[post]')");
          }
          
          <table width="50%" border="0" cellspacing="0" cellpadding="0"><tr> 
          <td>
               <table width="19%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                         <td width="33%"><input type="radio" name="image" value="img/news-fig1.jpg"></td>
                         <td width="67%"><div align="center"><img src="img/news-fig1.jpg" width="40" height="41"></div></td>
                    </tr>
               </table>
          </td>
          
          <td>
               <table width="19%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                         <td width="33%"><input type="radio" name="image" value="img/news-fig2.jpg"></td>
                         <td width="67%"><div align="center"><img src="img/news-fig2.jpg" width="40" height="41"></div></td>
                    </tr>
               </table>
          </td>
          
          <td>
               <table width="19%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                         <td width="33%"><input type="radio" name="image" value="img/news-fig3.jpg"></td>
                         <td width="67%"><div align="center"><img src="img/news-fig3.jpg" width="40" height="41"></div></td>
                    </tr>
               </table>
          </td>
          
          <td>
               <table width="19%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                         <td width="33%"><input type="radio" name="image" value="img/news-fig4.jpg"></td>
                         <td width="67%"><div align="center"><img src="img/news-fig4.jpg" width="40" height="41"></div></td>
                    </tr>
               </table>
          </td></tr></table>
          

          and when I call the function I just put:

          <img src='$image' width='35' height='35'>

            well, when you call the images from the database, you'dhave to use something like:

            <?php
            $query = "SELECT * FROM `table` ORDER BY id ASC";
            $result = mysql_query($query);
            while($row = mysql_fetch_array($result))
            {
                echo '<img src="'.$row['image'].'" width="35" height="35"><br>'."\n";
            }
            ?>

            ~Brett

              Well, I don't have a problem with calling the images from the database.

              My problem is that, after I add the news, when I try to edit it, the editnews.php does not recognise which image i selected before (when the news was added).

                So then what is that code? The code you posted is code to initially insert the information. Where's your UPDATE SQL?

                ~Brett

                  Write a Reply...