Frage

<?php

    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name="hsp_property"; // Database name 
    $tbl_name="project_directory"; // Table name 

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    //Get values from form
    $id = $_POST['id'];
    $hospital = $_POST['hospital'];
    $project = $_POST['project'];
    $state = $_POST['state'];
    $status = $_POST['status'];
    $da_status = $_POST['da_status'];
    $pm = $_POST['pm'];
    $budgett = $_POST['budgett'];
    $budgetat = $_POST['budgetat'];
    $pdapproval = $_POST['pdapproval'];
    $pdcs = $_POST['pdcs'];
    $pdcd = $_POST['pdcd'];
    $pdcf = $_POST['pdcf'];
    $pnm = $_POST['pnm'];
    $prm = $_POST['prm'];
    $comments = $_POST['comments'];

    // update data in mysql database 
    $sql="UPDATE $tbl_name SET Hospital='$hospital', Project='$project', State='$state',Project_Status='$status',DA_Status='$da_status',Project_Manager='$pm',Budget_Total='$budgett',Budget_Approved='$budgetat',Project_Approval_Dates='$pdapproval',Project_Contstruction_Dates='$pdcs',Project_Contract_Dates='$pdcd',Project_Current_Dates='$pdcf',Program_Next_Milestone='$pnm',Program_Milestone='$prm',Comments='$comments' WHERE id='$id'";
    $result=mysql_query($sql);

// if successfully updated. 
    if ($result) {
        header ('Location: ../project_directory.php');
    }
    else {
        echo 'Error';
    }

?>

The above is some code to update a MySQL db, i'm running WAMP to test the website before I'll upload.

I've been using the phpeasysteps tutorial as php and mysql is new to me. It's been working all ok until now.

Would love to know what i'm doing wrong, the PhpEasySteps tutorial might be a tad old as i've had to update a few elements of the initial code to get it to work..

War es hilfreich?

Lösung

Replace echo 'Error'; with echo mysql_error(); to see why you didn't get a result and then slap yourself for misspelling a column name or something most likely easily overlooked. If you still can't figure it out, post the error. And if you go that far, post the result of SHOW CREATE TABLE project_directory

Andere Tipps

You need to add $link_identifier to your mysql_select_db database selection,

Syntax: bool mysql_select_db ( string $database_name [, resource $link_identifier = NULL ] )

 $link = mysql_connect("$host", "$username", "$password")or die("cannot connect");
 mysql_select_db("$db_name", $link)or die("cannot select DB");

You can use mysql_error(); function to find the mysql related errors.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top