-1

been trying for few hours but i still cant find the mistake i made. I've gotten insert and display but not update. If someone can figure this out.. it would be a big help. This is my code:

updatetest.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update</title>

</head>

<body>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
      if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue)
  ;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}};

if(isset($_POST['update'])) { 
$UpdateQuery = "UPDATE maklumat SET iC='$_POST[iC]', Name='$_POST[name]', IP='$_POST[ip]'  WHERE iC= '$_POST[hidden]'";
mysql_query($UpdateQuery, $in2);    

};

mysql_select_db($database_in2, $in2);
$query_in2 = "SELECT * FROM maklumat";
$Record = mysql_query($query_in2, $in2) or die(mysql_error());
$row_Record= mysql_fetch_assoc($Record);
$totalRows_Record= mysql_num_rows($Record);

?>
<form id="form1" name="form1" method="post" action="updatetest.php">



  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <center>
    <table width="900" border="2">
    <tr>
      <th width="120"><div align="center">Identified Card</div></th>
      <th width="191"><div align="center">Name</div></th>
      <th width="12"><div align="center">IP Address</div></th>
      <th width="121"><div align="center"> Action </div></th>
    </tr>
    <?php

     do { ?>
      <tr>
        <td><div align="center"><?php echo "<input type=text name=iC value=" .  $row_Record['iC']; ?> </div></td>
        <td><div align="center"><?php echo "<input type=text name=name value=" .$row_Record['Name']; ?> </div></td>
        <td><div align="center"><?php echo "<input type=text name=ip value=" .$row_Record['IP']; ?> </div></td>
        <td><div align="center"><?php echo "<input type=hidden name=hidden value=" .  $row_Record['iC']; ?> </div></td>
        <td><div align="center"><?php echo "<input type=submit name=update value=update" ?> </div></td>


      </tr>
      <?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
  </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
</center>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($Record);
?>
jophab
  • 5,356
  • 14
  • 41
  • 60

1 Answers1

1

Try below:

<?php
$_POST = array("iC"=>"a", "name"=>"Does",'ip'=>'1.1.1.1', 'hidden'=>true);
$updateQuery = "UPDATE maklumat SET iC1='{$_POST['iC']}', Name='{$_POST['name']}', IP='{$_POST['ip']}'  WHERE iC= '{$_POST['hidden']}'";
var_dump($updateQuery);

What you need is a pair of braces parentheses : {$array['key']}, when you want to access the value from an array in string.

Check it out:Interpolation (double quoted string) of Associative Arrays in PHP

I think you should debug you PHP file with xdebug tool, or print your SQL statement. It will helpful for you to analyze the issue.

Community
  • 1
  • 1
Does
  • 569
  • 6
  • 24