PHP Error please help me

problem about Edit page code in AppServ

I think I write wrong in black frame.

echo"
<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
  <div class=\"form-group\">
   <label for=\"productname\">Productname:</label>
   <input name=\"Productname\" typr=\"productname\" class=\"form-control\"value='$productname'>
  </div>
  <div class=\"form-group\">
   <label for=\"price\">Price:</label>
   <input name=\"Price\" type=\"text\" class=\"form-control\"value='$price'>
  <div>
   <div class=\"form-group\">
   <label for=\"balance\">Balance:</label>
   <input name=\"Balance\" type=\"text\" class=\"form-control\"value='$balance'>
  <div>
  <input name='id' type='hidden'  value='$id'>
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";
 ?>
</div>    
</body>
</html>

It would be easier if you posted the code rather than a screen shot. I can copy code into my text editor to try and find the fault but not a screen shot.

in your original post I notice you were using mysql, but you should be using mysqli or PDO (My Recommendation) for mysql is obsolete. As for what posted that’s basically an HTML form written using PHP. I find it easier to using ’ instead of " that way I won’t have to use \ .
Example:

echo '<input name="id" type="hidden" value="' . $id . '">';

HTH John

I do not understand how to solve it.

You had a spelling mistake typr instead of type. What does this give you and what error do you get?

echo"
<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
  <div class=\"form-group\">
   <label for=\"productname\">Productname:</label>
   <input name=\"Productname\" type=\"productname\" class=\"form-control\" value=\"$productname\">
  </div>
  <div class=\"form-group\">
   <label for=\"price\">Price:</label>
   <input name=\"Price\" type=\"text\" class=\"form-control\" value=\"$price\">
  <div>
   <div class=\"form-group\">
   <label for=\"balance\">Balance:</label>
   <input name=\"Balance\" type=\"text\" class=\"form-control\" value=\"$balance\">
  <div>
  <input name=\"id\" type=\"hidden\" value=\"$id\">
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";
<!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>Untitled Document</title>
 <link rel="stylesheet" href="css/bootstrap.min.css">
  <script src="js/jquery.min.js"></script>
  <script src="js/bootstrap.min.js"></script>
</head>

<body>
<?php
include('config.php');

$sql="SELECT *  FROM  `homework3` ORDER BY  `homework3`.`id` DESC ";

$sql_result = mysql_query($sql, $connection) or die("");

echo"

<div class='container'>

 <table class='table'>
  <thead>
   <tr>
    <th>id</th>
	<th>Productname</th>
	<th>Price</th>
	<th>Balance</th>
	<th>Edit</th>
   </tr>
  </thead>
  
  <tbody>";
  
while ($row = mysql_fetch_array($sql_result)){
$id = $row["id"];
$productname = $row["Productname"];
$price = $row["Price"];
$balance = $row["Balance"];
echo"
      <tr>
	    <td>$id</td>
		<td>$productname</td>
		<td>$price</td>
		<td>$balance</td>
		<td><a href='fedit.php?id=$id'>แก้ไข </a><td>
	  </tr> ";
}
echo"

         </tbody>
  </table";
  ?>
</div>


</body>
</html>
<?
$hostname = "localhost";
$username="root";
$password="root";
$dbname = "homework3"; 
$dblogin = "homework3"; 
$connection=mysql_connect($hostname,$username,$password) or die("ติดต่อฐานข้อมูลไม่ได้");
$db=mysql_select_db($dblogin,$connection) or die("ไม่สามารถเลือกฐานข้อมูลได้");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET collation_connection = ’utf8_thai_ci’ ");
?>
<!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>Untitled Document</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
 <script src="js/jquery.min.js"></script>
 <script src="js/bootstrap.min.js"></script>
</head>


