/    Sign up×
Community /Pin to ProfileBookmark

radio buttons Passing val to database

[code=php]<?php
if (!empty($_GET[‘id’])) {
$id = ($_GET[‘id’]);

if (isset($_POST[‘submit’])) {
$sql=”SELECT * from `images` WHERE `list_id` = ‘”.$id.”‘ ORDER BY `sub_cat` ASC “;
$result = @mysql_query($sql);
if ($result) {

while ($row = mysql_fetch_assoc($result)) {
$pic_id = $row[‘img_id’];
$desc = $_POST[”.$pic_id.’pic_desc’];

$default = $_POST[‘default[‘.pic_id.’]’];

if ($default == 1){
$sub_cat = $default;
}
if (sub_cat1 > 1){
$sub_cat = $sub_cat1
}

$pic_cat=”UPDATE `images` SET `sub_cat`='”.$sub_cat.”‘, `desc` ='”.$desc.”‘ WHERE `img_id`='”.$pic_id.”‘ “;
$pic_result= @mysql_query($pic_cat);
}

?>[/code]

later in the script i have a form that has imges pulled along with their categories….default, inside, outside, blue print

[code=php]<?php
$sql=”SELECT * from `images` WHERE `list_id` = ‘”.$id.”‘ ORDER BY `sub_cat` ASC LIMIT 0, 30″;
$result = @mysql_query($sql);
if ($result) {
while ($row = mysql_fetch_assoc($result)) {

$pic_id = $row[‘img_id’];
if ($row[‘sub_cat’] == ‘1’) { $def_status = ‘checked=”checked”‘; }
elseif ($row[‘sub_cat’] == ‘2’) { $ins_status = ‘checked=”checked”‘; }
elseif ($row[‘sub_cat’] == ‘3’) { $out_status = ‘checked=”checked”‘;}
elseif ($row[‘sub_cat’] == ‘4’) { $blue_status = ‘checked=”checked”‘;
}?>
<table width=”100&#37;” border=”0″>
<tr>
<td width=”47%” valign=”top” class=”form_text”><img src=”../../images/house/<?php echo “”.$id.”/”.$row[‘image’].”” ?>” width=”175″ ></td>
<td width=”23%” valign=”top” nowrap=”nowrap” class=”form_text”>
<input type=”radio” name=”<?php echo ‘default[‘.pic_id.’]’;?>” onclick=”setDisplay(‘<?php echo $pic_id.’setA’;?>’)” value=”1″ <?PHP print $def_status; ?> />Default<br />
<div id=”<?php echo $pic_id.’setA’; ?>” class=”setDiv”>
<input type=”radio” name=”<?php echo ‘set1[‘.$pic_id.’]’; ?>” value=”2″ <?PHP print $ins_status; ?>/>Inside<br />
<input type=”radio” name=”<?php echo ‘set1[‘.$pic_id.’]’ ?>” value=”3″ <?PHP print $out_status; ?>/>Outside<br />
<input type=”radio” name=”<?php echo ‘set1[‘.$pic_id.’]’ ?>” value=”4″ <?PHP print $blue_status; ?>/>Blue Print<br />
</div>
</td>
<td width=”30%” align=”left” valign=”top” class=”form_text”>
<textarea name=”<?php echo $pic_id.’pic_desc’;?>” cols=”30″ rows=”5″></textarea>
</td>
</tr>
<tr>
<td colspan=”3″ valign=”top” ><hr /></td>
</tr>
</table>
[/code]

The only thing that passes correctly is the desc short description of the pictures….

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ebarauthorMay 31.2009 — heh.... messed up in my typing forgot that i had made the var $sub_cat1

so in the top part it should be
[code=php]<?php

if (!empty($_GET['id'])) {
$id = ($_GET['id']);


if (isset($_POST['submit'])) {
$sql="SELECT * from images WHERE list_id = '".$id."' ORDER BY sub_cat ASC ";
$result = @mysql_query($sql);
if ($result) {

while ($row = mysql_fetch_assoc($result)) {
$pic_id = $row['img_id'];
$desc = $_POST[''.$pic_id.'pic_desc'];
$sub_cat1 = $_POST['set1['.pic_id.']'];
$default = $_POST['default['.pic_id.']'];

if ($default == 1){
$sub_cat = $default;
}
if (sub_cat1 > 1){
$sub_cat = $sub_cat1;
}

$pic_cat="UPDATE images SET sub_cat='".$sub_cat."', desc ='".$desc."' WHERE img_id='".$pic_id."' ";
$pic_result= @mysql_query($pic_cat);
}


?>[/code]


[/quote]


What i get obviously is that every default is set to 1 and every sub_cat is of course 1...
Copy linkTweet thisAlerts:
@ebarauthorJun 01.2009 — aw i know it can be done some how i may just have it set up wrong.... Did i mention i really don't like arrays especially complecated ones like this.
Copy linkTweet thisAlerts:
@ebarauthorJun 01.2009 — any ideas/direction right now would be better than nothing ? i about to pull my hair out over this one..?
Copy linkTweet thisAlerts:
@ebarauthorJun 01.2009 — ok i got the default to work correctly... just have to work on each images category otherwise... here is what i got

[code=php] if (isset($_POST['submit'])) {

$sql="SELECT * from images WHERE list_id = '".$id."' ORDER BY sub_cat ASC ";
$result = @mysql_query($sql);
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$pic_id = $row['img_id'];
$default = $_POST['default'];
if ($default == $pic_id) {
$sub_cat = "1";
echo 'The Default is:'.$pic_id.' set to '.$sub_cat.'<br />';
} else {
/*need to work on this section
$sub_cat = $_POST['set1['.$pic_id.']'];
echo 'The picture is:'.$pic_id.' set to'.$sub_cat.'<br />';*/
}
} [/code]

in the form i changed it to...
[code=php]<input type="radio" name="default" onclick="setDisplay('<?php echo $pic_id.'setA';?>')" value="<?php echo $pic_id; ?>" <?PHP print $def_status; ?> />Default<br />[/code]
Copy linkTweet thisAlerts:
@ebarauthorJun 01.2009 — i got it!!! i will post for future use by others and close this thread...
×

Success!

Help @ebar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...