Jump to content

Dymanic drop down box / insert


Angelojoseph17

Recommended Posts

Created a dynamic drop down box which pulls values from three columns from the database. However my insert function is not injecting the values in and i get an undefined index error.

html>

 

<div id = "form" align="center">

 

<h1> Create a repair Ticket </h1>

 

<?php

// Connects to Database

mysql_connect("localhost", "bla", "bla") or die(mysql_error());

mysql_select_db("bla bla") or die(mysql_error());

 

?>

 

<form>
<p> Choose the machine to be repaired: </p> 
<select>
<?php 
// This query selects the machine_id and name from the machine table and stores in the "result" variable. 
$sql="SELECT machine_id,description FROM machine";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['machine_id'].">". $data['description']."</option>"); 
?>
<?php } ?>
</select>

<p> Choose the engineer to be allocated: </p> 
<select>
<?php 
// This query selects engineer_id and name 
$sql="SELECT engineer_id,engineer_name FROM engineer";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['engineer_id'].">". $data['engineer_name']."</option>"); 
?>
<?php } ?>
</select>

<p> Choose the part to be allocated: </p> 
<select>
<?php 
// This query selects the part_number and description 
$sql="SELECT part_number,description FROM parts";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['part_number'].">". $data['description']."</option>"); 
?>
<?php } ?>
</select>		

<p> Reported By: <input type="text" name="reported_by" /> </p>

<p><b>Fault Description</b> </p>
<textarea cols="50" rows="4" name="fault_description" align="right" wrap="virtual"></textarea>

</form> 
<form action="insert.php" method="post">

<input type="Submit">

</div>   

 

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
$con = mysql_connect("localhost","bla","bla");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("bla", $con);

$machine_id= $_POST['machine_id'];
$reportedby= $_POST['reported_by'];
$Date = date("d/m/y");
$fault_description =$_POST['fault_description'];
$repaired_by = $_POST['engineer_name'];
$part_used = $_POST['description'];

$sql="INSERT INTO repairs (machine_number,reported_by,repair_start_date,fault description,repaired_by,part_used)
VALUES
('".$machine_id."', '".$reportedby."','".$Date."','".$fault_description."','".$repairedby."','".$part_used."')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con);


echo "You records have been updated";
?>

 

 

 

Link to comment
Share on other sites

I've added the select statements and it still creates that error message

 

<form>
<p> Choose the machine to be repaired: </p> 
<select name ="machine_id">
<?php 
// This query selects the machine_id and name from the machine table and stores in the "result" variable. 
$sql="SELECT machine_id,description FROM machine";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['machine_id'].">". $data['description']."</option>"); 
?>
<?php } ?>
</select> 

<p> Choose the engineer to be allocated: </p> 
<select name ="engineer_name">
<?php 
// This query selects engineer_id and name 
$sql="SELECT engineer_id,engineer_name FROM engineer";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['engineer_id'].">". $data['engineer_name']."</option>"); 
?>
<?php } ?>
</select>

<p> Choose the part to be allocated: </p> 
<select name ="description">
<?php 
// This query selects the part_number and description 
$sql="SELECT part_number,description FROM parts";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo ("<option value=".$data['part_number'].">". $data['description']."</option>"); 
?>
<?php } ?>
</select>		

<p> Reported By: <input type="text" name="reported_by" /> </p>

<p><b>Fault Description</b> </p>
<textarea cols="50" rows="4" name="fault_description" align="right" wrap="virtual"></textarea>

</form> 
<form action="insert.php" method="post">

<input type="Submit">

</div>   

Link to comment
Share on other sites

Notice: Undefined index: machine_id in /var/www/engineering/insert.php on line 13 Notice: Undefined index: reported_by in /var/www/engineering/insert.php on line 14 Notice: Undefined index: fault_description in /var/www/engineering/insert.php on line 16 Notice: Undefined index: engineer_name in /var/www/engineering/insert.php on line 17 Notice: Undefined index: description in /var/www/engineering/insert.php on line 18 Notice: Undefined variable: repairedby in /var/www/engineering/insert.php on line 22 You records have been updated

Link to comment
Share on other sites

some minor changes..

 

the form

<form action="insert.php" method="post">
<p> Choose the machine to be repaired: </p> 
<select name ="machine_id">
<?php 
// This query selects the machine_id and name from the machine table and stores in the "result" variable. 
$sql="SELECT machine_id,description FROM machine";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP echo $data['machine_id']; ?>"><?PHP echo $data['description']; ?></option><br> 
	<?php
}
 ?>
</select> 

<p> Choose the engineer to be allocated: </p> 
<select name ="engineer_name">
<?php 
// This query selects engineer_id and name 
$sql="SELECT engineer_id,	engineer_name FROM engineer";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP ech $data['engineer_id']; ?>"><?PHP echo $data['engineer_name']; ?></option><br>
	<?PHP
}
?>
</select>

<p> Choose the part to be allocated: </p> 
<select name ="description">
<?php 
// This query selects the part_number and description 
$sql="SELECT part_number,description FROM parts";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP echo $data['part_number']; ?>"><?PHP echo $data['description']; ?></option><br>
	<?php 
}
</select>
<p> Reported By: <input type="text" name="reported_by" /> </p>
<p><b>Fault Description</b> </p>
<textarea cols="50" rows="4" name="fault_description" align="right" wrap="virtual"></textarea>
<br>
<input type="Submit">
</form> 

the insert

?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
$con = mysql_connect("localhost","bla","bla");
if (!$con){
die('Could not connect: ' . mysql_error());
}

mysql_select_db("bla", $con);

$machine_id= $_POST['machine_id'];
$reportedby= $_POST['reported_by'];
$Date = date("d/m/y");
$fault_description =$_POST['fault_description'];
$repaired_by = $_POST['engineer_name'];
$part_used = $_POST['description'];


$sql="INSERT INTO repairs (machine_number, reported_by, repair_start_date, fault description, repaired_by, part_used) VALUES ('$machine_id', '$reportedby', '$Date', '$fault_description' , '$repairedby', '$part_used')";

$result = mysql_query($sql);

mysql_close($con);


echo "You records have been updated";
?>

Link to comment
Share on other sites

<html>

<div id = "form" align="center"> 

<h1> Create a repair Ticket </h1>	

<?php
// Connects to Database
mysql_connect("localhost", "angelo", "password") or die(mysql_error());
mysql_select_db("church_engineers") or die(mysql_error());

?>

<form action="insert.php" method="post">
<p> Choose the machine to be repaired: </p> 
<select name ="machine_id">
<?php 
// This query selects the machine_id and name from the machine table and stores in the "result" variable. 
$sql="SELECT machine_id,description FROM machine";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP echo $data['machine_id']; ?>"><?PHP echo $data['description']; ?></option><br> 
	<?php
}
 ?>
</select> 

<p> Choose the engineer to be allocated: </p> 
<select name ="engineer_name">
<?php 
// This query selects engineer_id and name 
$sql="SELECT engineer_id,engineer_name FROM engineer";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP echo $data['engineer_id']; ?>"><?PHP echo $data['engineer_name']; ?></option><br>
	<?PHP
}
?>
</select>

<p> Choose the part to be allocated: </p> 
<select name ="part_number">
<?php 
// This query selects engineer_id and name 
$sql="SELECT part_number,description FROM parts";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
	?>
	<option value="<?PHP echo $data['description']; ?>"><?PHP echo $data['part_number']; ?></option><br>
	<?PHP
}
?>
</select>

<p> Reported By: <input type="text" name="reported_by" /> </p>
<p><b>Fault Description</b> </p>
<textarea cols="50" rows="4" name="fault_description" align="right" wrap="virtual"></textarea>
<br>
<input type="Submit">
</form> 

 

 

 

 

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
$con = mysql_connect("localhost","angelo","password");
if (!$con){
die('Could not connect: ' . mysql_error());
}

mysql_select_db("church_engineers", $con);

$machine_id= $_POST['machine_id'];
$reportedby= $_POST['reported_by'];
$Date = date("d/m/y");
$fault_description =$_POST['fault_description'];
$repaired_by = $_POST['engineer_name'];
$part_used = $_POST['part_number'];


$sql="INSERT INTO repairs (machine_number, reported_by, repair_start_date, fault description, repaired_by, part_used) VALUES ('$machine_id', '$reportedby', '$Date', '$fault_description' , '$repaired_by', '$part_used')";

$result = mysql_query($sql);

mysql_close($con);


echo "You records have been updated";
?>

 

 

 

Link to comment
Share on other sites

| Field            | Type        | Null | Key | Default            | Extra                                                                                                          |

+-------------------+--------------+------+-----+---------------------+---------                                                                                                -------+

| repair_id        | mediumint(9) | NO  | PRI | NULL                | auto_inc                                                                                                rement |

| machine_number    | varchar(100) | YES  | MUL | NULL                |                                                                                                                |

| reported_by      | varchar(100) | YES  |    | NULL                |                                                                                                                |

| repair_start_date | datetime    | NO  |    | 0000-00-00 00:00:00 |                                                                                                                |

| repair_end_date  | datetime    | NO  |    | 0000-00-00 00:00:00 |                                                                                                                |

| fault_description | varchar(100) | YES  |    | NULL                |                                                                                                                |

| repaired_by      | varchar(100) | YES  | MUL | NULL                |                                                                                                                |

| part_used        | mediumint(9) | YES  | MUL | NULL                |     

Link to comment
Share on other sites

try changing this...

$sql="INSERT INTO repairs (machine_number, reported_by, repair_start_date, fault description, repaired_by, part_used) VALUES ('$machine_id', '$reportedby', '$Date', '$fault_description' , '$repaired_by', '$part_used')";

 

to this...

$sql="INSERT INTO repairs (machine_number, reported_by, repair_start_date, fault_description, repaired_by, part_used) VALUES ('$machine_id', '$reportedby', '$Date', '$fault_description' , '$repaired_by', '$part_used')";

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.