0

I face the problem::

To Insert data
to update data

When I go www.myweb.com/cpanel
user:xxxxx
Pass:xxxx
Go
Database
PhP MyAdmin
by this way I can update my database..

But when I connect by PHP... I failed...
Pls suggest some one.......pls !!1

1) test.php.. of a row

<a href="update.php?id=<? echo $rows['id']; ?>">Update</a> 

2) update.php

<?php
$host="localhost"; 
$username="xxxx"; 
$pass="xxxx"; 
$db="xxx"; 
$tbl="website";
// Connect to server and select database.
@mysql_connect("$host", "$username", "$pass")or die("cannot connect");
@mysql_select_db("$db")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl WHERE id='$id'";
$result=@mysql_query($sql);

$rows=mysql_fetch_array($result);
?>

<form action="update_ac.php?id=<? echo $rows['id']; ?>"  method="post" enctype="multipart/form-data" >
  <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td width="11%" align="center" bgcolor="#E6E6E6"><strong>S.L</strong></td>
      <td width="27%" align="center" bgcolor="#E6E6E6"><strong>Name</strong></td>
      <td width="20%" align="center" bgcolor="#E6E6E6"><strong>Description</strong></td>
      <td width="21%" align="center" bgcolor="#E6E6E6"><strong>Link  </strong></td>
      <td width="21%" align="center" bgcolor="#E6E6E6"><strong>Image</strong>  </td>
    </tr>


    <tr>

      <td bgcolor="#FFFFFF">
      <input type="text" name="id" value="<?php echo $rows["id"] ?>" />

      </td>
      <td bgcolor="#FFFFFF"><p align="center">
          <input name="nam" type="text" value="<? echo $rows['nam']; ?>" />
        </p>
          <p>&nbsp; </p></td>
      <td bgcolor="#FFFFFF"><p align="center">
        <input name="desc" type="text"  value="<? echo $rows['desc']; ?>" />
      </p></td>
      <td bgcolor="#FFFFFF"><div align="center">
        <input name="link" type="text" value="<? echo $rows['link']; ?>" />
      </div></td>
      <td bgcolor="#FFFFFF"><div align="center">
        <input name="pic" type="text"  value="<? echo $rows['pic']; ?>" />
      </div></td>

    </tr>

    <tr>
      <td colspan="5" align="right" bgcolor="#E6E6E6"><input type="submit" name="submit" value="Update" />      </td>
    </tr>
  </table>

</form>

<?php

mysql_close();
?>

3)update_ac.php

<?
$host="localhost"; 
$username="xxxx"; 
$pass="xxxx"; 
$db="xxx"; 
$tbl="website";

// Connect to server and select database.
@mysql_connect("$host", "$user", "$pass")or die("cannot connect");

@mysql_select_db("$db")or die("cannot select DB");


if ($_POST["submit"])
   {

   $id=$_POST['id'];
$nam = $_POST["nam"];
$desc = $_POST["desc"];
$link = $_POST["link"];
$pic = $_POST["pic"];

       $sql = " UPDATE  website  SET  id='$id',   nam='$nam',  desc='$desc',  link='$link',  pic='$pic'  WHERE    id='$id'  " ;

      $result = @mysql_query($sql);
      echo "1 Row Updated";
         }
else 
{
echo "ERROR";
}

if($result) 
   {
echo "1 Row Updated";
echo "</BR>";
  }
else 
  {
  echo "</BR >";
echo "ERROR Record Update.....";
echo "</BR >";
echo "</BR >";

}

?>

4) output

1 Row Updated
ERROR Record Update.....

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by hielo
0

Try using:

$result=mysql_query( $sql ) or die( mysql_error() );

Instead so you can determine what is causing the error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.