<body>
<?php
include('config.php');
$sql="SELECT *  FROM  `homework3` WHERE id ='$id'";
$sql_result = mysql_query($sql, $connection) or die("");
while ($row = mysql_fetch_array($sql_result)){
$id = $row["id"];
$productname = $row["Productname"];
$price = $row["Price"];
$balance = $row["Balance"];
}
echo"
<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
  <div class=\"form-group\">
   <label for=\"productname\">Productname:</label>
   <input name=\"Productname\" typr=\"productname\" class=\"form-control\"value='$productname'>
  </div>
  <div class=\"form-group\">
   <label for=\"price\">Price:</label>
   <input name=\"Price\" typr=\"text\" class=\"form-control\"value='$price'>
  <div>
   <div class=\"form-group\">
   <label for=\"balance\">Balance:</label>
   <input name=\"Balance\" typr=\"text\" class=\"form-control\"value='$balance'>
  <div>
  <input name='id' type='hidden'  value='$id'>
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";
 ?>
</div>    
</body>
</html>
<?php
$id=$_POST[id];
$productname=$_POST[Productname];
$price=$_POST[Price];
$balance=$_POST[Balance];

include('config.php');

$sql="UPDATE  `homework3`.`homework3` SET  `Productname` =  'คอมพิวเตอร์',`Price` =  '25000',
`Balance` =  '2500' WHERE  `homework3`.`id` ='$id'";
$result=mysql_db_query($dbname,$sql);

if ($result) {
	echo "<H3>Ok Done!</H3>";
	echo "[ <A HREF=index.php>Click here to go back.</A> ] ";
} else {
	echo "<H3>ERROR : ไม่สามารถแก้ไขได้</H3>";
}
mysql_close();
?>

Off Topic

@the_virus: when you post code on the forums, you need to format it so it will display correctly.

You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.

I can not edit my code. I think I write wrong in black frame.

This code

<button type\"submit\" class=\"btn btn-default\">Submit</button> 

is missing an = sign after the word type.

If that doesn’t solve it, what error are you getting?

I noticed that, you’re then sticking the value of $id straight into the query, that leaves you wide open to SQL injection attacks. Never trust user submitted data no matter how well you trust the users. All user submitted data should be validated

What should I use between typr or type?

echo"
<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
  <div class=\"form-group\">
   <label for=\"productname\">Productname:</label>
   <input name=\"Productname\" typr=\"productname\" class=\"form-control\"value='$productname'>
  </div>
  <div class=\"form-group\">
   <label for=\"price\">Price:</label>
   <input name=\"Price\" typr=\"text\" class=\"form-control\"value='$price'>
  <div>
   <div class=\"form-group\">
   <label for=\"balance\">Balance:</label>
   <input name=\"Balance\" typr=\"text\" class=\"form-control\"value='$balance'>
  <div>
  <input name='id' type='hidden'  value='$id'>
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";
 ?>

This is the original.There are two data
But I took 3 new data .

<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
  <div class=\"form-group\">
   <label for=\"email\">Email:</label>
   <input name=\"Email\" typr=\"email\" class=\"form-control\"value='$email'>
  </div>
  <div class=\"form-group\">
   <label for=\"pwd\">Password:</label>
   <input name=\"Pass\" type=\"text\" class=\"form-control\"value='$pass'>
  <div>
  <input name='id' type='hidden'  value='$id'>
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";

I have never heard of a “typr” attribute for the input element.
Let me guess, that’s the one that isn’t working?
Can you see why it isn’t working?

And as @mittineague said, typr is just a typo, not a valid attribute name.

Now I can fix everyone’s thanks.

<div class=\"contaimer\">
 <h2>การแก้ไขข้อมูล</h2>
 <form method=\"post\" action=\"edit.php\">
 <div class=\"form-group\">
   <label for=\"nameproduct\">Nameproduct:</label>
   <input name=\"Nameproduct\" typr=\"nameproduct\" class=\"form-control\"value='$nameproduct'>
  <div>
  <div class=\"form-group\">
   <label for=\"price\">Price:</label>
   <input name=\"Price\" typr=\"price\" class=\"form-control\"value='$price'>
  </div>
  <div class=\"form-group\">
   <label for=\"balance\">Balance:</label>
   <input name=\"Balance\" type=\"text\" class=\"form-control\"value='$balance'>
  <div>
  <input name='id' type='hidden'  value='$id'>
  <button type\"submit\" class=\"btn btn-default\">Submit</button> 
 </form>";

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.