Jump to content

Recommended Posts

Hello All,

I have a script that displays and allows users to edit records in a mysql database. It displays the information correctly, but when I try to edit the information through forms I have created,  it gives me the "successful" message, but makes no changes to the database. I have printed out the sql, which looks like this...

UPDATE division_1 SET Team='Dundee', Played='2', Won='3', Lost='4', Drawn='3', [For]='12', Against='5', Points='12' WHERE ID=2

and heres what the sql in the code looks like...

UPDATE division_1 SET Team='".$Team."', Played='$Played', Won='$Won', Lost='$Lost', Drawn='$Drawn', [For]='$For', Against='$Against', Points='$Points' WHERE ID=".$id;


theres probably blinding errors - I'm fairly new to this.

Heres my code that inserts it into the database (sorry its a mess) -

[CODE]
<?php
$host = "localhost";
$user = "root";
$passw="password";
$db = "millhill";
$connection = @mysql_connect($host, $user) or die (mysql_error());
mysql_select_db($db, $connection) or die (mysql_error());

$id = $_GET['id'];
$Team = $_POST['Team'];
$Played = $_POST['Played'];
$Won = $_POST['Won'];
$Lost = $_POST['Lost'];
$Drawn = $_POST['Drawn'];
$For = $_POST['For'];
$Against = $_POST['Against'];
$Points = $_POST['Points'];
$submit = $_POST['submit'];

if ($id) {
  if ($submit) {
    $sql = "UPDATE division_1 SET Team='".$Team."', Played='$Played', Won='$Won', Lost='$Lost', Drawn='$Drawn', [For]='$For', Against='$Against', Points='$Points' WHERE ID=".$id;
echo $sql;
    $result = mysql_query($sql);
echo $result;
    echo "Thank you! Information updated.\n";

  } else {

    // query the DB
    $sql = "SELECT * FROM division_1 WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);

    ?>

    <form method="post" action="<?php echo $PHP_SELF?>">
    <input type=hidden name="id" value="<?php echo $myrow["ID"] ?>">
    Team:<input type="Text" name="Team" value="<?php echo $myrow["Team"] ?>"><br>
    Played<input type="Text" name="Played" value="<?php echo $myrow["Played"] ?>"><br>
    Lost<input type="Text" name="Lost" value="<?php echo $myrow["Lost"] ?>"><br>
Won:<input type="Text" name="Won" value="<?php echo $myrow["Won"] ?>"><br>
    Drawn:<input type="Text" name="Drawn" value="<?php echo $myrow["Drawn"] ?>"><br>
For:<input type="Text" name="For" value="<?php echo $myrow["For"] ?>"><br>
Against:<input type="Text" name="Against" value="<?php echo $myrow["Against"] ?>"><br>
Points:<input type="Text" name="Points" value="<?php echo $myrow["Points"] ?>"><br>
    <input type="Submit" name="submit" value="Enter information">
    </form>

<?php
}
} else {

  // display list of employees
  $result = mysql_query("SELECT * FROM division_1",$connection );
  while ($myrow = mysql_fetch_array($result)) {
    printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["ID"], $myrow["Team"], $myrow["Played"]);

  }
}
[/CODE]


any ideas what I'm doing wrong?

Cheers

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.