Jump to content

edit a record


Recommended Posts

(feeling a bit difficult to describe)

 

i am trying to edit a post on a mysql table. in it data is transferred from one row to

previous data was recorded for "ID-1" and now data on some cell should be transferred to "ID-2" and that makes change to another table also.

i succeeded to change data on another table and change on "ID-2". but i got difficulties to retrieve "ID-1" to change its value.

 

the edit form is like this ---

<form method ="POST" action="saleseditpost.php"><fieldset><legend><h1>Edit Sales Record</h1></legend><div class="form-field"><label>Customer Name:</label><select name="cname" id="cname"><option></option>	<?php    // select table	$query = "SELECT * FROM customer";	$result = mysql_query($query);		if (!$result) die("Unable to select database: " . mysqli_error());		// fetch data	$rows = mysql_num_rows($result);	for ($n = 0 ; $n < $rows ; ++$n)	{		echo "<option>" . mysql_result($result,$n,'cname') . "</option>" ;	}	?></select>    </div>    <div class="form-field">    	<label>S.N.: </label>		<input type="text" name="sn" id="sn" value="<?php echo $rs-> sn ?>" readonly="readonly">    </div>    <div class="form-field">        <label for="date">Date: </label>        <input type="text" name="date" id="date" value="<?php echo $rs-> date ?>">    </div>    <div class="form-field">    	<label for="ref">Ref.No.: </label>        <input type="text" name="ref" id="ref" value="<?php echo $rs-> ref ?>">    </div>    <div class="form-field">    	<label for="amt">Bill Amount: </label>        <input type="text" name="amt" id="amt" value="<?php echo $rs-> amt ?>">    </div>    <div class="form-field">    	<input type="submit" value="EDIT" name="submit" id="submit">    </div></fieldset></form> 

the name selected from the <select> option is "ID-2".

data retrieved through "$rs->" is for "ID-1". now when the edit form is submitted input name - "amt" is stored for "ID-2" and previous data "$rs-> amt" must be erased from "ID-1". i succeeded to store input "amt" to ID-2 but not succeeded to erase that from ID-1. actually i could not retrieve ID-1

 

i want to learn how to grab that previous ID?

 

i used action script like this ---

// grab cid from cname$resultcid = mysql_query("SELECT cid	FROM customer WHERE cname = '$cname'");$rowcid = mysql_fetch_array($resultcid);$cid = $rowcid['cid'];// grab balance from customer$chkBal = "SELECT * FROM customer WHERE cname = '$cname'";$result = mysql_query($chkBal) or die(mysql_error());while($myRows = mysql_fetch_array($result)) {$balance = $myRows['bal'];$newBalance = $balance + $amt;$preSales = $myRows['sales'];$newSales = $preSales + $amt;}// grab s.n.$sn = ($_POST['sn']);$sql = "SELECT * FROM customer where cid = '$cid' ";$result = mysql_query($sql);$rs = mysql_fetch_object($result);$date = strtoupper($_POST['date']);$ref = strtoupper($_POST['ref']);$amt = strtoupper($_POST['amt']);$sql2= "UPDATE sales SET sn = '$sn',cid = '$cid',date = '$date',ref = '$ref',amt = '$amt' WHERE sn ='$sn'";$sql3= "UPDATE customer SET sales = '$newSales',bal = '$newBalance' WHERE cid ='$cid'";mysql_query($sql2)or die(mysql_error());  mysql_query($sql3)or die(mysql_error());  
Edited by funbinod
Link to post
Share on other sites

i'm sorry!

 

does these lines from action script define my problem?

$sql1= "UPDATE sales SET sn = '$sn',cid = '$cid',date = '$date',ref = '$ref',amt = '$amt' WHERE sn ='$sn'";$sql2= "UPDATE customer SET sales = '$newSales',bal = '$newBalance' WHERE cid ='$cid'";$sql3= "UPDATE customer SET sales = '$subSales2',bal = '$subBalance2' WHERE cid ='$preCid'";// i couldnt make the third query done.// or i couldnt retrive the previous 'cid' as '$precid'.
Edited by funbinod
Link to post
Share on other sites

Try...

echo "UPDATE sales SET sn = '$sn',cid = '$cid',date = '$date',ref = '$ref',amt = '$amt' WHERE sn ='$sn'";echo "UPDATE customer SET sales = '$newSales',bal = '$newBalance' WHERE cid ='$cid'";echo "UPDATE customer SET sales = '$subSales2',bal = '$subBalance2' WHERE cid ='$preCid'";

See...

 

http://www.w3schools.com/php/php_mysql_intro.asp

Link to post
Share on other sites

Try...

echo "UPDATE sales SET sn = '$sn',cid = '$cid',date = '$date',ref = '$ref',amt = '$amt' WHERE sn ='$sn'";echo "UPDATE customer SET sales = '$newSales',bal = '$newBalance' WHERE cid ='$cid'";echo "UPDATE customer SET sales = '$subSales2',bal = '$subBalance2' WHERE cid ='$preCid'";

See...

 

http://www.w3schools.com/php/php_mysql_intro.asp

 

sorry!

i think failed to make u understand my problem!

let it be!

Link to post
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...