Page 1 of 1

Radio Buttons with image

Posted: Mon Feb 02, 2009 4:53 pm
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!

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 5:56 pm
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?

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 6:04 pm
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?

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 6:11 pm
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.

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 6:15 pm
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?

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 6:20 pm
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

Re: Radio Buttons with image

Posted: Mon Feb 02, 2009 6:31 pm
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

Re: Radio Buttons with image

Posted: Tue Feb 03, 2009 3:19 am
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?

Re: Radio Buttons with image

Posted: Tue Feb 03, 2009 5:00 am
by killbaz
Oh, btw, can anyone test the script to see what i meant to say?

here it is:

download/file.php?id=445