Radio Buttons with image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Radio Buttons with image

Post by killbaz »

Hello to all.
I've been searching a script that will do this job , but nowhere is.

So , i want to make a script that will extract some data from a table and put it in radio buttons with image and after that with a submit form insert it in another table.

Well , that's what i did so far:

creeaza.php

Code: Select all

<form id="creeaza" name="creeaza" method="post" action="creeaza_tot.php">
                  <?php
 
$queryasd = mysql_query("SELECT * FROM creeaza_tip_guler ORDER BY ID ASC;");
while($row = mysql_fetch_array($queryasd))
{
 
$id = $row['ID'];
$nume = $row['nume'];
$baza=  addslashes($row['poza']);
$poza= "creeaza/" . $baza;
 
echo '<table width="100" border="0" cellspacing="0" cellpadding="0" style="float: left;">
                  <tr>
                    <td>
                      <div align="center">';
                 echo '<INPUT TYPE=RADIO NAME="rad" VALUE="' . $nume . '">' . $nume . '<BR>';
               echo '</div>
                    </td>
                    <td rowspan="2">&nbsp;</td>
                  </tr>
                  <tr>
                    <td>';
               echo "<div align=\"center\"><img src=\"$poza\"";
               echo ' alt="" width="112" height="112" /><br /></td></div></tr></table>';
 
}
           
?>
                  <input type="submit" name="creeaza_submit" id="creeaza_submit" value="CREEAZA" />
                </form>
 
creeaza_tot.php

Code: Select all

<?php
include('include/connection.php');
 
$numee = $_POST['rad'];
$pozaa = $_POST['poza'];
 
 
$query="INSERT INTO creeaza (nume_guler,poza_guler) VALUES ('$numee','$pozaa');";
mysql_query($query) or die ('Eroare la adaugat');
 
echo "<a href=creeaza.php>";
echo "APASA AICI - click aici";
echo "</a>";
 
?>
All i want is to look like this:

Image

And when i press "creeaza" to put the name tes2 and the picture for tes2 in the creeaza table.

PS:

I have 2 tables :

1. creeaza_tip_guler [ID,nume,poza]
2. creeaza [ID, nume_guler , poza_guler]

How can i make those radio buttons , to show in the creeaza table the correct picture for respective name and radio button?

Please , anybody!
Last edited by killbaz on Mon Feb 02, 2009 6:13 pm, edited 1 time in total.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Re: Radio Buttons with image

Post by Citizen »

How can i make those radio buttons , to show in the creeaza table the correct picture for respective name and radio button?
What part of that are you having trouble with?
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Re: Radio Buttons with image

Post by killbaz »

Example , i select TES2 .
When i press "creeaza" , in the creeaza table , he only puts the name [tes2]
How can i make this script to put the correct image for tes2 in creeaza table?

PS:
Please ,can you test this script? to see what's the problem?
Attachments
please_test.rar
The above script with database!
(16.58 KiB) Downloaded 32 times
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Re: Radio Buttons with image

Post by Citizen »

You're not going to be able to store the actual picture (without going overboard) in the database, if that's what your asking. If you're asking about storing the image location and filename, just assign the location/name to a variable and store it in the db as you would anything else. (or give you pictures ids, etc)

Also please use code=php in your code tags for your forum posts.
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Re: Radio Buttons with image

Post by killbaz »

Citizen wrote:You're not going to be able to store the actual picture (without going overboard) in the database, if that's what your asking. If you're asking about storing the image location and filename, just assign the location/name to a variable and store it in the db as you would anything else. (or give you pictures ids, etc)

Also please use code=php in your code tags for your forum posts.
Ok, but if i give id to pictures , how he will understand i select something, how the script will know the selected radio button is for the correct picture?
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Re: Radio Buttons with image

Post by Citizen »

I'm saying something like this:

Code: Select all

 
<input type='hidden' name='image' value='images/image1.gif'>
 

Code: Select all

$img = $_POST['image'];
// now store it
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Re: Radio Buttons with image

Post by killbaz »

i worked somehow ... but
if i select tes2 or just test it result the same image [if i select test or tes2 the name of last image from creeaza_tip_guler table will show in creeaza table [poza column] ]

I need somehow to unite the radio button with the picture for the same form , so the selection will be perfect. if you know what i mean ... please test the script and you will see what i mean.

thanks
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Re: Radio Buttons with image

Post by killbaz »

Citizen wrote:I'm saying something like this:

Code: Select all

 
<input type='hidden' name='image' value='images/image1.gif'>
 

Code: Select all

$img = $_POST['image'];
// now store it
how can i make the image part of the radio button?
killbaz
Forum Newbie
Posts: 12
Joined: Mon Feb 02, 2009 4:44 pm

Re: Radio Buttons with image

Post by killbaz »

Oh, btw, can anyone test the script to see what i meant to say?

here it is:

download/file.php?id=445
Post Reply