insert.php

<?php
$dbun = "$_POST[dbun]";
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="INSERT INTO $dbun (sn, date, particular, dr, cr)
VALUES
('$_POST[sn]','$_POST[date]','$_POST[ptr]','$_POST[dr]','$_POST[cr]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

DB name = my_db

user.php

<html>
<body>

<form action="db.php" method="post">
NEW DATA BASE USER: <input type="text" name="snn" />
<input type="submit" />
<br>
<form action="db.php" method="post">
DATA BASE USER NAME: <input type="text" name="dbun" />

<input type="submit" />
</form>

</body>
</html>

db.php

<?php
$snn = "$_POST[snn]";
		
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE $snn
(
Sn int,
Date int,
Particular varchar(15),
Dr int,
Cr int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

index.php

<form action="insert.php" method="post">
 
      DB User name: 
      <input type="text" name="dbun" />
      <br>
      Sn: 
      <input type="text" name="sn" />
      <br>
      Date: 
      <input type="text" name="date" />
      <br>
      Particurar: 
      <input type="text" name="ptr" />
      <br>
      Dr: 
      <input type="text" name="dr" />
      <br>
      Cr:</span>
      <input type="text" name="cr" />
       <br>
      <br>
      <input type="submit" />
      

</form>
<a href="user.php">USER</a></span>
<a href="output.php">OUT PUT</a>
</body>
</html>

My question is how to edit my sql data that already entered with html post plz help....

Dani AI

Generated

A clear, maintainable way to allow edits is to stop creating a new table per user and implement an “Edit” flow: list rows, link each row to an edit form that is prefilled from a SELECT, then submit that form to run an UPDATE for the row’s primary key. The current approach (dynamic table creation + raw POST values in SQL) is fragile and unsafe. created the table/insert UI but needs the edit UI + an UPDATE statement, not another INSERT.

Schema and security notes that address problems seen in the thread:

  • Use a proper primary key (INT AUTO_INCREMENT) instead of relying on ad-hoc Sn values.
  • Use appropriate types: DATE/DATETIME for dates and DECIMAL(10,2) for money amounts.
  • Avoid reserved names (rename Date to entry_date or always quote identifiers).
  • Never inject raw POST values into SQL. Switch from deprecated mysql_* to PDO or mysqli and use prepared statements. Validate or whitelist any user-supplied table name if dynamic tables are unavoidable.

Minimal example of an update handler (use as the POST target of the edit form):

<?php
$pdo = new PDO('mysql:host=localhost;dbname=my_db;charset=utf8mb4','root','',[
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

$table = $_POST['dbun'] ?? '';
if (!preg_match('/^[A-Za-z0-9_]+$/',$table)) exit('Invalid table');

$sql = "UPDATE `$table` SET `entry_date` = ?, `particular` = ?, `dr` = ?, `cr` = ? WHERE `sn` = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$_POST['date'], $_POST['ptr'], $_POST['dr'], $_POST['cr'], $_POST['sn']]);
echo 'Row updated';

Troubleshooting: enable exceptions/error reporting to see syntax errors (missing quotes/semicolons or malformed CREATE TABLE will cause failures). Fix the nested/duplicate <form> tags in the UI so each form submits the expected fields. As observed, PHP will fail silently if the SQL string is invalid — check the DB error output or PDO exception message to find the exact cause.

sorry db.php is this

<?php
$snn = "$_POST[snn]";
		
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("my_db", $con);
$sql = CREATE TABLE $snn
(
Sn int,
Date int,
Particular varchar(15),
Dr int,
Cr int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

sorry db.php is this

<?php
$snn = "$_POST[snn]";
		
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("my_db", $con);
$sql = CREATE TABLE $snn
(
Sn int,
Date int,
Particular varchar(15),
Dr int,
Cr int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

1st new data user to creat new table in index.php

and we have to enter data but how to edit that entered data

sorry db.php is here

<?php
$snn = "$_POST[snn]";
		
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("my_db", $con);
$sql = CREATE TABLE $snn
(
Sn int,
Date int,
Particular varchar(15),
Dr int,
Cr int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

sql please,,,
Because that php cannot use if sql nothing -_-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.