count usage

Now it’s all crystal clear on what you are trying to do. It really helps to have the full code and a screen shot to go along with it.

I’m assuming the ID field is a numeric column of some kind in the database. After it updates the table I’m not sure what you want it to do, looks like you got a piece of it commented out.

So it should just reload the updated information.

[php] <?php
session_start();
if(isset($_SESSION[‘user’]) && !empty($_SESSION[‘user’])){
echo "Welcome ". $_SESSION[‘user’];

//include 'tabmenuOneForAll.php';

?>

<?php include 'config.php'; mysql_connect($server,$db_user,$db_pass); if (isset($_POST['upload'])) { $user_id = $_POST['user_id']; $company_address = $_POST['company_address']; $tel = $_POST['tel']; $mobile = $_POST['mobile']; $incharge = $_POST['incharge']; $email = $_POST['email']; $update = "UPDATE customer SET company_address = '{$company_address}', tel = '{$tel}', mobile = '{$mobile}', incharge = '{$incharge}', email = '{$email}' WHERE id = {$user_id}"; $result_update = mysql_query($update); echo $result_update; //header("Location: edit_client.php?update=".$result_update.""); //var_dump($result_update); exit; //echo "
Files updated
"; //setting $id to the user that was just updated. $id = $user_id } else $id = $_GET['id']; } $query = "SELECT * FROM customer WHERE id = {$id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //header("Location: edit_client.php?update=".$result.""); //header("Location: view_client.php"); ?>
      <tr>
        <td></td>
        <td align="right"><input type="submit"  name="upload" value="upload"></td>
      </tr>
id :
Customer ID :
Name :
Address:
Phone Number:
Mobile:
Person In Charge:
E-mail:
<?php }else{ header("location:login.php"); } ?>[/php]

[php] $id = $user_id
} else
$id = $_GET[‘id’];
}[/php]

[php] $id = $user_id;
} else{
$id = $_GET[‘id’];
}[/php]

is the bracket is left out and the ; is left out also. so i add in but still the same. the data is not updated …

i do hv id column which is numeric and auto increament when adding new client

After:

[php] $update = “UPDATE customer SET company_address = ‘{$company_address}’, tel = ‘{$tel}’, mobile = ‘{$mobile}’, incharge = ‘{$incharge}’, email = ‘{$email}’ WHERE id = {$user_id}”;
[/php]

Add

[php]echo $update;
exit;[/php]

What does the output say?

Welcome admin UPDATE customer SET company_address = 'qwrwqr', tel = 'qwr', mobile = '', incharge = '', email = '' WHERE id = 

but the update statement is wrong right??? WHERE id should be WHERE user_id right cause my user_id is unique

but ,now the error code also the same with a warning

[php]Welcome admin UPDATE customer SET company_address = ‘asfasf’, tel = ‘’, mobile = ‘’, incharge = ‘’, email = ‘’ WHERE user_id =
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sth_inventory\html\edit_client.php on line 43[/php]

Coding without being able to test it is not fun!

Try the below…

[php] <?php
session_start();
if(isset($_SESSION[‘user’]) && !empty($_SESSION[‘user’])){
echo "Welcome ". $_SESSION[‘user’];

  	//include 'tabmenuOneForAll.php';
  ?>
  
  <?php

include 'config.php';

mysql_connect($server,$db_user,$db_pass);

if (isset($_POST['upload'])) {

$user_id = $_POST[‘user_id’];
$company_address = $_POST[‘company_address’];
$tel = $_POST[‘tel’];
$mobile = $_POST[‘mobile’];
$incharge = $_POST[‘incharge’];
$email = $_POST[‘email’];

$update = "UPDATE customer SET company_address = '{$company_address}', tel = '{$tel}', mobile = '{$mobile}', incharge = '{$incharge}', email = '{$email}' WHERE id = {$user_id}";

$result_update = mysql_query($update);
echo $result_update;
//header("Location: edit_client.php?update=".$result_update."");

//var_dump($result_update); exit;
//echo "<br>Files updated<br>";
 //setting $id to the user that was just updated. 
$id = $user_id; 

} else
$id = $_GET[‘id’];
}

$query = "SELECT * FROM customer WHERE id = {$id}"; 
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

//header("Location: edit_client.php?update=".$result."");

//header("Location: view_client.php");
?>

