0

db name: orange
table: Name, Position, Department, Telephone, Purpose, Startdate, Enddate, Item1, Item2

input.php

<html>
<body>
<form method="post" action="conn.php">

<table width="500" border="1">

    <tr>
    <td>Name</td>
    <td><input type="textbox1" name="Name[]" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Position</td>
    <td><input type="textbox2" name="Position[]" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Department</td>
    <td><input type="textbox3" name="Department[]" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Telephone</td>
    <td><input type="textbox4" name="Telephone[]" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Purpose</td>
    <td><input type="textbox5" name="Purpose[]" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Start Date</td>
    <td><input type="textbox6" name="Startdate[]" value=""></td>
    <td> till </td>
    <td><input type="textbox7" name="Enddate[]" value=""></td>
  </tr>
</table>
<br />
<table width="500" border="1">
  <tr>
    <th scope="col">No.</th>
    <th scope="col">Hardware</th>
    <th scope="col">Model</th>
    <th scope="col">No. Inventori</th>
  </tr>
  <tr>
    <td>1.</td>
    <td><input type="textbox8" name="Item1[]" value=""></td>
    <td><input type="textbox9" name="Item1[]" value=""></td>
    <td><input type="textbox10" name="Item1[]" value=""></td>
  </tr>
  <tr>
    <td>2.</td>
    <td><input type="textbox11" name="Item2[]" value=""></td>
    <td><input type="textbox12" name="Item2[]" value=""></td>
    <td><input type="textbox13" name="Item2[]" value=""></td>
  </tr>
</table>


<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

conn.php

4
Contributors
11
Replies
49
Views
3 Years
Discussion Span
Last Post by dukumanis
0

conn.php

<?php

// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("pinjaman") or die(mysql_error());

$TextBox1 = implode(',', $_POST['Name']);
$TextBox2 = implode(',', $_POST['Position']);
$TextBox3 = implode(',', $_POST['Department']);
$TextBox4 = implode(',', $_POST['Telephone']);
$TextBox5 = implode(',', $_POST['Purpose']);
$TextBox6 = implode(',', $_POST['Startdate']);
$TextBox7 = implode(',', $_POST['Enddate']);
$TextBox = implode(',', $_POST['Item1']);
$TextBox = implode(',', $_POST['Item1']);
$TextBox = implode(',', $_POST['Item1']);
$TextBox = implode(',', $_POST['Item2']);
$TextBox = implode(',', $_POST['Item2']);
$TextBox = implode(',', $_POST['Item2']);

if(isset($_POST['submit']))
{       
    $query="INSERT INTO orange VALUES ('" . $TextBox1 . "','" . $TextBox2 . "','" . $TextBox3 . "','" . $TextBox4 . "','" . $TextBox5 . "','" . $TextBox6 . "','" . $TextBox7 . "','" . $TextBox . "','" . $TextBox . "')";     

    mysql_query($query) or die (mysql_error() );

    echo "Complete";

}

?>
0

Input.php

    <html>
    <body>
    <form method="post" action="conn.php">


<table width="500" border="1">

    <tr>
    <td>Name</td>
    <td><input type="textbox1" name="Name" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Position</td>
    <td><input type="textbox2" name="Position" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Department</td>
    <td><input type="textbox3" name="Department" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Telephone</td>
    <td><input type="textbox4" name="Telephone" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Purpose</td>
    <td><input type="textbox5" name="Purpose" value=""></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Start Date</td>
    <td><input type="textbox6" name="Startdate" value=""></td>
    <td> till </td>
    <td><input type="textbox7" name="Enddate" value=""></td>
  </tr>
</table>
<br />
<table width="500" border="1">
  <tr>
    <th scope="col">No.</th>
    <th scope="col">Hardware</th>
    <th scope="col">Model</th>
    <th scope="col">No. Inventori</th>
  </tr>
  <tr>
    <td>1.</td>
    <td><input type="textbox8" name="Item1[]" value=""></td>
    <td><input type="textbox9" name="Item1[]" value=""></td>
    <td><input type="textbox10" name="Item1[]" value=""></td>
  </tr>
  <tr>
    <td>2.</td>
    <td><input type="textbox11" name="Item2[]" value=""></td>
    <td><input type="textbox12" name="Item2[]" value=""></td>
    <td><input type="textbox13" name="Item2[]" value=""></td>
  </tr>
</table>


<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

conn.php

<?php

// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("pinjaman") or die(mysql_error());


if(isset($_POST['submit']))
{       
$TextBox1 = ($_POST['Name']);
$TextBox2 = ($_POST['Position']);
$TextBox3 = ($_POST['Department']);
$TextBox4 = ($_POST['Telephone']);
$TextBox5 = ($_POST['Purpose']);
$TextBox6 = ($_POST['Startdate']);
$TextBox7 = ($_POST['Enddate']);
$TextBox_item1 = ($_POST['Item1']);
$TextBox_item2 = ($_POST['Item2']);

$query="INSERT INTO orange VALUES ('$TextBox1','$TextBox2 ','$TextBox3','$TextBox4','$TextBox5 ','$TextBox6 ','$TextBox7 ',' $TextBox_item1','$TextBox_item2')";     
mysql_query($query) or die (mysql_error() );
echo "Complete";
}

?>

try this

0

RESULT: Notice: Array to string conversion in C:\xampp\htdocs\pinjaman1\2.php on line 16

Notice: Array to string conversion in C:\xampp\htdocs\pinjaman1\2.php on line 16
Complete

Attachments Capture.PNG 14.96 KB
0

tbl name: orange
column :Name, Position, Department, Telephone, Purpose, Startdate, Enddate, Item1, Item2

0

Since $_POST['Item1'] and $_POST['Item2'] are array, you have to convert it to string before saving to your table.

Replace
$TextBox_item1 = ($_POST['Item1']);
with this to
$TextBox_item1 = implode(',', $_POST['Item1']);

And

$TextBox_item2 = ($_POST['Item2']);
with this to
$TextBox_item2 = implode(',', $_POST['Item2']);

0

Hi,
Your type of inputs is wrong. Change type with "text" like this:

<input type="text" name="Name" value="">

textbox1, textbox2 and so on not exist like type of inputs.

0

acctually i have a problem in making reservation form of hardware. my form is okay but i have problem in making the database. i hope someone can help me.

Attachments Capture.PNG 10.62 KB
0

As seen in your picture you need 3 table; one for employee, one for hardware and one for reservation.
employee [id,name,position,department,telephone,purpose,start_date]
id is primary key
hardware
[id,hardware,model,inventory,other fields]
id is primary key
reservation
[id,idemp, idhdw,other fields]
id - primary key
idemp - foreing key, link with employee table
idhdw - foreing key, link with harware table

Edited by albucurus

This question has already been answered. 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.