PHP Submit button doesn't have any effect.

Okay so I was making a code, the code is given below. Now whenever I click on the submit button, the page loads and nothing happens. The same form is displayed again and no results are displayed as per the code.

My code is:

What may be the issue here? I can't use POST as PHPStorm POST code doesn't work. Any help why the page loads but doesn't echo the result and remains same as it is?

<html>
<head><title>
    Creating a Table!
</title>

<style>
.h1 {text-align: center}
</style>


</head>


<body>

<?php

if(isset($_GET['button_create'])) {

$conn = mysqli_connect("localhost","root","");

if(!conn) {
    die("Connection failed!");
}

mysqli_select_db($conn,"test");

$tablename = $_POST['table_name'];

$row1name = $_POST['row1_name'];
$row1input = $_POST['row1_input'];
$row1length = $_POST['row1_length'];

$row2name = $_POST['row2_name'];
$row2input = $_POST['row2_input'];
$row2length = $_POST['row2_length'];

$row3name = $_POST['row3_name'];
$row3input = $_POST['row3_input'];
$row3length = $_POST['row3_length'];

$sql = "CREATE TABLE $tablename (".
    "$row1name $row1input($row1length),".
    "$row2name $row2input($row2length),".
    "$row3name $row3input($row3length) )";

$retval = mysqli_query($conn,$sql);

if(!$retval) {
    echo("Error. Queries couldn't be done <br />").mysqli_error();
}

echo("Table created successfully! <br />");
echo("Follow the navigation window below now! <br />");

mysqli_close($conn);

}

else {

?>


<h1>

    Creating a Table!

</h1>


<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
    <table>
        <tr>
            <td>Enter your Table Name:</td>
            <td><input type="text" name="Table name" id="table_name"/></td>
        </tr>
        <br/>
        <tr>
            <td>Row 1 Name:</td>
            <td><input type="text" name="Row 1 name" id="row1_name"/></td>
            <td>Row 1 INPUT TYPE: <br/>
                <input type="text" name="Row 1 INPUT TYPE" id="row1_input"/></td>
            <td>Row 1 LENGTH: <br/>
                <input type="text" name="Row 1 INPUT LENGTH" id="row1_length"/></td>
        </tr>

        <br/>

        <tr>
            <td>Row 2 Name:</td>
            <td><input type="text" name="Row 2 name" id="row2_name"/></td>
            <td>Row 2 INPUT TYPE: <br/>
                <input type="text" name="Row 2 INPUT TYPE" id="row2_input"/></td>
            <td>Row 2 LENGTH: <br/>
                <input type="text" name="Row 2 INPUT LENGTH" id="row2_length"/></td>
        </tr>
        <br/>

        <tr>
            <td>Row 3 Name:</td>
            <td><input type="text" name="Row 3 name" id="row3_name"/></td>
            <td>Row 3 INPUT TYPE: <br/>
                <input type="text" name="Row 3 INPUT TYPE" id="row3_input"/></td>
            <td>Row 3 LENGTH: <br/>
                <input type="text" name="Row 3 INPUT LENGTH" id="row3_length"/></td>
        </tr>
        <br/>
        <tr>
            <td><input type="submit" name="Submit" id="button_create" value="Create Table!"></td>
        </tr>

    </table>
</form>

<form>
    <a href="landing_page.phtml"><input type="button" value="Go back to landing page!"/> </a>
    <a href="insert%20table.phtml"><input type="button" value="Insert values into table!"/></a>

</form>

<?php
}

?>
</body>
</html>
1 comment

Hi there,

The problem is in your code (form uses GET and not POST) and has nothing to do with PhpStorm -- you will get the same result in another IDE/editor.

Same on StackOverflow: https://stackoverflow.com/questions/50325888/php-submit-button-doesnt-have-any-effect-phpstorm

0

Please sign in to leave a comment.