<form method="post" action="edit_client.php" />
<center>
<table>
<tr>
<td>id :</td>
<td><input name="checkbox_id" type="checkbox" id="checkbox_id" value="<?php echo $row['id'] ?>" checked = "checked" disabled = "disabled"></td>
</tr>
<tr>
<td>Customer ID :</td>
<td><input type="text" name="user_id"  size="20" value="<?php echo $row['id'] ?>" disabled = "disabled"></td>
</tr>

<tr>
<td>Name :</td>
<td><input type="text" name="company_name" size="20" value="<?php echo $row['company_name'] ?>" disabled = "disabled"></td>
</tr>

<tr>
<td>Address:</td>
<td><input type="text" name="company_address" size="60" value="<?php echo $row['company_address'] ?>"></td>
</tr>

<tr>
<td>Phone Number:</td>
<td><input type="text" name="tel" size="20" value="<?php echo $row['tel'] ?>"></td>
</tr>

<tr>
<td>Mobile:</td>
<td><input type="text" name="mobile" size="20" value="<?php echo $row['mobile'] ?>"></td>
</tr>

<tr>
<td>Person In Charge:</td>
<td><input type="text" name="incharge" size="20" value="<?php echo $row['incharge'] ?>"></td>
</tr>

<tr>
<td>E-mail:</td>
<td><input type="text" name="email" size="20" value="<?php echo $row['email'] ?>"></td>
</tr>

        <tr>
          <td></td>
          <td align="right"><input type="submit"  name="upload" value="upload"></td>
        </tr>
</table>
</center>
</form>

<?php	

}else{
header(“location:login.php”);
}

?>[/php]

[php]

<?php session_start(); if(isset($_SESSION['user']) && !empty($_SESSION['user'])){ echo "Welcome ". $_SESSION['user']; //include 'tabmenuOneForAll.php'; ?>
     <?php
  
  include 'config.php';
  
  mysql_connect($server,$db_user,$db_pass);
  
  if (isset($_POST['upload'])) {
    
              
  
 $user_id = $_POST['user_id'];
  $company_address = $_POST['company_address'];
  $tel = $_POST['tel'];
  $mobile = $_POST['mobile'];
  $incharge = $_POST['incharge'];
  $email = $_POST['email'];
  
  $update = "UPDATE customer SET company_address = '{$company_address}', tel = '{$tel}', mobile = '{$mobile}', incharge = '{$incharge}', email = '{$email}' WHERE id = {$user_id}";
  
  $result_update = mysql_query($update);
  echo $result_update;
  //header("Location: edit_client.php?update=".$result_update."");
  
  //var_dump($result_update); exit;
  //echo "<br>Files updated<br>";
   //setting $id to the user that was just updated. 
  $id = $user_id; 
} else{
  $id = $_GET['id']; 
 }

  $query = "SELECT * FROM customer WHERE id = {$id}"; 
  $result = mysql_query($query);
  $row = mysql_fetch_assoc($result);

  //header("Location: edit_client.php?update=".$result."");
  
  //header("Location: view_client.php");
  ?>
  
  <form method="post" action="edit_client.php" />
  <center>
  <table>
  <tr>
  <td>id :</td>
  <td><input name="checkbox_id" type="checkbox" id="checkbox_id" value="<?php echo $row['id'] ?>" checked = "checked" disabled = "disabled"></td>
  </tr>
  <tr>
  <td>Customer ID :</td>
  <td><input type="text" name="user_id"  size="20" value="<?php echo $row['id'] ?>" disabled = "disabled"></td>
  </tr>
  
  <tr>
  <td>Name :</td>
  <td><input type="text" name="company_name" size="20" value="<?php echo $row['company_name'] ?>" disabled = "disabled"></td>
  </tr>
  
  <tr>
  <td>Address:</td>
  <td><input type="text" name="company_address" size="60" value="<?php echo $row['company_address'] ?>"></td>
  </tr>
  
  <tr>
  <td>Phone Number:</td>
  <td><input type="text" name="tel" size="20" value="<?php echo $row['tel'] ?>"></td>
  </tr>
  
  <tr>
  <td>Mobile:</td>
  <td><input type="text" name="mobile" size="20" value="<?php echo $row['mobile'] ?>"></td>
  </tr>
  
  <tr>
  <td>Person In Charge:</td>
  <td><input type="text" name="incharge" size="20" value="<?php echo $row['incharge'] ?>"></td>
  </tr>
  
  <tr>
  <td>E-mail:</td>
  <td><input type="text" name="email" size="20" value="<?php echo $row['email'] ?>"></td>
  </tr>
  
          <tr>
            <td></td>
            <td align="right"><input type="submit"  name="upload" value="upload"></td>
          </tr>
  </table>
  </center>
  </form>
  
  <?php	
}else{
header("location:login.php");

}

