html php 手机edit,html - Edit Records PHP Form - Stack Overflow

I currently have these PHP pages which lets me add a record to a database. (in this case its members) It works perfectly in the sense that I can ADD, DELETE and VIEW. But Im not sure how to get the edit(or UPDATE functionality working.

Here is my db connection Code:

// Server Info

$server = 'localhost';

$username = 'root';

$password = '';

$database = 'gamgam';

// Connect to database

$connection = new mysqli($server, $username, $password, $database);

?>

Here is my Add Code:

Insert Users

Insert User Confirmation

require_once('connection.php');

echo "Member ID:";

echo "";

echo "
";

echo "Username:";

echo "";

echo "
";

echo "Password:";

echo "";

echo "
";

echo "Firstname:";

echo "";

echo "
";

echo "Lastname:";

echo "";

echo "
";

echo "Address:";

echo "";

echo "
";

echo "Email:";

echo "";

echo "
";

echo "";

echo "";

echo "
";

?>

Login

if(!isset($_POST['submit'])) {

echo 'Please Register';

} else {

$memberID = $_POST['memberID'];

$username = $_POST['username'];

$password = $_POST['password'];

$fName = $_POST['fName'];

$lName = $_POST['lName'];

$address = $_POST['address'];

$email = $_POST['email'];

$query = "INSERT INTO `members`

(MemberID, Username, Password, FirstName, LastName,

StreetAddress, Email)

VALUES ('$memberID', '$username', '$password', '$fName',

'$lName', '$address', '$email')";

mysqli_query($connection, $query)

or die(mysqli_error($connection));

$rc = mysqli_affected_rows($connection);

if ($rc==1)

{

echo '

The database has been updated with the following details:
';

echo 'MemberID: '.$memberID.'
';

echo 'Username: '.$username.'
';

echo 'Password: '.$password.'
';

echo 'First Name: '.$fName.'
';

echo 'Last Name: '.$lName.'
';

echo 'Address: '.$address.'
';

echo 'Email: '.$email.'
';

} else {

echo '

The data was not entered into the database this time.

';

}

}

?>

Here is my View Code:

View Records

/*

VIEW.PHP

Displays all data from 'players' table

*/

// connect to the database

include('connection.php');

// get results from database

$result = mysqli_query($connection, "SELECT * FROM members")

or die(mysqli_error());

// loop through results of database query, displaying them in the table

while($row = mysqli_fetch_array( $result )) {

// echo out the contents of each row into a table

echo "

";

echo '

' . $row['MemberID'] . '';

echo '

' . $row['Username'] . '';

echo '

' . $row['Password'] . '';

echo '

' . $row['FirstName'] . '';

echo '

' . $row['StreetAddress'] . '';

echo '

' . $row['Email'] . '';

echo '

Edit';

echo '

Delete';

echo "

";

}

// close table>

echo "

";

?>

Add a new record

And here is the Delete Code:

// Connect to the database

include('connection.php');

// Confirm that the 'code' variable has been set

if (isset($_GET['MemberID']))

{

// Get the 'MemberID' variable from the URL

$MemberID = $_GET['MemberID'];

// Delete record from database

if ($stmt = $connection->prepare("DELETE FROM members WHERE MemberID = ? LIMIT 1")) {

$stmt->bind_param("i",$MemberID);

$stmt->execute();

$stmt->close();

} else {

echo "ERROR: could not prepare SQL statement.";

}

$connection->close();

// Redirect user after delete is successful

header("Location: view.php");

} else {

// If the 'code' variable isn't set, redirect the user

header("Location: view.php");

}

?>

I have gone through many basic php form templates online trying to incorporate what they have done to achieve results but have not had any success. What code needs to be written for my website to have the functionality to edit records already created in the database without going through phpmyadmin. Any help is apreciated.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值