select help..

hey guys im going nuts with this script!!lol

i have a script that pulls images from a database for the client to chose witch one he wants.

now i have a radio button next to the image in a form.that part is cool…the only thing is the script that gets the image name and inserts in the DB that does not get the image name…here is the script
select the image

<? $dbh = mysql_connect("localhost","_","tr") or die("There was a problem with the database connection.");
$dbs = mysql_select_db("techker_gymgraph", $dbh) or die("There was a problem selecting the categories.");


$sql = "SELECT * 
FROM `gymball` 
WHERE `type` = '$type' ";

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<form action="add_pic1.php" method="post">
<p align="center"><u>S?lectionner UNE photo</u></p>
<table width="346" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><? while($row = mysql_fetch_array($fileLIST)) { ?>
<td width="173"><?php echo '<a href="/Gymgraph/Gymgraph/gymball/'. $row['name'] .'" target="_blank">
<img src="/Gymgraph/Gymgraph/gymball/'. $row['name'] .'" border="0" alt="" width=115/>
<br />'; ?></td>
<td width="173"><label>
<input type="checkbox" name="pic" id="pic" value='<? $row['name'] ?>'/></label>
Selection de photo </label>
<input type="hidden" name="name" id="name" value='<? echo $row['name'] ?>'/>
<input type="hidden" name="ex" id="ex" value='gymball'/>

<? } ?>
<div align="center">
<select name="location" id="location">
<option value="pic1">1</option>
<option value="pic2">2</option>
<option value="pic3">3</option>
<option value="pic4">4</option>
<option value="pic5">5</option>
<option value="pic6">6</option>
<option value="pic7">7</option>
<option value="pic8">8</option>
Emplacement de la photo


<div align="center">
<input type="submit" name="submit" id="submit" value="Submit" />
<div align="center"> 
<p>Envoyer la s?lection </p>
<p><img src="pics/gymgraph_loc.jpg" width="629" height="383" /> </p>

now the add pic



mysql_connect("localhost", "", "tr") or die(mysql_error()) ;
mysql_select_db("techker_gymgraphpics") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO $location (exercice,name) ".
"VALUES ('$exercice','$name')");

//Tells you if its all ok
$id= mysql_insert_id();
echo "<p>This file has the following Database ID: <b>$id</b>";
echo "You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=type.php>";


the part i dont grab is the one were the add_pic1.php grabs the radio button selection and inserts the name of the pic i selected…

First of all, do something about your security. This script is open to SQL injection for example.

Secondly, I see you looping through your radio buttons with two hidden inputs. Radio buttons can be duplicated, but hiddens cannot. The reason is that a hidden input is a solid input, whereas a radio button is actually a single element in an imaginary input that encompasses all radio buttons by the same name (much like an is an element in a input). Don’t create multiple inputs by the same name -> get your hidden inputs out of the loop.

Concerning the following line of code:


I presume you’ll want to remove the [0] since it serves no purpose. Furthermore, I don’t see you using the variable $pic in the rest of your code.

yap i wasn’t inserting the pic name in the database…i was using the name variable not pic…


Sponsor our Newsletter | Privacy Policy | Terms of Service