0

Hi, all. Currently i am facing some problem with my coding. I am used this code to insert data from multiple checkbox values into database. but its still not happen anything. Sorry, i am new to php. Please can anyone help me on this? I would be more appreciate if i get to solve this problem. Thank you so much.

<script type="text/javascript">
var currentEnabled = null;
function enableElement(elem) {
if (currentEnabled) {
currentEnabled.disabled = true;
}
elem.disabled = false;
currentEnabled = elem;
}
</script>
<body background="images/form.jpg" bgcolour="#CC66FF">

<?php 
error_reporting(0);
session_start();
include('includes/header.html');
include('dbcon.php');

// Get values from form
if(isset($_POST['submit'])) {
$fdate = date('Y-m-d');
$ref_no = $_POST['ref_no'];
$from = $_POST['from'];
$copy = $_POST['copy'];
$description = implode(',',$_POST['description']);
$buyer = $_POST['buyer'];
$ref = $_POST['ref'];
$potential_annual = $_POST['potential_annual'];
$target_price = $_POST['target_price'];
$market_app = $_POST['market_app'];
$instruct = implode(',', $_POST['instruct']);
$comp_colour = $_POST['comp_colour'];
$pattern = implode(',', $_POST['pattern']);
$sole_colour = $_POST['sole_colour'];
$calender_pattern = $_POST['calender_pattern'];
$heel_type = $_POST['heel_type'];
$heel_colour = implode(',', $_POST['heel_colour']);
$moul_sole = $_POST['moul_sole'];
$top_fox = $_POST['top_fox'];
$top_colour = implode(',', $_POST['top_colour']);
$bottom_fox = $_POST['bottom_fox'];
$bottom_colour = implode(',',$_POST['bottom_colour']);
$last_type = $_POST['last_type'];
$boots_height = $_POST['boots_height'];
$size = $_POST['size'];
$total_pairs = $_POST['total_pairs'];
$date_required = $_POST['date_required'];
$lin_material = $_POST['lin_material'];
$cuff_material = implode(',', $_POST['cuff_material']);
$lace_colour = implode(',',$_POST['lace_colour']);
$brand = $_POST['brand'];
$colour = $_POST['colour'];
$lacquer_finishing = implode(',', $_POST['lacquer_finishing']);
$safety = implode(',', $_POST['safety']);
$features = implode(',', $_POST['features']);
$attachment = $_POST['attachment'];
$remarks = $_POST['remarks'];
$department = $_POST['department'];
$pair = $_POST['pair'];
$request_by = $_POST['request_by'];
$approval_status = $_POST['approval_status'];

$query = "INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, dept_name, pair, request_by, approval_status ) VALUES ('$fdate', '$ref_no', '$from', '$copy', '$description', '$buyer', '$ref', '$potential_annual', '$target_price', '$market_app', '$instruct', '$comp_colour', '$pattern', '$sole_colour', '$calender_pattern', '$heel_type', '$heel_colour', '$moul_sole', '$top_fox', '$top_colour', '$bottom_fox', '$bottom_colour', '$last_type', '$boots_height', '$size', '$total_pairs', '$date_required', '$lin_material', '$cuff_material', '$lace_colour', '$brand', '$colour', '$lacquer_finishing', '$safety', '$features', '$attachment', '$remarks', '$department', '$pair', '$request_by', 'pending')";

 $result=mysql_query($sql);
        if($result)
        {
             echo "Requisition Successfully Added!";
        }
        else
        {
             echo "failed";
        }
    }
?>

<table width="1028" height="1181" border="2" align="center" cellpadding="2" cellspacing="3" cols="2" bgcolor="#C0C0C0">
  <td width="1012" height="20"><center><font color="#0000FF"><strong>SAMPLE REQUISITION FORM</strong></font></center>
  <tr>
<form action="form.php" method="post">
<br>
<tr>
                <td height="20"><b><strong>Filed Date :</span></div>
                </strong>
 <input name="fdate" type="text" id="day" value="<?php echo date('Y-m-d'); ?>" size="10" maxlength="15"  readonly />
                <b> <strong>Reference No :</strong><input name="ref_no" type="text" id="ref_no" value="" size="10" maxlength="10" /></td>
          </tr>
<tr>
<td height="20"><strong><b>From :</strong>
  <input type="text" name="from" size="28" value=""/>  
   <b> <strong>Copy :</strong>
   <input type="text" name="copy" size="28" value=""/>
   <b> <strong>To : <em>Product Department</em></strong></td></tr>
  <tr>
<td height="30"><b><strong>Description :
      </strong>
  <label><br>
      <input name = "description[]" type = "checkbox" value ="safety" onClick="enableElement(this.form.elements['inp1']);"  />
      SAFETY </label>
    <label> 
      <input name = "description[]" type = "checkbox" value = "work" onClick="enableElement(this.form.elements['inp2']);" />
      WORK </label>
    <label> 
      <input name= "description[]" type ="checkbox" value="yachting" onClick="enableElement(this.form.elements['inp3']);"/>
      YACHTING </label>
    <label> 
      <input name="description[]" type ="checkbox" value="golf" onClick="enableElement(this.form.elements['inp4']);"/>
      GOLF </label>
    <label> 
      <input name="description[]" type = "checkbox" value="hiking" onClick="enableElement(this.form.elements['inp5']);"/>
      HIKING </label>
    <label> 
      <input name="description[]" type="checkbox" value="ladies" onClick="enableElement(this.form.elements['inp6']);"/>
      LADIES</label>
      <input name="description[]" type="checkbox" value="children" onClick="enableElement(this.form.elements['inp7']);"/>      
      CHILDREN</label>
    <label> 
      <input name="description[]" type="checkbox" value="hunting" onClick="enableElement(this.form.elements['inp8']);"/>
      HUNTING </label>
    <br>
    <label> 
      <input name="description[]" type="checkbox" value="wader" onClick="enableElement(this.form.elements['inp9']);"/>
      WADER </label>
      <label>
    <input type="checkbox" name="description[]" value ="others" onClick="enableElement(this.form.elements['inp10']);" />OTHERS :
<input type="text" name="inp10" size="30" disabled="disabled"/>
</label>
</td></tr>
<tr>
<td height "30"><strong><b>Buyer (Company Address/ Country) :</strong>
  <textarea name="buyer" type="text" size="30" maxlength="30"></textarea>
  <strong><b> Reference :</strong>
  <input name="ref" type="text"  value="" size="30" maxlength="30"  />
  </tr>
