Hello there,
I am working on an update script that can be broken down into 3 parts.
1. The form (uses id to populate fields)
2. The UPDATE
3. The confirmation.
Form:
<?php require_once("includes/connection.php");
$pid = $_POST['pid'];
$delete = $_POST['Delete'];
$update = $_POST['Update'];
if(isset($update))
{
$sql = "SELECT * FROM player WHERE id = {$pid}";
$result = mysql_query($sql, $connection);
$row = mysql_fetch_array($result)
or die("Database query failed: " . mysql_error());
setcookie(pid, $pid, 3600);
?>
<html>
<h3>Update Player</h3>
<br>
<body>
<form action="update_player.php" method="post">
<table cellspacing="0" cellpadding="0" width="100%">
...
</form>
</body>
</html>
<?php
}
else
if(isset($delete))
{
$sql = "DELETE FROM player WHERE id = {$pid}";
$result = mysql_query($sql, $connection)
or die("Database query failed: " . mysql_error());
The UPDATE:
<?php
$pid = $_COOKIE['pid'];
$ln = $_POST['ln'];
$fn = $_POST['fn'];
$mi = $_POST['mi'];
$ad = $_POST['ad'];
...
$DoBYYYY = $_POST['DoBYYYY'];
$team = $_POST['team'];
$output_form = false;
if (empty($ln) || empty($fn) || empty($pcell)){
echo 'You forgot either the last name, first name, or player\'s cell. <br \>';
$output_form = true;
}
else{
$query = "UPDATE player SET last_name = '$ln', first_name = '$fn', middle_initial = '$mi', home_address = '$ad', city = '$ci', state = '$st', zip = '$zi', mother = '$mn', father = '$dn',".
"player_cell = '$pcell', mom_cell = '$mcell', dad_cell = '$dcell', home_number = '$hnumber', mom_work_number = '$mwork', dad_work_number = '$dwork', mom_email = '$memail', dad_email = '$demail', personal_email = '$pemail',".
"preferred_email = '$prefemail', years_played = '$yrsp', medical_conditions = '$medc', emergency_contact_name = '$emerc', emergency_contact_phone = '$emercnumber', texting = '$text', as_of_date = '$AoD',".
"position_played = '$position', preferences = '$prefs', school = '$school', DoBMM = '$DoBMM', DoBDD = = '$DoBDD', DoBYYYY = '$DoBYYYY', feet = '$feet', inches = '$inches', lbs = '$lbs', oz = '$oz', team = '$team')".
"WHERE id = '$pid'";
if
$result = mysql_query($query, $connection)
or die("Database query failed: " . mysql_error());
header('Refresh: 1;url=add_thankyou.php');
I'm not getting any MySQL errors and the data is not being updated which suggests to me that i'm using the cookie inappropriately.
Here is the error:
Notice: Use of undefined constant pid - assumed 'pid' in C:\wamp\www\base_ball\update_delete.php on line 13
Any thoughts?