Jump to content

warning when editing mysql using php


Nucleus

Recommended Posts

Hello,

 

I am using this form, to connect on MySQL database and edit the fields "FirstName", "LastName" and "PhoneNumber" in the "Employees" table.

 

<?
//connect to mysql
include 'connect.php';

//If cmd has not been initialized
if(!isset($cmd))
{
   //display all the fields
   $result = mysql_query("select * from Employees order by id");

   //run the while loop that grabs all the fields
   while($r=mysql_fetch_array($result))
   {
      //grab the title and the ID of the fields
      $ID=$r["ID"];
      $FirstName=$r["FirstName"];
      $LastName=$r["LastName"];
      $PhoneNumber=$r["PhoneNumber"];

 //make the title a link
      echo "<a href='edit.php?cmd=edit&id=$id'>$FirstName - Edit</a>";
      echo "<br>";
    }
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["ID"];
      $sql = "SELECT * FROM Employees WHERE id=$id";
      $result = mysql_query($sql);
      $myrow = mysql_fetch_array($result);
      ?>

      <form action="edit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

      First Name:<INPUT TYPE="TEXT" NAME="FirstName" VALUE="<?php echo $myrow["FirstName"] ?>" SIZE=30><br>
      Last Name:<INPUT TYPE="TEXT" NAME="LastName" VALUE="<?php echo $myrow["LastName"] ?>" SIZE=30><br>
      Phone Number:<INPUT TYPE="TEXT" NAME="PhoneNumber" VALUE="<?php echo $myrow["PhoneNumber"] ?>" SIZE=30><br>

      <input type="hidden" name="cmd" value="edit">

      <input type="submit" name="submit" value="submit">

      </form>

<? } ?>
<?
   if ($_POST["$submit"])
   {
      $FirstName = $_POST["FirstName"];
  $LastName = $_POST["LastName"];
  $PhoneNumber = $_POST["PhoneNumber"];

  $sql = "UPDATE Employees SET FirstName='$FirstName',LastName='$LastName',PhoneNumber='$PhoneNumber' WHERE id=$id";
      //replace the fields with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
}
}
?>

 

My problem is that I get this warning message:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home1/koutouro/public_html/ioannou/edit.php on line 34

 

As a result I cannot update the database.

 

I started working with PHP and MySQL yesterday, so please be patient with me.

 

Thanks.

Link to comment
Share on other sites

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.