Jump to content
php.lv forumi

php + javascript


snach15

Recommended Posts

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 by snach15
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by snach15
Link to comment
Share on other sites

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 ...

Link to comment
Share on other sites

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 by indoom
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...