简体   繁体   中英

Embedded PHP printing like HTML?

I'm very much new to web programming, and all the other numerous errors in my spaghetti code aside, I keep having all this print out on my web page, and I'm not sure what's causing it:

For reference, I'm trying to create a web page that can append and delete rows from an SQL table. School project.

<fieldset>

<legend><h3> Edit Listings </h3> </legend>

<?php
if (isset($_POST['buttondelete']))
{
$key=$_POST['key'];
$query="DELETE FROM theatre WHERE key='$key'";
$result=$conn->query($query);
if(!$result) echo "DELETE failed: $query<br>";
}
if(isset($_POST['buttonadd']))
{
if(isset($_POST['key']) &&
    isset($_POST['name']) &&
    isset($_POST['genre']) &&
    isset($_POST['showtime']) &&
    isset($_POST['days'])) &&
    isset($_POST['cost'])
    {
        $key = $_POST['key'];
        $name = $_POST['name'];
        $genre = $_POST['genre'];
        $showtime = $_POST['showtime'];
        $days = $_POST['days'];
        $cost = $_POST['cost'];
        $query = $conn->prepare('INSERT INTO theatre (key, name, genre, 
        showtime, days, cost) VALUES (?,?,?,?,?,?)');
        $query->bind_param('ssssss', $key, $name, $genre, $showtime, $days, 
        $cost);
        $query->execute();
        if($query->affected_rows==0) echo 'Insert FAILED: $query<br>';

        }
}
?>




<form action='appendtheatre.html' method='post'>

<pre>

      Key: <input type='text' name='key'>
     Name: <input type='text' name='name'>
    Genre: <input type='text' name='category'>
 Showtime: <input type='text' name='showtime'>
     Days: <input type='text' name='days'>
     Cost: <input type='text' name='cost'>
     <br>
    <input type='submit' value='ADD RECORD' name='buttonadd'>
</pre>
</form>

</fieldset>

You need a webserver that is configured with PHP. Secondly, looking at your source it appears you named the file "appendtheatre.html" so unless you configured your webserver or PHP-FPM to route .html files to the PHP processor then it will not render them as PHP since it assumes it is plain HTML.

I would recommend renaming your file to a ".php" extension and trying again. If that does not work check Google for one of the many tutorials on how to setup PHP or just a LAMP server in general. I haven't looked at your code for accuracy, but it appears your problem is with your webserver config and likely has nothing todo with the PHP code.

Take it one step at time... first create a file called "test.php" for example with this code

<?php
phpinfo();

If it works and shows the PHP info page then PHP is configured properly. Then go ahead and add your code to it, and if it doesn't work start debugging by eliminating the code until you track down the culprit if you can't discern it from error messages and/or your IDE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM