What seems to be a relatively minor coding issue is giving me a massive headache. I currently have a set up that grabs from my SQL database information about services (it's ID, name, a file location for company logo, and a click location) and throws it into an array.
$qry = mysql_query(sprintf("SELECT * FROM manageme WHERE element IN ('%s')", $element));
$count = 0;
while (($services = mysql_fetch_array($qry)) != null && $count < 52) { $count++;?>
<li>
<a href="">
<img src="<?php print $services['fileLocation']; ?>";
title="<?php print $services['title']; ?>";
name="<?php print $services['clickLocation']; ?>";
alt="wat"
class="btnshow" />
</a>
Right now, everything displays as I would like it to, that's not my issue. I'm trying to add a button that displays under each company logo that would on click insert the corresponding ID from each value that the array displays into a different MySQL table, coupled with the logged in user's $_COOKIE['user_id'].
<?PHP
$sql= sprintf("INSERT INTO user_service (user_id, service_id)
VALUES (%s, %s);", mysql_real_escape_string($_COOKIE['user_id']),
mysql_real_escape_string($gotcha));
$result=mysql_query($sql);
if($result) {
echo "YESSSS!!!!!!!!";
}else{
echo "NOOOOO!!!!!";
}
?>
<form id="button" method="POST">
<fieldset>
<input type="submit" value="Add" name="button" />
</fieldset>
</form>
When I attempt this, clicking the button currently INSERT's a record for every ID recognized from the table referenced in the array. So, if there are 20 ID's in the table, upon attempting to insert (108, 1) , it will also insert (108, 2), (108, 3)...and so on. Basically clicking on one button inserts an ID value from every row recognized in the array when I'm only trying to INSERT the current value of the array. Any help would be greatly appreciated, I'm about to pull my hair out!