<tr><td height="20"><strong><b>Potential Annual Volume :</strong>
  <input type="text" name="potential_annual" size="20" value=""/>
      <b><strong>Target Price :</strong>
      <input type="text" name="target_price" size="20" value=""/> 
  <b> <strong>Market Application :</strong>  <input type="text" name="market_app" size="30" value=""/></td>
  </tr>

<tr>
<td height="57"><b><strong>Instruction :
</strong>
  <label><br>
  <input name = "instruct[]" type = "checkbox" value ="safety" onClick="enableElement(this.form.elements['inp1']);" />
      REFER FAX/ LETTER ATTACHED FOR FULL 
      DETAILS. </label> 
  <label>
      <input name="instruct[]" type="checkbox" value="duplicate" onClick="enableElement(this.form.elements['inp2']);"/> 
      DUPLICATE 
      <input name="instruct[]" type="checkbox" value="new" onClick="enableElement(this.form.elements['inp3']);"/>
NEW PRODUCT DEVELOPMENT</label>
   <label><br>
  </label>
  <label> 
     <input name="instruct[]" type="checkbox" value="art" onClick="enableElement(this.form.elements['inp4']);"/>
      MODIFICATION OF ART/MODEL : 
      <input type="text" name="inp4" size="30" disabled="disabled"/>
    </label>
  <label><br>
        <input name="instruct[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp5']);"/>
      OTHERS :  <input type="text" name="inp5" size="30" disabled="disabled"/>
  </label></td>
</tr>
 <tr><td height="20"><center><font color="#0000FF"> 
   <strong><em>UPPER </em></strong></font>
 </center></td></tr> 
<tr>
  <td height="58"><b><strong>Compound / Colour :</strong>
    <input type="text" name="comp_colour" size="30" value=""/>  <br><b><strong>Pattern :  
        </strong>
    <label>
      <input name="pattern[]" type="checkbox" value="kid" onClick="enableElement(this.form.elements['inp1']);"/>KID </label>
      <label> 
        <input name="pattern[]" type="checkbox" value="nappa" onClick="enableElement(this.form.elements['inp2']);"/>NAPPA</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="bull" onClick="enableElement(this.form.elements['inp3']);"/>BULL</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="plain" onClick="enableElement(this.form.elements['inp4']);"/>PLAIN </label>
       <label>
         <input name="pattern[]" type="checkbox" value="others" onClick="enableElement(this.form.elements['inp5']);"/>
         OTHERS (Please Specify): 
         <input type="text" name="inp5" size="15" disabled="disabled"/>
       </label></td>
    </tr>
      <tr><td height="20"><center><font color="#0000FF"> 
        <strong><em>SOLE </em></strong></font>
      </center></td></tr>
    <tr>
  <td height="20"><b><strong>Sole Compound / Colour :</strong>
    <input type="text" name="sole_colour" size="30" value=""/>
<b> <strong>Calender Roll/Pattern : </strong>
<input type ="text" name="calender_pattern" size="30" value=""/></td></tr>
<tr>
  <td height="20"><strong><b>Heel Types :</strong>
    <input type="text" name="heel_type" size="30" value=""/>
<br><b><strong>Colour :</strong>
<label>
  <input name="heel_colour[]" type="checkbox" value="same_as_sole" onClick="enableElement(this.form.elements['inp1']);"/>Same as Sole </label>
<label>
<input name="heel_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" disabled="disabled"/>
</label></td></tr>
<tr>
<td height="20"><b><strong>Moulded Sole Type :</strong>  <input type="text" name="moul_sole" size="30" value=""/> </td>
</tr>
<tr> 
<td height="20"><b><strong>Top Foxing Pattern/Roll :</strong>
  <input type="text" name="top_fox" size="30" value=""/>
<br><b> <strong> Colour: </strong>
<label>
<input name="top_colour[]" type="checkbox" value="same_as_upper" onClick="enableElement(this.form.elements['inp1']);"/>Same as Upper</label>
<label>
<input name="top_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : <input type="text" name="inp2" size="28" disabled="disabled"/></label>
</td>
</tr>
<tr>
<td height="20"><strong><b>Bottom Foxing Pattern/Roll :</strong>
  <input type="text" name="bottom_fox" size="30" value=""/>
<br><b><strong>Colour : 
</strong>
<label>
  <input name="bottom_colour[]" type="checkbox" value="upper/sole" onClick="enableElement(this.form.elements['inp1']);"/> Same as Upper/Sole</label>
<label>
<input name="bottom_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);"/> 
OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" value="" disabled="disabled"/></label> </td>
<tr>
<td height="20"><b><strong>Last Type :</strong>
  <input type="text" name="last_type" size="20" value=""/>
<b> <strong>Boots Height :</strong>
<input type="text" name="height" size="10" value=""/>
<b> <strong>Size :</strong>
<input type="text" name="size" size="10" value=""/> 
 <b> <strong>Total Pairs : </strong>
 <input type="text" name="total_pairs" size="10" value=""/>
<br><b><strong>Date Required :</strong> <input name="date_required" type="date" value=""/></td>
</tr>
<tr>
                <td height="20"><b><strong>Lining Material/ Colour :</strong> </span></div>
                <input name="lin_material" type="text"  value="" size="30"/></td>

<tr>
<td height="20"><b><strong>Cuff Material/Colour :
</strong>
  <label>
<input name="cuff_material[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="cuff_material[]" type="checkbox" value="" onClick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
<tr>
<td height="20"><b><strong>Lace/Colour :</strong>
<label>
  <input name="lace_colour[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="lace_colour[]" type="checkbox" value="" onClick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
  <tr>
    <td height="20"><b><strong>Brand :</strong>   <input type="text" name="brand" size="30" value=""/> 
      <b><strong>Colour :</strong>   <input type="text" name="color" size="30" value=""/></td>
    </tr>
<tr>
<td height="20"><b><strong>Lacquer Finishing :</strong>
<label> 
  <input name = "lacquer_finishing[]" type = "checkbox" value ="gloss" onClick="enableElement(this.form.elements['inp1']);"/>
  GLOSS </label>
    <label> 
      <input name = "lacquer_finishing[]" type = "checkbox" value = "dull" onClick="enableElement(this.form.elements['inp2']);"/>
      DULL </label>
    </td></tr>
