acidpunk Posted September 18, 2012 Share Posted September 18, 2012 Hello everyone hows everyone's night.. I'm coding this page basically a 'vault', storing inventory. Basically in this vault, i'm using Javascript to act like a checkbox (so when you click the images) it checks off the item. The end result is, your supposed to be able to re-ward these inventory items to other members in you're group. Now, i'm running into a problem with the reward aspect. I get all the inventory ID'S to show up (using an onmousover as my test to make sure the id's are correct) however; during my award, i can't seem to get it to run properly. I've rescripted it 4 times, nothing will work. <?php <?php if($_POST["submit"] == "Award") { $sec_answer = mysql_real_escape_string($_POST['answer']); $user_answer = $stat[sec_answer]; if ($sec_answer != $user_answer) { echo "<script>alert(\"Your security answer did not match. Please try again.\");</script>"; } else { $count = 0; $selected_item = mysql_fetch_array($_POST['v_selected_$count']); $award = mysql_fetch_array ( mysql_query ( "SELECT * FROM user_equipment WHERE crew = $stat[crewid]" ) ); $award_itemname = $award['name']; $award_itemid = $award['id']; if($selected_item == $award_itemid) { /* lazy fetch just to see if it works */ $award_username = mysql_real_escape_string($_POST['username']); $user = mysql_fetch_array ( mysql_query ( "SELECT * FROM users WHERE id = '$award_username'") ); $username = $user['name']; $userid = $user['id']; $date = date("M/d/Y g:iA"); mysql_query("insert into award_log (crew, log, date) values($stat[crewid],'<font color=#949477>$stat[name] Gave ".$award_itemname." to ".$username.".</font>','".$date."')"); mysql_query("UPDATE user_equipment SET owner = '$userid', crew='0' where id = '$award_itemid'") or die ( mysql_error ()); echo "Item Awarded."; } else { echo "something wen't wrong."; } $count++; } } what ends up happening is, it chooses the wrong item being awarded. my checkbox name is 'v_selected_$count' the value is $itemid. cannot get it to work :/ help please would be great, some type of guidence, someone work with me, i'd love it! hehe Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/ Share on other sites More sharing options...
kicken Posted September 18, 2012 Share Posted September 18, 2012 Name your checkbox v_selected[] that way on the PHP side you have an array. That will make it easier to process. Also $_POST['v_selected_$count'] is not going to work right. Variables are not translated when inside single-quoted strings so you are looking for a posted item named quite literally 'v_selected_$count' rather than 'v_selected_0' as you intend. Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378804 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 I re-modified my code a bit <?php if($_POST["submit"] == "Award") { $sec_answer = mysql_real_escape_string($_POST['answer']); $user_answer = $stat[sec_answer]; if ($sec_answer != $user_answer) { echo "<script>alert(\"Your security answer did not match. Please try again.\");</script>"; } else { $count = 0; $crewid = $stat['crewid']; $crew_vault_award_result = mysql_query("select * from user_equipment where crew = '$crewid' order by `name` ASC")or die(mysql_error()); while($row = mysql_fetch_array($crew_vault_award_result)) { $item_name = $row["name"]; $item_id = $row["id"]; $award_target_id = mysql_real_escape_string($_POST["username"]); $award_name_result = mysql_query("select * from `users` where id = $award_target_id")or die(mysql_error()); $award_user = mysql_result($award_name_result,0,"name"); if($_POST["v_selected_$count"] == "$item_id") { $date = date("M/d/Y g:iA"); mysql_query("insert into award_log (crew, log, date) values($stat[crewid],'<font color=#949477>$stat[name] Gave ".$item_name." to ".$award_user.".</font>','".$date."')"); mysql_query("UPDATE user_equipment SET owner = '$_POST[username]', crew='0' where id = '$item_id'") or die ( mysql_error ()); echo "succeed."; } else { echo "error."; } $count++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378805 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 I actually noticed the single quotes I had in there, exactly what you were talking about, will the "" work? thats what I had changed them too in my modified version. Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378806 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 Well, my modified code got it to work, now for testing if multiple (checks will pass off!) wow. I always do this to myself, think i'm stranded, try again, and find my problems. You're fast bro, you noticed the "" quick Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378809 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 Ok, now for the last part. How can I get it to when I echo out the results, to not echo out results for all the items stored in this. I only wan't the selected ones to echo. Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378811 Share on other sites More sharing options...
kicken Posted September 18, 2012 Share Posted September 18, 2012 You'd need a condition where if the item is not selected, do not do anything. If you change your variable to an array as I mentioned before it'll make the process easier because you could just loop the array of selected items rather than have to loop over everything. Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378822 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 I see what you're saying. I'm still only a few years into this gig, I still take the paths I know. Could you guide me as an example? foreach ($item_id as $value) { echo $value; echo "<br/>"; } if i did it like that would it work? Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378824 Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Author Share Posted September 18, 2012 Also, i very much appreciate you're responses kicken. Quote Link to comment https://forums.phpfreaks.com/topic/268489-stuck-on-something-2nd-eye-please/#findComment-1378825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.