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.");

$type=$_POST['type'];


$sql = "SELECT * 
FROM `gymball` 
WHERE `type` = '$type' ";
$fileLIST=mysql_query($sql);
$file=$row['name'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GymGraph</title>
</head>

<body>

<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/>
</a> 
<br />'; ?></td>
<td width="173"><label>
<input type="checkbox" name="pic" id="pic" value='<? $row['name'] ?>'/></label>
Selection de photo </label>
<label>
<input type="hidden" name="name" id="name" value='<? echo $row['name'] ?>'/>
<input type="hidden" name="ex" id="ex" value='gymball'/>
</label></td>

<? } ?>
</table>
<p>
<p>
<label>
<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>
</select> 
Emplacement de la photo

</label>

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

now the add pic

<?php

$pic=$_POST['pic'][0]; 
$location=$_POST['location'];
$name=$_POST['name'];
$exercice=$_POST['ex'];


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:

$pic=$_POST['pic'][0]; 

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…

thx!

Sponsor our Newsletter | Privacy Policy | Terms of Service