<tr>
<td height="20"><b><strong>Safety Standards to Confirm :</strong>
<label><input name="safety[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/>N/A</label>
<label><input name="safety[]" type="checkbox" value="en-" onClick="enableElement(this.form.elements['inp2']);"/>EN-
<input type="text" name="inp2" disabled="disabled" size="10"></label>
<label><input name="safety[]" type="checkbox" value="csa" onClick="enableElement(this.form.elements['inp3']);"/>CSA</label>
<label><input name="safety[]" type="checkbox" value="astm" onClick="enableElement(this.form.elements['inp4']);"/>ASTM</label>
<label><input name="safety[]" type="checkbox" value="sirim" onClick="enableElement(this.form.elements['inp5']);"/>SIRIM</label>
<label>
<input name="safety[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp6']);"/>Others:<input type="text" name="inp6" size="10" disabled="disabled"/>
</label></td>
</tr>
<tr>
<td height="75"><b><strong>NotWithStanding 15.0 Above, Other Features Required :
</strong>
  <label><br>
<input name="features[]" type="checkbox" value="none" onClick="enableElement(this.form.elements['inp1']);"/>NONE</label>
<label>
<input name="features[]" type="checkbox" value="steel_toe_cap" onClick="enableElement(this.form.elements['inp2']);"/>STEEL TOE CAP</label>
<label>
<input name="features[]" type="checkbox" value="steel_mid_sole" onClick="enableElement(this.form.elements['inp3']);"/>STEEL MID SOLE</label>
<label>
<input name="features[]" type="checkbox" value="steel_shank" onClick="enableElement(this.form.elements['inp4']);"/>STEEL SHANK</label>
<label>
<input name="features[]" type="checkbox" value="anti_static" onClick="enableElement(this.form.elements['inp5']);"/>ANTI-STATIC</label>
<label>
  <input name="features[]" type="checkbox" value="fire_retardant" onClick="enableElement(this.form.elements['inp6']);"/>
  FIRE RETARDANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="oil_resistant_sole_upper" onClick="enableElement(this.form.elements['inp7']);"/>OIL RESISTANT SOLE & UPPER</label>
<label>
  <input name="features[]" type="checkbox" value="chainsaw_protection" onClick="enableElement(this.form.elements['inp8']);"/>
CHAINSAW PROTECTION</label>
<label>
  <input name="features[]" type="checkbox" value="anti_slip_sole" onClick="enableElement(this.form.elements['inp9']);"/>
  ANTI-SLIP SOLE</label>
<label>
  <input name="features[]" type="checkbox" value="electric_shock_resistant" onClick="enableElement(this.form.elements['inp10']);"/>ELECTRIC SHOCK RESISTANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp11']);"/>
  OTHERS (please specify) :
<input type="text" name="inp11" size="38" disabled="disabled"/></label>
</td></tr>

<tr>
<td height="20"><b><strong>Sketches/Drawings Attached :
</strong>
  <label> 
      <input name = "attachment[]" type = "radio" value ="yes" checked/>YES</label>
      <label>
      <input name="attachment[]" type="radio" value="no"/>NO</label>

</td>      
</tr>
<tr>
  <td height="45"><b><strong>Other Description/Remarks :</strong>  <textarea name="remarks" type="text" rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td height="20"><center><font color="#0000FF"><em><strong>#Sample Distribution</strong></em></font>
</center></td> 
</tr>
<tr>
<td height="20"><strong><strong>TO :</strong><select name = "department" >
  <option selected> Department </option>
  <option> Marketing Department</option>
  <option> Technical Department </option>
  <option> Product Development Section</option>
</select> 
  <strong><b> Pairs :</strong>
  <input type="text" name="pair" size="10"/>
  <br>
<strong><b> Requested By :</strong>  <input type="text" name="request_by" size="30" value=""/></td>
</tr>

<tr>
<tr>
</tr>
<tr>
<td>
<label>
<input name="notify" type="checkbox" value="notify" checked/> 
<em><strong>Send notification for approval. </strong></em><strong></strong></label>
(Make sure it's always checked!)</td>
</tr>
<tr>
<td height="30"><center><input type = "submit" value = "Submit Requisition"  name="Submit" /></center></td>
<input type="hidden" name="submitted" />
</tr>
</form>
</tr>
</table>
<?php
echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";
include('includes/footer.html');
?>
</body>
</html>
4
Contributors
14
Replies
96
Views
3 Years
Discussion Span
Last Post by Isaac_4
Featured Replies
  • 1
    diafol 3,720   3 Years Ago

    That's alot of markup to wade through. One thing prob. not related is the fact that you're using deprecated functions (mysql_*) without any sanitizing (e.g. with `mysql_real_escape_string()`). Use PDO or mysqli and bind parameters/values via prepared statement. You are open to SQL injection - this is VERY serious. Read More

  • 1
    diafol 3,720   3 Years Ago

    Unfortunately, with param bidning and prepared statements (PDO and mysqli), you can't print the resulting SQL string to the screen. But on line 57 do this: print $query; That will echo the "tokened" sql string to the screen. Copy it from the screen and paste it into phpmyadmin change the … Read More

  • 1
    diafol 3,720   3 Years Ago

    <Unrelated> Your db will be sluggish methinks with all those 255/varchar fields. The majority from what i can see do not need to be so big. Possibly you could make more tables and relate them to the requisition table. Colour for example. Target price I would thing would be better … Read More

1

That's alot of markup to wade through. One thing prob. not related is the fact that you're using deprecated functions (mysql_*) without any sanitizing (e.g. with mysql_real_escape_string()). Use PDO or mysqli and bind parameters/values via prepared statement. You are open to SQL injection - this is VERY serious.

0

Diafol is very right, your code is subject to injection attachs. As hey says, you should at least call mysql_real_escape_string() on every value before putting them into your $sql variable. Even better would be to use my sample Safe and SIMPLE database inserts which should actually be even easier (less code) than what you are doing.

In your block where you print out that the SQL query failed, you can get more info by doing this:

echo "failed";
echo mysql_error();

Here is your insert query rewritten to use my include file, which is much safer to use than the raw mysql functions.

<?php

define('DEBUG', true);  // Change to false in production to prevent errors from showing to visitors!!

require_once("database.php");

// Get values from form
if(isset($_POST['submit']))
{
    $row = array(
        date('Y-m-d'),
        $_POST['ref_no'],
        $_POST['from'],
        $_POST['copy'],
        implode(',',$_POST['description']),
        $_POST['buyer'],
        $_POST['ref'],
        $_POST['potential_annual'],
        $_POST['target_price'],
        $_POST['market_app'],
        implode(',', $_POST['instruct']),
        $_POST['comp_colour'],
        implode(',', $_POST['pattern']),
        $_POST['sole_colour'],
        $_POST['calender_pattern'],
        $_POST['heel_type'],
        implode(',', $_POST['heel_colour']),
        $_POST['moul_sole'],
        $_POST['top_fox'],
        implode(',', $_POST['top_colour']),
        $_POST['bottom_fox'],
        implode(',',$_POST['bottom_colour']),
        $_POST['last_type'],
        $_POST['boots_height'],
        $_POST['size'],
        $_POST['total_pairs'],
        $_POST['date_required'],
        $_POST['lin_material'],
        implode(',', $_POST['cuff_material']),
        implode(',',$_POST['lace_colour']),
        $_POST['brand'],
        $_POST['colour'],
        implode(',', $_POST['lacquer_finishing']),
        implode(',', $_POST['safety']),
        implode(',', $_POST['features']),
        $_POST['attachment'],
        $_POST['remarks'],
        $_POST['department'],
        $_POST['pair'],
        $_POST['request_by'],
        'pending',
    );

    // Make N placeholders (the ? symbol is replaced by prepare with your value), where N == number of fields in the row to insert
    $tokens = array_fill('?', count($row));
    $query = 'INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, dept_name, pair, request_by, approval_status ) VALUES ('.implode(',', $tokens).')';

    $result = db_query($sql, $row);

    if($result)
    {
         echo "Requisition Successfully Added!";
    }
    else
    {
        if(DEBUG) {
            echo "<b>MySQL error:</b><br/>";
            print_r($pdo->errorInfo());
        } else {
            echo "<b>Sorry, we could not process your request</b><br/>";
        }
    }
}

If you really want to keep using the functions you are using, at least switch to the mysqli package. The mysql functions you are using will be removed in probably the next major version of PHP. See these pages for more info:

http://php.net/manual/en/mysqlinfo.api.choosing.php
http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated

(My database include uses PDO, which is references in these pages.)

0

Thank you for your reply, Difol and Issac 4.
Issac 4, when i tried to replce my insert code with insert query which you were rewritten, i still facing the same problem. which is its nothing bringany changes to database( still empty). Is there any other solutions for this? Thank you for your time. :)