?>

[/php]

you left out an open bracket on else …

but still the same.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in

this is the error msg

Put the

[php] echo $update;
exit;[/php]

back in and show me the output again

[php] UPDATE customer SET company_address = ‘asfgasgasg’, tel = ‘qweqwe’, mobile = ‘’, incharge = ‘’, email = ‘’ WHERE id = [/php]

still dun hv value on WHERE id

Now I know what it is :confused:

What’s it worth to ya :stuck_out_tongue:

Change:

[php]

/td>[/php]

To:

[php]

/td>[/php]

You can’t read the post of a disabled text box, so we’re going to simulate it…

oh great… is working…

by the way, i would like to ask you readonly style="background:lightgray what is this mean?? pardon me for my low lvl of php knowledge…

That’s not php, its html

readonly makes the field non-editable, meaning you can’t type in it.
style=“background:lightgray” sets the background of the field to gray

oic…

thanks for the answer… it really helps…

anyway, i have a set of question again.

this time is with condition statement.

let me explain abit on what i try to do here.

i have a table with only 7 row of data. So is fix with 7 row. no more nor less.

So, in my display data statement,

there is 2 row i do not want to display it.

so the condition please how i not going to display it the specifix row?

example, i do not want to show row 1 and 7. how i going to make it?

i only manage not to display either row 1 or 7.

so my code is somthing like this

[php]‘conditions’=>"test.id != ‘1’ " [/php]

i nd to add in the row 7 which is the “testid != ‘1’”

i hv try something like this

[php]‘conditions’=>"Game.id != ‘1’ AND ‘7’ " [/php]

[php]‘conditions’=>"Game.id != ‘1’ " AND "Game.id != ‘7’ " [/php]

any suggestion?

Easier to just change your SQL Statement and not pull back the 2 rows you don’t want.

not equal in MySQL is <>, not !=

if you want a php solution, just take out the conditions in the query and do regular if statements, looking for those particular id’s.
[php]
if($row[‘id’] != 1 || $row[‘id’] != 7) {
// display information
}[/php]

It would be simpler to have it in the query though, less code to troubleshoot.

thanks for all your suggestion. im still nd to go with the condition. im using a framework to do it. but i manage to do it using operators. id > 1 and < 7 something like this.

That’s still going to display the records for 1 and 7. Just change the query condition to

conditions = Game.id <> 1 OR Game.id <> 7"

hi… thanks… i have changed it…it works fine…

by the way,

im doing a form which require to multiple 2 column value.

is like quantity X unti price after ther user insert the value instant…

my form is something like this

[code]

[/code]

how to display into the amount column with QTY value X unit_Price value ??
and also total amount on my below???

You want to take unti_price and then multiply it by 2?

[php]$m_unit = $_POST[‘unit_price’] * 2;

[/php]That'll update the box with the doubled figure once the submit button has been pressed.

nop…

is qty * unit_price = amount

so the amount must be instant show the answer when user complete input the field on qty and unit_price.

after i hv look through it seems using javascript is the best way…

[code]
$(function(){
$(‘input’).each(function() {
$(this).keyup(function(){
calculatedis($(this));
});
});
});

      function calculatedis(src) {
      var sub = 0;
      var sumtable = src.closest('.sumtable');
      sumtable.find('tr').each(function() {
          var QTY = parseInt($(this).find('input[name="QTY"]').val());
            var Price = parseInt($(this).find('input[name="Price"]').val());
            sub = (QTY * Price)
        $(this).find('.amount').val(sub);
          });
      sumtable.find(".amount").val(sub.toFixed(2));
      }   
     </script>[/code]

this is how i found and come out with it… but it did not work on my amount field display…

[code]

[/code]
Sponsor our Newsletter | Privacy Policy | Terms of Service