Jump to content

funbinod

Members
  • Posts

    501
  • Joined

  • Last visited

Everything posted by funbinod

  1. funbinod

    edit a record

    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'.
  2. funbinod

    edit a record

    (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());
  3. funbinod

    delete topic

    how can i delete a topic that i started?
  4. funbinod

    mysql and string

    can mysql table hold a STRING not a exact value? like [ ($ob + $totalSales) - $totalReceipt ] and how can we SUM total value from selected rows?
  5. funbinod

    duplicate entry

    i did it! thank u! if (mysql_num_rows(mysql_query("SELECT cname FROM customer WHERE cname = '$cname'"))) { echo "<div class='errorDiv'>" . $cname . " is registered already!</div>";}
  6. can javascript change key functions? like pressing "Enter" key does "Tab" function; "Left Arrow" functions "Back" button, likewise....
  7. funbinod

    duplicate entry

    noone interested? anyway thanks.....
  8. funbinod

    duplicate entry

    help me fild error now with this new tryout .... <?//check required fields$emptyCname = (empty($cname));$emptyCadd = (empty($cadd));$emptyCperson = (empty($cperson));if ($emptyCname == true && $emptyCadd == true && $emptyCperson ==true) { echo "Please enter Customer Name, Address and Contact Person!";}else if ($emptyCname == true && $emptyCadd == true) { echo "Please enter Customer Name and Address!";}else if ($emptyCname == true && $emptyCperson == true) { echo "Please enter Customer Name and Contact Person!";}else if ($emptyCadd == true && $emptyCperson == true) { echo "Please enter Address and Contact Person!";}else if ($emptyCname == true) { echo "Please enter Customer Name!";}else if ($emptyCadd == true) { echo "Please enter Address!";}else if ($emptyCperson == true) { echo "Please enter Contact Person!";}//check duplicate entryelse if (mysqli_num_rows(mysqli_query("SELECT cname * FROM customer WHERE cname='$cname'"))) { echo "is already registered.";}else {$sql = ("INSERT INTO customer (cname, cadd, cemail, cphone, cperson, cmob, cob, bal)VALUES ('$_POST[cname]', '$_POST[cadd]', '$_POST[cemail]', '$_POST[cphone]', '$_POST[cperson]', '$_POST[cmob]', '$_POST[cob]', '$_POST[cob]')");$query = mysqli_query($con,$sql) or die (mysqli_error());echo "<center><h2>" . $cname. " registered successfully!";}if (!mysqli_query($con, $sql)) { die('Error: ' . mysqli_error($con)); }mysqli_close($con);?>
  9. funbinod

    duplicate entry

    that's nice. thank u. but what is the use of (?) !? is this the value from a corresponding form? if so can we use this the same way for other functions? for example?
  10. funbinod

    duplicate entry

    and please help me understand each elements on these lines-- if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"))) {echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;} and after that please help me become clear about why this used reverse statement before it without defining the statement itself. i mean there is nowhere declared $stmt = $mysqli->prepare() but it used !($stmt = $mysqli->prepare()) { }
  11. funbinod

    duplicate entry

    u caught the point. i've just started to learn and thinking complex things. i'm reading php books downloaded from net. while going on reading something something strikes me and i try to move with it. i've just completed basics of jQuery. now m entering php (i know some basics of it already)....
  12. funbinod

    duplicate entry

    please guide me through prepared statement.. i found this on php.net manual-- <?php$mysqli = new mysqli("example.com", "user", "password", "database");if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;}/* Non-prepared statement */if (!$mysqli->query("DROP TABLE IF EXISTS test") || !$mysqli->query("CREATE TABLE test(id INT)")) { echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;}/* Prepared statement, stage 1: prepare */if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;}?> please help me understand the use of "new" on first line and the exclamation (!) sign before $mysqli (or elsewhere)
  13. thank u! but will the "HOW" question be entertained?
  14. funbinod

    duplicate entry

    i tried this --- <?php$query = "SELECT * FROM customerWHERE cname='$_POST[cname]'"; //trying to get data from form field named 'cname'$result = mysql_query($query);if (!$result) die("Unable to select database: " . mysql_error());// match dataif $dup = mysql_result($result,'cname');{echo "Name already register";}?> but didn't work. has this got some rhythm? or i should i have to go elsewhere? please.......
  15. thank u... but if a php script retrived the data from database on a separate file, can javascript read that? if yes please guide....
  16. funbinod

    duplicate entry

    how to check for duplicate entry on a form using php?
  17. i've echoed it and got the result... please recheck on the last line in my first post // error messageecho $dateErr; // and so on and in between on several places in my second post...... <span class="error">* <? echo $dateErr; ?></span> //and so on
  18. i want to know if jquery (or javascript) can deal with mysql database?
  19. i dunno what exactly is the different between "for loop" & "while loop".. please guide...
  20. the parameter for mysql_result() u meant (or PHP meant) might be with "mysql connection", i think. if so i've done this before the line. i dunno if it should be included there. and i understood the mistake while assigning $icode. additionally, i couldn't understand the validation u noticed on any of the user input. and i got little confused while using "mysqli" function. i couldnt understand that if it is just a replacement of "mysql" or there will be some additional changes in it... please guide....
  21. i got what the problem was. before, i used -- <? echo $dateErr; ?> later i changed it to -- <?php $dateErr; ?> and it worked. but i dont know what the different is.....
  22. thank u but this returned nothing when i click submit to a blank form. the form is like this-- <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST"><fieldset class="form-field-set"><legend><h1>Test Invoice</h1></legend><div class="form-field" id="main"><div class="form-field"><span class="error">* <? echo $cnameErr; ?></span><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"><span class="error">* <? echo $dateErr; ?></span><label>Date:</label><input type="date" name="date" id="date"></div><div class="form-field"><label>Reference No.:</label><input type="text" name="rfn" id="rfn"></div><div class="form-field"><span class="error">* <? echo $itemErr; ?></span><label>Item Name:</label><select name="item"><option></option><?php// select table$query = "SELECT * FROM stock";$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,'item') . "</option>" ;}?></select></div><div class="form-field"><span class="error">* <? echo $rateErr; ?></span><label>Rate:</label><input type="text" name="rate" id="rate"></div><div class="form-field"><span class="error">* <? echo $qtyErr; ?></span><label>Quantity:</label><input type="text" name="qty" id="qty"></div><div class="form-field"><label>Discount (%):</label><input type="text" name="less" id="less"></div><div class="form-field"><label>Amount:</label><input type="text" name="amt" id="amt" disabled></div><div class="form-field"><input type="submit" value="Add to Cart" name="submit" id="submit"></div></form>
  23. ok! i describe it with what i tried to code. what i'm trying is in the comments within the code--- <form action="#" id="test" name="test"><input name="icode" id="icode" type="text"><br /> <!-- after inputing 'code' here --><?php$icode = '$_POST[icode]';$result = mysql_query("SELECT * FROM stockWHERE icode='$icode'");while($row = mysql_result($result)) { echo '<input name="item" id="item" value="$row[item]" placeholder="i wish the ITEM NAME be displayed here automatically">'; }?><br /><!--i wish the 'item name' be displayed here automatically --><input name="qty" id="qty" type="text"><br /><input name="rate" id="rate" type="text"><br /><input name="amt" id="amt" type="text"><br /><input type="submit" name="submit" id="submit" value="SUBMIT"></form> but it returned -- Warning: mysql_result() expects at least 2 parameters, 1 given in E:xampphtdocsactestjQuery.php on line 30 and please look for other errors or techniques....
  24. m back again here. i'm trying to understand what u gave me on reference. now m understanding this a bit more. but m confused that this echos the first name or last name after "submitting" the form or only after "inputting" the value on form?
  25. i was trying to make error message relating from the w3schools learning center but it returned nothing. please help me find the error.... here is the code i wrote... <?php// define variables and set to empty values$cnameErr = $dateErr = $itemErr = $rateErr = $qtyErr = "";$cname = $date = $rfn = $item = $rate = $qty = $less = $amt = "";if ($_SERVER["REQUEST_METHOD"] == "POST"){ if (empty($_POST["cname"])) {$cnameErr = "Customer Name is required";} else {$cname = test_input($_POST["cname"]);} if (empty($_POST["date"])) {$emailErr = "Date is required";} else {$date = test_input($_POST["date"]);} if (empty($_POST["rfn"])) {$rfn = "";} else {$rfn = test_input($_POST["rfn"]);} if (empty($_POST["item"])) {$itemErr = "Item name is required";} else {$item = test_input($_POST["item"]);} if (empty($_POST["rate"])) {$rateErr = "Please input Rate";} else {$rate = test_input($_POST["rate"]);} if (empty($_POST["qty"])) {$qtyErr = "Please input item quantity";} else {$qty = test_input($_POST["qty"]);} if (empty($_POST["less"])) {$less = "";} else {$less = test_input($_POST["less"]);} if (empty($_POST["amt"])) {$amt = "";} else {$amt = test_input($_POST["amt"]);}}function test_input($data){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;}// error messageecho $dateErr; // and so on?>
×
×
  • Create New...