无法更新数据库PHP / mysql [noob] [关闭]

I'm just having a bit of trouble with updating a database via a php form process, I've tried various things thus far to get it working but to no avail, All the pages seem to be working except for the _process.php itself;

  <?php
    /*saves the form data to the database */

    //read data passed via form
    $cabinID = $_POST['txtcabinID'];
    $cabintype = $_POST['txtCabinType'];
    $cabindesc = $_POST['txtCabinDesc'];
    $pricepern= $_POST['txtppN'];   
    $priceperw = $_POST['txtppW'];
    $photo = $_POST['txtPhoto'];

    //connect to server and database 
    include 'sqldb_connect.inc.php';

    //set up query
             $query =  "update tblCabins set
            cabinType='$cabintype' 
            cabinDescription='$cabindesc', 
            pricePerNight='$pricepern', 
            pricePerWeek='$priceperw', 
            PHOTO='$photo', 
            where cabinID ='$cabinID'"; // important

    //execute query
    $result = mysql_query($query);

    if(!$result)
    {
        mysql_close();
        exit("Query failed");
    }

    mysql_close();
    exit ("Cabin updated successfully");    
  ?>

</body>
</html>

Can anyone see any problems within the page that stand out? Appreciate it :)

Comma is missing in the query:

 $query =  "update tblCabins set
            cabinType='$cabintype' 
                                  ^
            cabinDescription='$cabindesc', 
            pricePerNight='$pricepern', 
            pricePerWeek='$priceperw', 
            PHOTO='$photo', 
            where cabinID ='$cabinID'"; 

Try with,

 $query =  "update tblCabins set
            cabinType='$cabintype',
            cabinDescription='$cabindesc', 
            pricePerNight='$pricepern', 
            pricePerWeek='$priceperw', 
            PHOTO='$photo', 
            where cabinID ='$cabinID'"; 

You're missing one comma and one comma too many:

(Rewrite)

$query = "UPDATE tblCabins SET
    cabinType='$cabintype', 
    cabinDescription='$cabindesc', 
    pricePerNight='$pricepern', 
    pricePerWeek='$priceperw', 
    PHOTO='$photo' 
WHERE cabinID ='$cabinID'"; // important
  • One missing after cabinType='$cabintype' and one too many for PHOTO='$photo',

Error reporting:

Add error reporting to the top of your file(s) which will help during production testing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Footnotes:

Your present code is open to SQL injection. Use prepared statements, or PDO.

mysql_* functions deprecation notice:

http://www.php.net/manual/en/intro.mysql.php

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

cabinType='$cabintype' 
        cabinDescription='$cabindesc',

You're missing a comma. Should be

 cabinType='$cabintype',
        cabinDescription='$cabindesc',

Also, just a note, as soon as you start feeling comfortable with mysql_query, I'd recommend skipping STRAIGHT into PDO and using prepared statements. It makes your SQL easier to read, and a lot safer :)