Jump to content

Need someone here to help build code


Stephenung

Recommended Posts

hi guys,

 

i am new here and looking for help on build a form and php code to send to mysql database's table with multiple rows inserted and AUTO Increment id.

 here what i have tried, but i gues im not good at php coding:

<body>

<form name="input_primary" action="test5.php" method="post">

    <font color="#000000"><strong>Customer Name</strong></font><input name="cust_name" type="text" />

<table width="100%" border="1px solid black" id="maintab">
  <tr>
      <th scope="col">JOB ID</th>
    <th scope="col">Make/Model</th>
    <th scope="col">Serial/IMEI</th>
    <th scope="col">Faulty</th>
    <th scope="col">Reapir</th>
    <th scope="col">Accessory</th>
    <th scope="col">Condi</th>
    <th scope="col">Intern Note</th>
    <th scope="col">Status</th>
    <th scope="col">Date Add</th>
  </tr>
<?php
//Repeat element inside loop 5 times
for($i=0;$i<5;$i++) {
?>
  <tr>
      <td>
        <input name="job_id[]" type="hidden"  />
    </td>
    <td>
        <input name="makemodel[]" type="text" size="20px" />
    </td>
    <td>
        <input name="serial[]" type="text" size="20px" />
    </td>
    <td>
         <input name="faulty[]" type="text" />
    </td>
    <td>
        <input name="repair[]" type="text"  />
    </td>
    <td>
         <input name="accessory[]" type="text" size="20px" />
    </td>
    <td>
         <input name="conditions[]" type="text" size="30px" />
    </td>
    <td>
         <input name="intern_note[]" type="text" />
    </td>
    <td>
         <input name="status[]" type="text" size="20px" />
    </td>
    
  </tr>
<?php
}
?>
</table>
<input type="submit" value="Save results!" name="submit" />
</form>

</body>

 

and here is my PHP

 

<?php

include "storescripts/connect_to_mysql.php";

if (isset($_POST["job_id"])) $job= $_POST["job_id"];
if (isset($_POST["makemodel"])) $model = $_POST["makemodel"];
if (isset($_POST["serial"])) $serial = $_POST["serial"];
if (isset($_POST["faulty"])) $faulty = $_POST["faulty"];
if (isset($_POST["repair"])) $repair = $_POST["repair"];
if (isset($_POST["accessory"])) $accessory = $_POST["accessory"];
if (isset($_POST["conditions"])) $conditions = $_POST["conditions"];
if (isset($_POST["intern_note"])) $intern_note = $_POST["intern_note"];
if (isset($_POST["status"])) $status = $_POST["status"];
//$url = $_POST["url_target"];
 
 
$sql = "INSERT INTO Repair(`job_id`,`makemodel`,`serial`,`faulty`,`repair`,`accessory`,`conditions`,`intern_note`,`status`,`date_added`) VALUES('job','$model','$serial','$faulty','$repair','$accessory','$conditions','$intern_note','$status', now())";

?>

 

When i submit the button, nothing heppen, no errors and no data create in my mysql table at all.

can anyone help me with this?

 

thanks in advanced

Stephen

Edited by Stephenung
Link to comment
Share on other sites

Whare do you actually execute the query? All I see is the defining of a possible query in which I see one likely problem. The query is defining the ID as the string 'job' for all records. I would suspect that field should be an auto-increment ID field, in which case leave it off of the INSERT query entirely. So, once you execute the query add an or die() to it to see if there are any errors generated.

 

 

$result = mysql_query($sql) or die("Query: $sql <br>Error: " . myslq_error());
Link to comment
Share on other sites

So OP - have you taken Psycho's advice and fixed your initial problems?

 

If you have I hope you also have learned to turn on error checking, validate your inputs, and practice safe data updating.  Your code is woefully lacking in any of those things and you are only asking for trouble down the road.  Must each row contain all of these fields?  You don't check for that.  Also - since you are using arrays as your input values, you may have a problem with the last field - your datetime one, since you are not providing an array of values for it.

 

You say there are no errors showing.  Well since you don't run a query I can believe that, but without error checking turned on, you don't even know if your script has other errors.

 

PS - is "size=20px" a valid attribute of an <input> tag?  I think it's just "20".

 

Looking forward to your next post.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.