snach15 Posted September 29, 2010 Report Share Posted September 29, 2010 (edited) aizķēros aiz vienas problēmas .. lūk kad izpilda funkciju mssql_query("UPDATE MEMB_INFO SET Warnings = Warnings - [warnings] WHERE MEMB___ID = '$login'"); mssql_query("UPDATE MEMB_INFO SET Credits = Credits - [crediti] WHERE MEMB___ID = '$login'"); kā var pievienot attiecīgi [warning] vietā <option value="3">10</option> un [crediti] vietā var values = {0: "", 1: "10", 2: "50", 3: "100", 4: "200", 5: "500", 6: "1000"}; <? $login = $_SESSION['user']; $warning = mssql_query("Select Warnings from MEMB_INFO where MEMB___ID ='$login'"); $warning = mssql_fetch_row($warning); $warning = $warning[0]; ?> <table class="sort-table" width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <thead> <tr> <td width="" align="center">Accounts</td> <td width="100" align="center">Your Warnings</td> <td width="110" align="center">Warning Points</td> <td width="60" align="center">Credits</td> <td width="60" align="center">Done</td> </tr> </thead> <tbody> <tr> <td align="center"><? print $login?></td> <td align="center"><? print $warning ?></td> <td align="center"><form name="form3" method="post" action=""> <label> <select name="foo" onchange="put(this.value);"> <option value="0">Select</option> <option value="1" >1</option> <option value="2">5</option> <option value="3">10</option> <option value="4">20</option> <option value="5">50</option> <option value="6">100</option> </select> <script type="text/javascript"> var values = {0: "", 1: "10", 2: "50", 3: "100", 4: "200", 5: "500", 6: "1000"}; function put(key){ document.getElementById("bar").innerHTML = values[key]; } </script> <br> </label> </form> </td> <td align="center"><span id="bar"></span></td> <td align="center"><form method="post" action=""> <label> <input type="hidden" name="username" value="<? print $login?>"> <input type="submit" value="Submit" /> </label> </form></td> </tr> </tbody> </table> <p> </p> <? if (isset($_POST['username'])) { mssql_query("UPDATE MEMB_INFO SET Warnings = Warnings - [warnings] WHERE MEMB___ID = '$login'"); mssql_query("UPDATE MEMB_INFO SET Credits = Credits - [crediti] WHERE MEMB___ID = '$login'"); echo "succes";} Edited September 29, 2010 by snach15 Quote Link to comment Share on other sites More sharing options...
indoom Posted September 29, 2010 Report Share Posted September 29, 2010 uztaisi tajā username vēl vienu hidden lauku, kurā ar put funkciju ieliec izvēlēto value un tad $foo = intval($_POST['vajadzīgais_value']) Vai arī ieliec visu tabulu <form></form>, tad selects nopostosies ar visu username Pašlaik no pirmās formas arī nav nekāda jēga, ja netaisies to postot Quote Link to comment Share on other sites More sharing options...
snach15 Posted September 29, 2010 Author Report Share Posted September 29, 2010 (edited) nu itkā vis būtu ok tik nesaprotu par to PUT ... ko tālāk ? neiebraucu kā lai dabodu to rezultātu attiecīgi pie kredītiem un warningiem <? $login = $_SESSION['user']; $warning = mssql_query("Select Warnings from MEMB_INFO where MEMB___ID ='$login'"); $warning = mssql_fetch_row($warning); $warning = $warning[0]; $foo = intval($_POST['value']) ?> <table class="sort-table" width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <thead> <tr> <td width="" align="center">Accounts</td> <td width="100" align="center">Your Warnings</td> <td width="110" align="center">Warning Points</td> <td width="60" align="center">Credits</td> <td width="60" align="center">Done</td> </tr> </thead> <tbody> <tr> <td align="center"><? print $login?></td> <td align="center"><? print $warning ?></td> <td align="center"><form name="form" method="post" action=""> <label> <select name="foo" onchange="put(this.value);"> <option value="0">Select</option> <option value="1" >1</option> <option value="2">5</option> <option value="3">10</option> <option value="4">20</option> <option value="5">50</option> <option value="6">100</option> </select> <script type="text/javascript"> var values = {0: "", 1: "10", 2: "50", 3: "100", 4: "200", 5: "500", 6: "1000"}; function put(key){ document.getElementById("bar").innerHTML = values[key]; } </script> <br> </label> </td> <td align="center"><span id="bar"></span></td> <td align="center"> <label> <input type="hidden" name="username" value="<? print $login?>"> <input type="hidden" name="value"> <input type="submit" value="Submit" /> </label> </form></td> </tr> </tbody> </table> <p> </p> <? if (isset($_POST['username'])) { mssql_query("UPDATE MEMB_INFO SET Warnings = Warnings - [warnings] WHERE MEMB___ID = '$login'"); mssql_query("UPDATE MEMB_INFO SET Credits = Credits - [crediti] WHERE MEMB___ID = '$login'"); echo "succes";} ?> Edited September 29, 2010 by snach15 Quote Link to comment Share on other sites More sharing options...
indoom Posted September 29, 2010 Report Share Posted September 29, 2010 Ja drīkst zināt, kā šito jau esošo uzrakstīji? Quote Link to comment Share on other sites More sharing options...
snach15 Posted September 29, 2010 Author Report Share Posted September 29, 2010 javascript pats nerakstīju jo pagaidām man no viņa ir 0 saprašana .. vismaz kādu piemēru uzraksti lai saprotu kā tam aptuveni jāizsakātās .. tālāk jav pats sakodēšu kā vajadzēs bet es to pašu principu nesaprotu kā to paveikt ... Quote Link to comment Share on other sites More sharing options...
indoom Posted September 29, 2010 Report Share Posted September 29, 2010 (edited) Kas ir formas, kā formas postojas, un kas ir $_POST dati vispār saproti? Princips ir <form action="" method="post"> <table><tr><td> <select name="foo" onchange="put(this.value);"> <option value="0">Select</option> <option value="1" >1</option> <option value="2">5</option> <option value="3">10</option> <option value="4">20</option> <option value="5">50</option> <option value="6">100</option> </select> <input type="hidden" name="username" value="<?php echo $login; ?>"> <input type="submit" value="Submit" /> </td></tr></table> </form> un php pusē <?php if (isset($_POST['username']) && $_POST['username'] == $login) { $kreditu_arrays = array(0, 10, 50, 100, 200, 500, 1000); $warnings = isset($_POST['foo']) && isset($kreditu_arrays[$_POST['foo']) ? intval($_POST['foo']) : 0; $krediti = isset($kreditu_arrays[$warnings]) ? $kreditu_arrays[$warnings] : 0; $safe_login = mysql_real_escape_string($login); mssql_query("UPDATE MEMB_INFO SET Warnings = Warnings - $warnings WHERE MEMB___ID = '$safe_login'"); mssql_query("UPDATE MEMB_INFO SET Credits = Credits - $krediti WHERE MEMB___ID = '$safe_login'"); } ?> klienta pusē nelikt nekādus lielumus, ko var lietotājs nomainīt un iesūtīt savus. Visām pieskaitīšanām, izmēriem, jābūt servera pusē. Edited September 29, 2010 by indoom Quote Link to comment Share on other sites More sharing options...
snach15 Posted September 29, 2010 Author Report Share Posted September 29, 2010 tagad itkā vis būtu kārtībā .. bet atkal problēma tajā kad credītus noņem tik cik vajg bet warningus nepareizi atskaita .. ja piemēram paņemu ceturto optionu tad arī atskaita četrus .. Quote Link to comment Share on other sites More sharing options...
indoom Posted September 29, 2010 Report Share Posted September 29, 2010 tur pieliec vēlvienu arrayu ar warningu lielumiem (pēc $safe_login rindas ieliec $warningu_arrays = array(0, 1, 5, 10, 20, 50, 100); $safe_warnings = $warningu_arrays[$warnings]; // attiecīgi mssql_query("UPDATE MEMB_INFO SET Warnings = Warnings - $safe_warnings WHERE MEMB___ID = '$safe_login'"); Quote Link to comment Share on other sites More sharing options...
snach15 Posted September 29, 2010 Author Report Share Posted September 29, 2010 Liels tev paldies Quote Link to comment 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.