1

What output do you get with my version? It should have printed out an error message object.

If you got no output at all, try putting this at the top of the file and report back what output you see:

<?php
echo "PHP Parsed okay<br/>";
ini_set('display_errors', 'on');
error_reporting(E_ALL);

Edited by Isaac_4

0

Hi, Issac 4. I got tried to put that code at the top of my file. But its still not working. Its supposed to be printout error message but its just refresh back the form. And this how i put the code.

<?php
echo "PHP Parsed okay<br/>";
ini_set('display_errors', 'on');
error_reporting(E_ALL);
define('DEBUG', true);  // Change to false in production to prevent errors from showing to visitors!!
require_once("dbcon.php");
include('includes/header.html');
// Get values from form
if(isset($_POST['submit']))
{
    $row = array(
        date('Y-m-d'),
        $_POST['ref_no'],
        $_POST['from'],
        $_POST['copy'],
        implode(',',$_POST['description']),
        $_POST['buyer'],
        $_POST['ref'],
        $_POST['potential_annual'],
        $_POST['target_price'],
        $_POST['market_app'],
        implode(',', $_POST['instruct']),
        $_POST['comp_colour'],
        implode(',', $_POST['pattern']),
        $_POST['sole_colour'],
        $_POST['calender_pattern'],
        $_POST['heel_type'],
        implode(',', $_POST['heel_colour']),
        $_POST['moul_sole'],
        $_POST['top_fox'],
        implode(',', $_POST['top_colour']),
        $_POST['bottom_fox'],
        implode(',',$_POST['bottom_colour']),
        $_POST['last_type'],
        $_POST['boots_height'],
        $_POST['size'],
        $_POST['total_pairs'],
        $_POST['date_required'],
        $_POST['lin_material'],
        implode(',', $_POST['cuff_material']),
        implode(',',$_POST['lace_colour']),
        $_POST['brand'],
        $_POST['colour'],
        implode(',', $_POST['lacquer_finishing']),
        implode(',', $_POST['safety']),
        implode(',', $_POST['features']),
        $_POST['attachment'],
        $_POST['remarks'],
        $_POST['department'],
        $_POST['pair'],
        $_POST['request_by'],
        'pending',
    );
    // Make N placeholders (the ? symbol is replaced by prepare with your value), where N == number of fields in the row to insert
    $tokens = array_fill('?', count($row));
    $query = 'INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, department, pair, request_by, approval_status ) VALUES ('.implode(',', $tokens).')';
    $result = db_query($sql, $row);
    if($result)
    {
         echo "Requisition Successfully Added!";
    }
    else
    {
        if(DEBUG) {
            echo "<b>MySQL error:</b><br/>";
            print_r($pdo->errorInfo());
        } else {
            echo "<b>Sorry, we could not process your request</b><br/>";
        }
    }
}
?>
1

Unfortunately, with param bidning and prepared statements (PDO and mysqli), you can't print the resulting SQL string to the screen. But on line 57 do this:

print $query;

That will echo the "tokened" sql string to the screen. Copy it from the screen and paste it into phpmyadmin change the ? tokens to values that would be acceptable to your datatypes - don't forget to use quotes around strings, dates etc. Run the query. Hopefully you'll get an error message. Hope that it's a simple typo in a fieldname or the number of fields to tokens is mismatched or something equally as fixable.

1

this is your query. the last value is 'pending'
try change 'pending' to $pending.

using mysqli is very safe and easy .

$query = "INSERT INTO requisition ('pending')";

here is an example of msqli

first create a new page called Mysqli.php

<?php
    $dbhost = 'localhost'; // your host
    $dbuser = 'root'; // username
    $dbpass = ''; // password
    $database = 'data'; // database name
    $conn     = mysqli_connect($dbhost,$dbuser,$dbpass,$database) or die("Error " . mysqli_error($link));   


?>

now in your index page just include the Mysqli.php at the top like this 

<?php
require_once('Mysqli.php');
?>
 now in all your sql statements just change msql to mysqli.   its that easy
1

Some things to check...

Does your page now start with the line PHP Parsed okay? If not, there is something wrong with PHP's configuration or there is a syntax error in your file.

Did you put my db_query() function and the $pdo = new PDO(...); line into your dbcon.php file? If not, you need to either add it there or include the database.php file instead of dbcon.php. Make sure you also adjust the PDO() line to match your database settings.

Also, is the file this code in actually called form.php? This is where the form is trying to post to, so if youy renamed it, you need to change the <form> tag's action attribute to match the new filename.

Do you have a .htaccess file in the root of your site? You need to make sure your S/FTP program is set to show hidden files to see it, or if you are on the command line, us ls -al to show hidden files. If you do have such a file, try moving it (or delete it after making a backup locally, and checking the backup has the same contents as the original). It could be causing a redirect which may prevent the POST from working... which you can also check by looking in your browser's Developer Tools to see if after submitting the form you get any 301 or 302 or other interesting return codes.

To see if you can catch anything else, put an exit here at the end of the processing section. Make sure it's inside the if(isset($_POST['submit'])) conditional so that it only exits when there is a post.

.....
    else
    {
        if(DEBUG) {
            echo "<b>MySQL error:</b><br/>";
            print_r($pdo->errorInfo());
        } else {
            echo "<b>Sorry, we could not process your request</b><br/>";
        }
    }

    if(DEBUG) {
        echo '<p><b>Exiting after POST for DEBUG</b></p>';
        echo '<pre>';
        echo "\n\n**Post:\n";
        print_r($_POST);
        echo "\n\n**Server:\n";
        print_r($_SERVER);
        echo '</pre>';
        exit; // debug only
    }
}
?>

Copy and paste the contents of the two arrays after a post to see if we can help figure out why it isn't processing.

Edited by Isaac_4

0

Hi, issac.

Does your page now start with the line PHP Parsed okay? If not, there is something wrong with PHP's configuration or there is a syntax error in your file.

Ya. its shows PHP Parsed okay at the top of my page.

