Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <form action="tableData.php" method="post">
- Scheme Name: <input type="text" name="scheme"><br><br>
- No of Members: <input type="text" name="memberCount"><br><br>
- No. of Months: <input type="text" name="monthCount"><br><br>
- EMI Amount: <input type="text" name="amount"><br><br>
- Start Date:<input type="text" name="sDate"><br><br>
- <!--E-mail: <input type="text" name="email"><br>-->
- <input type="submit">
- </form>
- </body>
- </html>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "gold";
- $table = $_POST['scheme'];
- $member = $_POST['memberCount'];
- $month = $_POST['monthCount'];
- $amount = $_POST['amount'];
- $ldate= $_POST['sDate'];
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- // sql to create table
- $sql = "CREATE TABLE " .$table." (
- book_no VARCHAR(10) NOT NULL PRIMARY KEY,
- name VARCHAR(50) NOT NULL,
- contact_no VARCHAR(15) NOT NULL,
- amount DECIMAL(20,3),
- month VARCHAR(10) NOT NULL)";
- if (mysqli_query($conn, $sql)) {
- echo "Table created successfully";
- } else {
- echo "Error creating table: " . mysqli_error($conn);
- }
- $i = 1;
- while ($i <= $month)
- {
- $zdate = date('Y/m/d', strtotime( "+".$i." month", strtotime($ldate)))."<br>";
- $column = $zdate;
- echo $column."<br>";
- $sql="ALTER TABLE ".$table." ADD ".$column." VARCHAR(55)";
- $conn->query($sql);
- $i++;
- }
- if (mysqli_query($conn, $sql)) {
- echo "Table altered successfully";
- } else {
- echo "Error adding column: " . mysqli_error($conn);
- }
- mysqli_close($conn);
- ?>
- $column= str_replace("/", "_", $zdate);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement