Angelojoseph17 Posted October 21, 2010 Share Posted October 21, 2010 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/ Share on other sites More sharing options...
litebearer Posted October 21, 2010 Share Posted October 21, 2010 you have a space in fault description sql="INSERT INTO repairs (machine_number,reported_by,repair_start_date,fault description,repaired_by,part_used) Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1124848 Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2010 Share Posted October 21, 2010 You'll never get a value out of it as long as your <select> tag doesn't have a name= attribute . . . Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1124850 Share on other sites More sharing options...
Angelojoseph17 Posted October 22, 2010 Author Share Posted October 22, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125174 Share on other sites More sharing options...
Pikachu2000 Posted October 22, 2010 Share Posted October 22, 2010 Paste the error message in here. Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125201 Share on other sites More sharing options...
Angelojoseph17 Posted October 22, 2010 Author Share Posted October 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125208 Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125213 Share on other sites More sharing options...
Angelojoseph17 Posted October 22, 2010 Author Share Posted October 22, 2010 thanks for that lightbear what is wierd is that it creates a new record on the database with empty fields when i press submit and it churns this error message out now. Notice: Undefined index: part_number in /var/www/engineering/insert.php on line 16 You records have been updated Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125220 Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 the code you showed thus far does not have that variable and/or field displayed, so we need to see the current version of your insert.php Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125226 Share on other sites More sharing options...
Angelojoseph17 Posted October 22, 2010 Author Share Posted October 22, 2010 <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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125230 Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 please display the field list of your 'repairs' table Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1125339 Share on other sites More sharing options...
Angelojoseph17 Posted October 25, 2010 Author Share Posted October 25, 2010 | 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 | Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1126093 Share on other sites More sharing options...
litebearer Posted October 25, 2010 Share Posted October 25, 2010 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/216473-dymanic-drop-down-box-insert/#findComment-1126183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.