Jump to content

How to write this ??


june_c21

Recommended Posts

hi ,

1)  why it only insert 1 line of data into the database only ?

2) how to make it input all the lines that user input and ignore the blank if user didn't input anything ?

 

 

here is my html code

 

<p><strong>RCA DATABASE</strong></p>
<p> </p>
<?php
include './includes/header.php';
$id = $_GET['id'];
$query = "SELECT * FROM corrective_action WHERE id=$id ";
$result = mysql_query($query, $dblink);

while($myrow = mysql_fetch_row($result))
  {
  $id = $myrow [0];
  $causes = $myrow [1];
  $corrective_action = $myrow[2];
  $name = $myrow[3];
  $date= $myrow[4];
    $remarks = $myrow[5];
  }
?>

<form name="form1" method="post" action="view_all1.php?id=<?php echo $id ?>">
  <table width="1133" border="0" cellspacing="3" cellpadding="0">
  <tr>
    <td width="20"><div align="center"><strong>No</strong></div></td>
    <td width="200"><div align="center"><strong>Causes</strong></div></td>
    <td width="317"><div align="center"><strong>Corrective Action </strong></div></td>
    <td width="146"><div align="center"><strong>Name Assigned </strong></div></td>
    <td width="133"><div align="center"><strong>Start Date (YYYY/MM/DD) </strong></div></td>
    <td width="296"><div align="center"><strong>Remarks</strong></div></td>
  </tr>
  
  <tr>
    <td><p><strong>1</strong></p>    </td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea> </td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>2</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>3</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>4</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>5</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>6</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>7</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>8</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>9</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
  <tr>
    <td><strong>10</strong></td>
    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>
    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>
    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>
    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>
    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>
  </tr>
</table>
<p>Status : </p>
<p><select name="status" id="status">
      <option value="complete">complete</option>
      <option value="pending" selected="selected">pending</option>
    </select>
  </p>
  <p> </p>
  <label>
    <input type="submit" name="Submit" value="Submit">
  </label>
  </p>
</form>


 

my php code

 

<?php
include './includes/header.php';


$id = $_GET ['id'];
$causes = $_POST ['causes'];
  $corrective_action = $_POST ['corrective_action'];
  $name = $_POST ['name'];
  $date = $_POST ['date'];
  $remarks = $_POST ['remarks'];
   $status = $_POST ['status'];


$query= "INSERT INTO corrective_action( id, causes, corrective_action, name, date, remarks ) VALUES ('$id','$causes','$corrective_action','$name','$date','$remarks') ";
$result = mysql_query($query,$dblink);



$query1= "UPDATE event SET status= '$status' where id=$id ";
$result1 = mysql_query($query1,$dblink);

?>

Link to comment
https://forums.phpfreaks.com/topic/195175-how-to-write-this/
Share on other sites

After a quick look your HTML form should be inside the WHILE loop so that each row gets it's won data.  That would mean you could give each INPUT a different name and that would let you save more than one row of data.  It might look like you have more than one row but they will all be identical so it only counts once.

Link to comment
https://forums.phpfreaks.com/topic/195175-how-to-write-this/#findComment-1025844
Share on other sites

Your form has multiple copies of each field.  For example, the causes field appears in each row.

 

I hate to say this to people but you are wrong on so many things that your best bet would be to learn PHP from the start so that you understand what i posted above.  Short of me writing the code for you it's not going to work and then you would learn nothing.

 

Sorry

Link to comment
https://forums.phpfreaks.com/topic/195175-how-to-write-this/#findComment-1025905
Share on other sites

Ok, a hint...

 

you would place this portion into a loop (either a WHILE or a FOR) read up on loops

 

<tr>    <td><strong>10</strong></td>    <td><textarea name="causes" cols="30" id="causes" value="<?php echo $causes ?>"></textarea></td>    <td><textarea name="corrective_action" cols="50" id="corrective_action" value="<?php echo $corrective_action ?>"></textarea></td>    <td><input name="name" type="text" id="name" value="<?php echo $name ?>" /></td>    <td><input name="date" type="text" id="date" value="<?php echo $date ?>" /></td>    <td><textarea name="remarks" cols="50" id="remarks" value="<?php echo $remarks ?>"></textarea></td>  </tr>

 

You would change the coding so that each field was actually become part of an array

 

ie cause[0], next time cause[1], cause[2] etc  - read up on arrays

 

then when your from processing file gets the info, it will also use a loop to go thru the info.

 

Make sense?

 

 

Link to comment
https://forums.phpfreaks.com/topic/195175-how-to-write-this/#findComment-1025911
Share on other sites

OK Im too lazy to read all that code.

 

I think your code should look like this.

 

while(some thing some thing){
   echo "<td><textarea name='causes' cols='30' id='causes' value='$causes'></textarea></td>";
}

 

The above will insert textareas untill the loop ends.

Becarefull of the naming coz the name will be the same and you might have difficulties in retrieving them.

 

 

Link to comment
https://forums.phpfreaks.com/topic/195175-how-to-write-this/#findComment-1025916
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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