I am trying to edit a single record. What I want to do is to pull the current record (same one every time, ID 1) edit it, and resubmit it to the sql server. This is for a score keeper that his changing rapidly with an autorefresh website.
The website is http://www.hearsports.com
Note the code below:
ScoreUpdate.php
<html>
<!-- Created with the CoffeeCup HTML Editor -->
<!-- http://www.coffeecup.com/ -->
<!-- Brewed on 1/21/2003 6:55:33 AM -->
<head>
<title></title>
</head>
<body>
<html>
<head><title>Score Update</title></head>
<body>
<CENTER><H1>Score Update</H1></CENTER>
<CENTER>
<form method="POST" action="ScoreInsert.php">
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td width="50%">
Visitor Team
</td>
<td width="50%">
<input type="text" name="Vteam" size="20">
</td>
<td width="50%">
Score
</td>
<td width="50%">
<input type="text" name="Vscore" size="2">
</td>
</tr>
<td width="50%">
Visitor Team
</td>
<td width="50%">
<input type="text" name="Hteam" size="20">
</td>
<td width="50%">
Score
</td>
<td width="50%">
<input type="text" name="Hscore" size="2">
</td>
</tr>
<td width="50%">
Period
</td>
<td width="50%">
<input type="text" name="Period" size="20">
</td>
<td width="50%">
ID
</td>
<td width="50%">
<input type="text" name="id" size="1">
</td>
</tr>
<tr>
<td width="50%">
</td>
<td width="50%">
<input type="submit" value="Update Score" name="btnSubmit">
</td>
</tr>
</table>
</form>
</body>
</html>
</body>
</html>
ScoreInsert.php
<?php
// check to see if firstname is passed as part of the query string. If it doesn't exist, redirect to an error page and exit immediately
This could happen if some hacker or a user bookmarked this page and came into it by accident. You want to check to see if the variables exist
if (!array_key_exists("Vteam", $_POST)) {
$loc = "Error.php?e=1";
header("Location: " . $loc);
exit(1);
}
// check to see if firstname is passed as part of the query string. If it doesn't exist, redirect to an error page and exit immediately
if (!array_key_exists("Vscore", $_POST)) {
$loc = "Error.php?e=2";
header("Location: " . $loc);
exit(1);
}
if (!array_key_exists("Hteam", $_POST)) {
$loc = "Error.php?e=1";
header("Location: " . $loc);
exit(1);
}
// check to see if firstname is passed as part of the query string. If it doesn't exist, redirect to an error page and exit immediately
if (!array_key_exists("Hscore", $POST)) {
$loc = "Error.php?e=2";
header("Location: " . $loc);
exit(1);
}
if (!array_key_exists("Period", $POST)) {
$loc = "Error.php?e=1";
header("Location: " . $loc);
exit(1);
}
// At this point we know firstname and lastname exist so store them in variables
$id = $POST['ID'];
$Vteam = $POST['Vteam'];
$Vscore = $POST['Vscore'];
$Hteam = $POST['Hteam'];
$Hscore = $POST['Hscore'];
$Period = $POST['Period'];
// Here you would do some validation and checking (like bad names, too long of a name, duplicate names, etc.). Assume DoValidation() accomplishes this and returns true if data is ok, false if it is bad. It is up to you to write this function.
if (DoValidation($Vteam, $Vscore, $Hteam, $Hscore, $Period ) == false) {
$loc = "yError.php"?e=3;
header("Location: " . $loc);
exit(1);
}
// ok now you have the variables stored and its time to persist the data in your mySQL database.
// First lets connect to mySQL. Here you will put in the host name of the server/IP address to the database, the administrator username and password
$dbLink = mysql_connect("localhost", "xxxx", "xxxx");
if ($dbLink == false) {
$loc = "myError.php?e=4";
header("Location: " . $loc);
exit(1);
}
// Second, you must select a database you want to work with. This is "myUser" database as we setup above in mySchema.sql
$result = mysql_select_db("LiveScore");
if ($result == false) {
$loc = "Error.php?e=5";
header("Location: " . $loc);
exit(1);
}
// Third, we prepare the SQL statement to insert into the database. Notice we do not specify the userId column as this is automatically generated by mySQL
$sql = "insert into score (VistorTeam, VisitorScore, HomeTeam, HomeScore, Period) values ('$Vteam', 'Vscore', '$Hteam', 'Hscore', '$Period')";
// Fourth, we execute the query
$result = mysql_query($sql, $dbLink);
if ($result == false) {
$loc = "Error.php?e=6";
header("Location: " . $loc);
exit(1);
}
// Fifth, close the database connection
$result = mysql_close($dbLink);
if ($dbLink == false) {
$loc = "Error.php?e=7";
header("Location: " . $loc);
exit(1);
}
// Finally, redirect to a success page
$loc = "http://sec.lavaa.net/Livescore/ScoreUpdate.php";
header("Location: " . $loc);
exit(0);
?>
I think that I tried to post this message once, but it appears to have gotten lost! Thanks in advnance for any assistance with this problem.