Hi I’m running XAMPP with the following
• Server: 127.0.0.1 via TCP/IP
• Software: MySQL
• Software version: 5.5.27 - MySQL Community Server (GPL)
• Protocol version: 10
• User: admin@localhost
• Server charset: UTF-8 Unicode (utf8)
• Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
• Database client version: libmysql - mysqlnd 5.0.10 - 20111026 - $Id: b0b3b15c693b7f6aeb3aa66b646fee339f175e39 $
• PHP extension: mysql
The html form take the users text input and activates the php script but it seems I have gone wrong some ware and I need help. The SQL database is called (test) table is called (teacher) rows in table are
Id and name.
THE HTML CODE
[code]
Delete Student FormDelete a Teacher Record
Enter the Name of the Teacher to be deleted:
Name:
[/code]The PHP CODE
[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”,“username”,“password”);
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”);
// Run query
$sql=“DELETE FROM teacher WHERE name=$id”;
$result=mysql_query($sql,$db);
// Check that query resulted in a deleted record
$affected=mysql_affected_rows();
if ($affected)
{
// $affected is non-zero
echo "Record: $id has been deleted.";
}
else
{
// $affected is zero so record does not exist
do_error("No such record");
}
function do_error($error)
{
echo $error;
die;
}
?> [/php]
Thank you for any help give.