delete works if i use text input.dose not work drop downmenu DB using php

Hi
I have tryed a form page with textinput and this works but when i get names from DB and use then in dropdown box from a DB it dose not work… well the names show up fine in the HTML FORM just dose not delete them from DB

My script works on the html page as it should it shows up the names in a drop down menu from a database called (test) table called (teacher) row called (name)
I have attached image 1 to show my script on the HTML form using php.php script to get the names from the database to the HTML FORM…

[php]]

<?php include('php.php'); ?>

DEL Teacher: <?php echo $options ?>

[/php]

HTML Form shows the teachers names in dropdown menu

*****Script called test2.1.php
[php]]

Delete Student Form

Delete a Teacher Record

Enter the Name of the Teacher to be deleted:

<?php include('php.php'); ?>

DEL Teacher: <?php echo $options ?>

[/php]

*****Script called php.php

php script looks to the DATABASE test and gets the names of the teachers lines 18 to 22 deal with teachers names

[php]]<?php

// Connect to server
// Replace username and password by your details

$db = @mysql_connect(“localhost”,“root”,“iqonr301”);
if (!$db)
{
do_error(“Could not connect to the server”);
}

// Connect to the database
// Note that your database will be called username

@mysql_select_db(“test”,$db)or do_error(“Could not connect to the database”);

//connect to db first
$options = ‘’;
$teachers = mysql_query(‘SELECT * FROM teacher ORDER BY name ASC’);
while($teacher = mysql_fetch_array($teachers)) {
$options .= sprintf("%s", $teacher[‘name’], $teacher[‘name’]);
}
$class_options = ‘’;
$classes = mysql_query(‘SELECT * FROM class’);
while($class = mysql_fetch_array($classes)) {
$class_options .= sprintf("%s", $class[‘name’], $class[‘name’]);
}
$room_options = ‘’;
$rooms = mysql_query(‘SELECT * FROM room’);
while($room = mysql_fetch_array($rooms)) {
$room_options .= sprintf("%s", $room[‘number’], $room[‘number’]);
}
$subject_options = ‘’;
$subjects = mysql_query(‘SELECT * FROM subject’);
while($subject = mysql_fetch_array($subjects)) {
$subject_options .= sprintf("%s", $subject[‘name’], $subject[‘name’]);
}
?>
[/php]

once the user selects the teacher name for deleting the HTML FORM then uses test2.php script to carry out the deleting of that teachers name…

PROBLEM SECTION*

BUT this is where the issue happens im not sure if test2.php is getting the name form the form correctly as if i just make a text box on the HTML FORM page and manually type in a teacher name well then it deletes the name from the database.

but if i use the drop down menu it like test2.php cant see or read the name to be deleted…
i hope i am making sense with all this

use the name to

*****Script called test2.php *********
[php]<?php

// Read name from form using $_POST (safest)

$id=$_POST[“name”];

// Connect to server
// Replace username and password by your details

$db = @mysql_connect(“localhost”,“root”,“iqonr301”);
if (!$db)
{
do_error(“Could not connect to the server”);
}

// Connect to the database
// Note that your database will be called username

@mysql_select_db(“test”,$db)or do_error(“Could not connect to the database”);

$qry = “DELETE FROM teacher WHERE name=’$id’;”;
$result = mysql_query($qry);

echo mysql_error();

if (!$result) {echo “query failed
”;
}
else {echo “query worked
”;

print_r($id);
// $affected is zero so record does not exist

do_error(“No such record”);

}

function do_error($error)
{
echo $error;
die;
}

?>[/
[/php]

and this is the following error i get from this script
Notice: Array to string conversion in C:\xampp\htdocs\test2.php on line 23
query worked
Array ( [
Notice: Undefined variable: i in C:\xampp\htdocs\test2.1.php on line 11
] => ******** ) No such record

Because you are now posting an array instead of a string. Hence the “array to string conversion” error.

[php][/php]

This is where you create $_POST[‘name’] = array(); Since $i is undefined I’m assuming you do not want to actually post an array here?

[php][/php]

To be honest I am not sure what I need to do any more I just want my html from to look at a database and have a drop down from of the names from this DB when I click on delete I just want the delete php to get rid of this user name

Like I said just remove the array from your select.

[php][/php]

will just give me a text box to put text into

this change fixed my issue [php]<?php echo $options ?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service