Did you put my db_query() function and the $pdo = new PDO(.

And yes. I got create a new file called Mysqli and i got inserted ur db_query and also $pdo = new PDO(). Like this.:
Mysqli.php

<?php

   function db_connect()
{
    // Connect to the database. This requires the PDO and PDO_Mysql modules to be installed in PHP.
    // TODO: Store this connection string in a config file instead of hardcoded
    return new PDO('mysql:host=localhost;dbname=ccse', 'root', '');
}
// Helper function to prepare and execute a statement with parameters immediately
function db_query($conn, $sql, $params=array()) {
    $query = $conn->prepare($sql);
    if($query->execute($params)) {
        return $query->fetchAll();
    } else {
        return array();
    }
}
?>

Also, is the file this code in actually called form.php? This is where the form is trying to post to, so if youy renamed it, you need to change the <form> tag's action attribute to match the new filename.

Yes, i am aslo name this file as form.php

And sorry, i dont understand about this query much.
$tokens = array_fill('41', count($row));
as diafol says, that i need to change the ? tokens to values that would be acceptable to your datatypes - don't forget to use quotes around strings, dates etc. But i quite confuse with this.

Edited by Nirmala_1

0

This is my form.php file

<script type="text/javascript">
var currentEnabled = null;
function enableElement(elem) {
if (currentEnabled) {
currentEnabled.disabled = true;
}
elem.disabled = false;
currentEnabled = elem;
}
</script>
<title>Online Requisition System</title>
<body background="images/form.jpg" bgcolour="#CC66FF">
<?php
echo "PHP Parsed okay<br/>";
ini_set('display_errors', 'on');
error_reporting(E_ALL);
define('DEBUG', true);  // Change to false in production to prevent errors from showing to visitors!!
require_once("Mysqli.php");
include('includes/header.html');
// Get values from form
if(isset($_POST['submit']))
{
    $row = array(
        date('Y-m-d'),
        $_POST['ref_no'],
        $_POST['from'],
        $_POST['copy'],
        implode(',',$_POST['description']),
        $_POST['buyer'],
        $_POST['ref'],
        $_POST['potential_annual'],
        $_POST['target_price'],
        $_POST['market_app'],
        implode(',', $_POST['instruct']),
        $_POST['comp_colour'],
        implode(',', $_POST['pattern']),
        $_POST['sole_colour'],
        $_POST['calender_pattern'],
        $_POST['heel_type'],
        implode(',', $_POST['heel_colour']),
        $_POST['moul_sole'],
        $_POST['top_fox'],
        implode(',', $_POST['top_colour']),
        $_POST['bottom_fox'],
        implode(',',$_POST['bottom_colour']),
        $_POST['last_type'],
        $_POST['boots_height'],
        $_POST['size'],
        $_POST['total_pairs'],
        $_POST['date_required'],
        $_POST['lin_material'],
        implode(',', $_POST['cuff_material']),
        implode(',',$_POST['lace_colour']),
        $_POST['brand'],
        $_POST['colour'],
        implode(',', $_POST['lacquer_finishing']),
        implode(',', $_POST['safety']),
        implode(',', $_POST['features']),
        $_POST['attachment'],
        $_POST['remarks'],
        $_POST['department'],
        $_POST['pair'],
        $_POST['request_by'],
        '$pending',
    );
    // Make N placeholders (the ? symbol is replaced by prepare with your value), where N == number of fields in the row to insert
    $tokens = array_fill('41', count($row));
    $query = 'INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, department, pair, request_by, approval_status ) VALUES ('.implode(',', $tokens).')';

    print $query;
    if($result)
    {
         echo "Requisition Successfully Added!";
    }
    else
    {
        if(DEBUG) {
            echo "<b>MySQL error:</b><br/>";
            print_r($pdo->errorInfo());
        } else {
            echo "<b>Sorry, we could not process your request</b><br/>";
        }
    }
}
?>

<table width="1028" height="1181" border="2" align="center" cellpadding="2" cellspacing="3" cols="2" bgcolor="#C0C0C0">
  <td width="1012" height="20"><center><font color="#0000FF"><strong>SAMPLE REQUISITION FORM</strong></font></center>
  <tr>
<form action="form.php" method="post">
<br>
<tr>
                <td height="20"><b><strong>Filed Date :</span></div>
                </strong>
 <input name="fdate" type="text" id="day" value="<?php echo date('Y-m-d'); ?>" size="10" maxlength="15"  readonly />
                <b> <strong>Reference No :</strong><input name="ref_no" type="text" id="ref_no" value="" size="10" maxlength="10" /></td>
          </tr>
<tr>
<td height="20"><strong><b>From :</strong>
  <input type="text" name="from" size="28" value=""/>  
   <b> <strong>Copy :</strong>
   <input type="text" name="copy" size="28" value=""/>
   <b> <strong>To : <em>Product Department</em></strong></td></tr>
  <tr>
<td height="30"><b><strong>Description :
      </strong>
  <label><br>
      <input name = "description[]" type = "checkbox" value ="safety" onClick="enableElement(this.form.elements['inp1']);" />
      SAFETY </label>
    <label> 
      <input name = "description[]" type = "checkbox" value = "work" onClick="enableElement(this.form.elements['inp2']);"/>
      WORK </label>
    <label> 
      <input name= "description[]" type ="checkbox" value="yachting" onClick="enableElement(this.form.elements['inp3']);"/>
      YACHTING </label>
    <label> 
      <input name="description[]" type ="checkbox" value="golf" onClick="enableElement(this.form.elements['inp4']);"/>
      GOLF </label>
    <label> 
      <input name="description[]" type = "checkbox" value="hiking" onClick="enableElement(this.form.elements['inp5']);"/>
      HIKING </label>
    <label> 
      <input name="description[]" type="checkbox" value="ladies" onClick="enableElement(this.form.elements['inp6']);"/>
      LADIES</label>
      <input name="description[]" type="checkbox" value="children" onClick="enableElement(this.form.elements['inp7']);"/>      
      CHILDREN</label>
    <label> 
      <input name="description[]" type="checkbox" value="hunting" onClick="enableElement(this.form.elements['inp8']);"/>
      HUNTING </label>
    <br>
    <label> 
      <input name="description[]" type="checkbox" value="wader" onClick="enableElement(this.form.elements['inp9']);"/>
      WADER </label>
      <label>
    <input type="checkbox" name="description[]" value ="others" onClick="enableElement(this.form.elements['inp10']);" />OTHERS :
<input type="text" name="inp10" size="30" disabled="disabled"/>
</label>
</td></tr>
<tr>
<td height "30"><strong><b>Buyer (Company Address/ Country) :</strong>
  <textarea name="buyer" type="text" size="30" maxlength="30"></textarea>
  <strong><b> Reference :</strong>
  <input name="ref" type="text"  value="" size="30" maxlength="30"  />
  </tr>
<tr><td height="20"><strong><b>Potential Annual Volume :</strong>
  <input type="text" name="potential_annual" size="20" value=""/>
      <b><strong>Target Price :</strong>
      <input type="text" name="target_price" size="20" value=""/> 
  <b> <strong>Market Application :</strong>  <input type="text" name="market_app" size="30" value=""/></td>
  </tr>

<tr>
<td height="57"><b><strong>Instruction :
</strong>
  <label><br>
  <input name = "instruct[]" type = "checkbox" value ="safety" onClick="enableElement(this.form.elements['inp1']);" />
      REFER FAX/ LETTER ATTACHED FOR FULL 
      DETAILS. </label> 
  <label>
      <input name="instruct[]" type="checkbox" value="duplicate" onClick="enableElement(this.form.elements['inp2']);"/> 
      DUPLICATE 
      <input name="instruct[]" type="checkbox" value="new" onClick="enableElement(this.form.elements['inp3']);"/>
NEW PRODUCT DEVELOPMENT</label>
   <label><br>
  </label>
  <label> 
     <input name="instruct[]" type="checkbox" value="art" onClick="enableElement(this.form.elements['inp4']);"/>
      MODIFICATION OF ART/MODEL : 
      <input type="text" name="inp4" size="30" disabled="disabled"/>
    </label>
  <label><br>
        <input name="instruct[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp5']);"/>
      OTHERS :  <input type="text" name="inp5" size="30" disabled="disabled"/>
  </label></td>
</tr>
 <tr><td height="20"><center><font color="#0000FF"> 
   <strong><em>UPPER </em></strong></font>
 </center></td></tr> 
<tr>
  <td height="58"><b><strong>Compound / Colour :</strong>
    <input type="text" name="comp_colour" size="30" value=""/>  <br><b><strong>Pattern :  
        </strong>
    <label>
      <input name="pattern[]" type="checkbox" value="kid" onClick="enableElement(this.form.elements['inp1']);"/>KID </label>
      <label> 
        <input name="pattern[]" type="checkbox" value="nappa" onClick="enableElement(this.form.elements['inp2']);"/>NAPPA</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="bull" onClick="enableElement(this.form.elements['inp3']);"/>BULL</label>
      <label> 
        <input name="pattern[]" type="checkbox" value="plain" onClick="enableElement(this.form.elements['inp4']);"/>PLAIN </label>
       <label>
         <input name="pattern[]" type="checkbox" value="others" onClick="enableElement(this.form.elements['inp5']);"/>
         OTHERS (Please Specify): 
         <input type="text" name="inp5" size="15" disabled="disabled"/>
       </label></td>
    </tr>
      <tr><td height="20"><center><font color="#0000FF"> 
        <strong><em>SOLE </em></strong></font>
      </center></td></tr>
    <tr>
  <td height="20"><b><strong>Sole Compound / Colour :</strong>
    <input type="text" name="sole_colour" size="30" value=""/>
<b> <strong>Calender Roll/Pattern : </strong>
<input type ="text" name="calender_pattern" size="30" value=""/></td></tr>
<tr>
  <td height="20"><strong><b>Heel Types :</strong>
    <input type="text" name="heel_type" size="30" value=""/>
<br><b><strong>Colour :</strong>
<label>
  <input name="heel_colour[]" type="checkbox" value="same_as_sole" onClick="enableElement(this.form.elements['inp1']);"/>Same as Sole </label>
<label>
<input name="heel_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" disabled="disabled"/>
</label></td></tr>
<tr>
<td height="20"><b><strong>Moulded Sole Type :</strong>  <input type="text" name="moul_sole" size="30" value=""/> </td>
</tr>
<tr> 
<td height="20"><b><strong>Top Foxing Pattern/Roll :</strong>
  <input type="text" name="top_fox" size="30" value=""/>
<br><b> <strong> Colour: </strong>
<label>
<input name="top_colour[]" type="checkbox" value="same_as_upper" onClick="enableElement(this.form.elements['inp1']);"/>Same as Upper</label>
<label>
<input name="top_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);" />OTHERS (Please Specify) : <input type="text" name="inp2" size="28" disabled="disabled"/></label>
</td>
</tr>
<tr>
<td height="20"><strong><b>Bottom Foxing Pattern/Roll :</strong>
  <input type="text" name="bottom_fox" size="30" value=""/>
<br><b><strong>Colour : 
</strong>
<label>
  <input name="bottom_colour[]" type="checkbox" value="upper/sole" onClick="enableElement(this.form.elements['inp1']);"/> Same as Upper/Sole</label>
<label>
<input name="bottom_colour[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp2']);"/> 
OTHERS (Please Specify) : 
<input type="text" name="inp2" size="28" value="" disabled="disabled"/></label> </td>
<tr>
<td height="20"><b><strong>Last Type :</strong>
  <input type="text" name="last_type" size="20" value=""/>
<b> <strong>Boots Height :</strong>
<input type="text" name="height" size="10" value=""/>
<b> <strong>Size :</strong>
<input type="text" name="size" size="10" value=""/> 
 <b> <strong>Total Pairs : </strong>
 <input type="text" name="total_pairs" size="10" value=""/>
<br><b><strong>Date Required :</strong> <input name="date_required" type="date" value=""/></td>
</tr>
<tr>
                <td height="20"><b><strong>Lining Material/ Colour :</strong> </span></div>
                <input name="lin_material" type="text"  value="" size="30"/></td>

<tr>
<td height="20"><b><strong>Cuff Material/Colour :
</strong>
  <label>
<input name="cuff_material[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="cuff_material[]" type="checkbox" value="" onClick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
<tr>
<td height="20"><b><strong>Lace/Colour :</strong>
<label>
  <input name="lace_colour[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/> N/A </label>
<label>
<input name="lace_colour[]" type="checkbox" value="" onClick="enableElement(this.form.elements['inp2']);"/><input type="text" name="inp2" size="30" value="" disabled="disabled"/></label>
</td></tr>
  <tr>
    <td height="20"><b><strong>Brand :</strong>   <input type="text" name="brand" size="30" value=""/> 
      <b><strong>Colour :</strong>   <input type="text" name="color" size="30" value=""/></td>
    </tr>
<tr>
<td height="20"><b><strong>Lacquer Finishing :</strong>
<label> 
  <input name = "lacquer_finishing[]" type = "checkbox" value ="gloss" onClick="enableElement(this.form.elements['inp1']);"/>
  GLOSS </label>
    <label> 
      <input name = "lacquer_finishing[]" type = "checkbox" value = "dull" onClick="enableElement(this.form.elements['inp2']);"/>
      DULL </label>
    </td></tr>
<tr>
<td height="20"><b><strong>Safety Standards to Confirm :</strong>
<label><input name="safety[]" type="checkbox" value="n/a" onClick="enableElement(this.form.elements['inp1']);"/>N/A</label>
<label><input name="safety[]" type="checkbox" value="en-" onClick="enableElement(this.form.elements['inp2']);"/>EN-
<input type="text" name="inp2" disabled="disabled" size="10"></label>
<label><input name="safety[]" type="checkbox" value="csa" onClick="enableElement(this.form.elements['inp3']);"/>CSA</label>
<label><input name="safety[]" type="checkbox" value="astm" onClick="enableElement(this.form.elements['inp4']);"/>ASTM</label>
<label><input name="safety[]" type="checkbox" value="sirim" onClick="enableElement(this.form.elements['inp5']);"/>SIRIM</label>
<label>
<input name="safety[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp6']);"/>Others:<input type="text" name="inp6" size="10" disabled="disabled"/>
</label></td>
</tr>
<tr>
<td height="75"><b><strong>NotWithStanding 15.0 Above, Other Features Required :
</strong>
  <label><br>
<input name="features[]" type="checkbox" value="none" onClick="enableElement(this.form.elements['inp1']);"/>NONE</label>
<label>
<input name="features[]" type="checkbox" value="steel_toe_cap" onClick="enableElement(this.form.elements['inp2']);"/>STEEL TOE CAP</label>
<label>
<input name="features[]" type="checkbox" value="steel_mid_sole" onClick="enableElement(this.form.elements['inp3']);"/>STEEL MID SOLE</label>
<label>
<input name="features[]" type="checkbox" value="steel_shank" onClick="enableElement(this.form.elements['inp4']);"/>STEEL SHANK</label>
<label>
<input name="features[]" type="checkbox" value="anti_static" onClick="enableElement(this.form.elements['inp5']);"/>ANTI-STATIC</label>
<label>
  <input name="features[]" type="checkbox" value="fire_retardant" onClick="enableElement(this.form.elements['inp6']);"/>
  FIRE RETARDANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="oil_resistant_sole_upper" onClick="enableElement(this.form.elements['inp7']);"/>OIL RESISTANT SOLE & UPPER</label>
<label>
  <input name="features[]" type="checkbox" value="chainsaw_protection" onClick="enableElement(this.form.elements['inp8']);"/>
CHAINSAW PROTECTION</label>
<label>
  <input name="features[]" type="checkbox" value="anti_slip_sole" onClick="enableElement(this.form.elements['inp9']);"/>
  ANTI-SLIP SOLE</label>
<label>
  <input name="features[]" type="checkbox" value="electric_shock_resistant" onClick="enableElement(this.form.elements['inp10']);"/>ELECTRIC SHOCK RESISTANT</label>
<label>
  <br>
  <input name="features[]" type="checkbox" value="other" onClick="enableElement(this.form.elements['inp11']);"/>
  OTHERS (please specify) :
<input type="text" name="inp11" size="38" disabled="disabled"/></label>
</td></tr>

<tr>
<td height="20"><b><strong>Sketches/Drawings Attached :
</strong>
  <label> 
      <input name = "attachment[]" type = "radio" value ="yes" checked/>YES</label>
      <label>
      <input name="attachment[]" type="radio" value="no"/>NO</label>

</td>      
</tr>
<tr>
  <td height="45"><b><strong>Other Description/Remarks :</strong>  <textarea name="remarks" type="text" rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td height="20"><center><font color="#0000FF"><em><strong>#Sample Distribution</strong></em></font>
</center></td> 
</tr>
<tr>
<td height="20"><strong><strong>TO :</strong><select name = "department" >
  <option selected> Department </option>
  <option> Marketing Department</option>
  <option> Technical Department </option>
  <option> Product Development Section</option>
</select> 
  <strong><b> Pairs :</strong>
  <input type="text" name="pair" size="10"/>
  <br>
<strong><b> Requested By :</strong>  <input type="text" name="request_by" size="30" value=""/></td>
</tr>

<tr>
<tr>
</tr>
<tr>
<td>
<label>
<input name="notify" type="checkbox" value="notify" checked/> 
<em><strong>Send notification for approval. </strong></em><strong></strong></label>
(Make sure it's always checked!)</td>
</tr>
<tr>
<td height="30"><center><input type = "submit" value = "Submit Requisition"  name="Submit" /></center></td>

</tr>
</form>
</tr>
</table>
<?php
echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";
include('includes/footer.html');
?>
</body>
</html>

And this is my Mysqli.php file

<?php

   function db_connect()
{
    // Connect to the database. This requires the PDO and PDO_Mysql modules to be installed in PHP.
    // TODO: Store this connection string in a config file instead of hardcoded
    return new PDO('mysql:host=localhost;dbname=ccse', 'root', '');
}
// Helper function to prepare and execute a statement with parameters immediately
function db_query($conn, $sql, $params=array()) {
    $query = $conn->prepare($sql);
    if($query->execute($params)) {
        return $query->fetchAll();
    } else {
        return array();
    }
}
?>

Ans this is my table for requisition in database.

-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 10, 2014 at 04:44 AM
-- Server version: 5.5.16
-- PHP Version: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `ccse`
--

-- --------------------------------------------------------

--
-- Table structure for table `requisition`
--

CREATE TABLE IF NOT EXISTS `requisition` (
  `req_id` int(100) NOT NULL AUTO_INCREMENT,
  `fdate` varchar(255) DEFAULT NULL,
  `ref_no` int(100) DEFAULT NULL,
  `from` varchar(255) DEFAULT NULL,
  `copy` varchar(255) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `buyer` varchar(255) DEFAULT NULL,
  `ref` varchar(255) DEFAULT NULL,
  `potential_annual` varchar(255) DEFAULT NULL,
  `target_price` varchar(255) DEFAULT NULL,
  `market_app` varchar(255) DEFAULT NULL,
  `instruct` varchar(255) DEFAULT NULL,
  `comp_colour` varchar(255) DEFAULT NULL,
  `pattern` varchar(255) DEFAULT NULL,
  `sole_colour` varchar(255) DEFAULT NULL,
  `calender_pattern` varchar(255) DEFAULT NULL,
  `heel_type` varchar(255) DEFAULT NULL,
  `heel_color` varchar(255) DEFAULT NULL,
  `moul_sole` varchar(255) DEFAULT NULL,
  `top_fox` varchar(255) DEFAULT NULL,
  `top_colour` varchar(255) DEFAULT NULL,
  `bottom_fox` varchar(255) DEFAULT NULL,
  `bottom_colour` varchar(255) DEFAULT NULL,
  `last_type` varchar(255) DEFAULT NULL,
  `boots_height` varchar(255) DEFAULT NULL,
  `size` varchar(255) DEFAULT NULL,
  `total_pairs` varchar(255) DEFAULT NULL,
  `date_required` varchar(255) DEFAULT NULL,
  `lin_material` varchar(255) DEFAULT NULL,
  `cuff_material` varchar(255) DEFAULT NULL,
  `lace_colour` varchar(255) DEFAULT NULL,
  `brand` varchar(255) DEFAULT NULL,
  `colour` varchar(255) DEFAULT NULL,
  `lacquer_finishing` varchar(255) DEFAULT NULL,
  `safety` varchar(255) DEFAULT NULL,
  `features` varchar(255) DEFAULT NULL,
  `attachment` varchar(255) DEFAULT NULL,
  `remarks` varchar(255) DEFAULT NULL,
  `department` varchar(255) DEFAULT NULL,
  `pair` varchar(255) DEFAULT NULL,
  `request_by` varchar(255) DEFAULT NULL,
  `approval_status` varchar(255) DEFAULT 'pending',
  PRIMARY KEY (`req_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

these are my files for now. but I still cant get any out put and when i click the submit button its refresh back the form. I am also dont know where i did wrong in this. I am struggling with this for past few weeks, but still cant solve it. Thank you for your time. :)

1

<Unrelated>
Your db will be sluggish methinks with all those 255/varchar fields. The majority from what i can see do not need to be so big. Possibly you could make more tables and relate them to the requisition table. Colour for example. Target price I would thing would be better as a float/decimal?
</Unrelated>

0

I see, you are using the updated version of the functions from our comments on my thread. You need to add this line after including the file:

require_once("Mysqli.php");
$conn = db_connect(); // Make the connection

And it looks like in your latest version you are not actually calling the query, and the $tokens value isn't quite built correct, so adjust that part to be like this:

// Count comes from the number of items in the count($row) of the array,
// leave the '?' here as it is part of the PDO query
$tokens = array_fill('?', count($row));

$query = 'INSERT INTO requisition ( fdate, ref_no, from, copy, description, buyer, ref, potential_annual, target_price, market_app, instruct, comp_colour, pattern, sole_colour, calender_pattern, heel_type, heel_colour, moul_sole, top_fox, top_colour, bottom_fox, bottom_colour, last_type, boots_height, size, total_pairs, date_required, lin_material, cuff_material, lace_colour, brand, colour, lacquer_finishing, safety, features, attachment, remarks, department, pair, request_by, approval_status ) VALUES ('.implode(',', $tokens).')';

// Query should have a bunch of ? marks at the end of it
print $query;

// Actually run the query
$result = db_query($conn, $query);

if($result)
{
     echo "Requisition Successfully Added!";
}
else
{
    if(DEBUG) {
        echo "<b>MySQL error:</b><br/>";
        print_r($pdo->errorInfo());
    } else {
        echo "<b>Sorry, we could not process your request</b><br/>";
    }
}

Edited by Isaac_4

0

Also, related to <unrelated> topic </unreleated> ;):

varchar(255) should be okay - char(255) would for sure be bad as it always takes up 255 characters. varchar on the other hand only takes what characters it needs, up to the limit you give it (no more than 255 characters in this case) although it is always a good idea to set lengths to realistic values so that users cannot mess up your system by putting in long values. So this is more of a usability issue for any admin screens than a true performance issue in this case.

You should also do things like strip_tags() on all your $_POST values for security reasons.

Edited by Isaac_4

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.