Results 1 to 3 of 3

Thread: update info in a database

  1. #1
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default update info in a database

    I'm trying to figure out what I'm doing wrong here. I'm trying to update the vessel info in a database. The vessel_id is passed thru the address bar. I listed the code below. Any help would be great! Thanks in advance.
    [<?



    include_once "../main.php";



    if(isset($submit) && $submit == 'Save changes')

    {

    $pday = date('d', mktime(0,0,0,0, date(d)));

    $pmonth = date('m', mktime(0,0,0, date(m), date(d)));

    $pyear = date('Y', mktime(0,0,0,date(m) ,date(d) , date(Y)));



    $q3 = "update vessel_info set

    name = '$_POST[name]',
    captain = '$_POST[captain]',
    mate = '$_POST[mate]',
    engineer = '$_POST[engineer]',
    deckhand = '$_POST[deckhand]',
    status = '$_POST[status]',
    charter_name = '$_POST[charter_name]',
    location = '$_POST[location]',
    crewchange = '$_POST[crewchange]',
    updated_by = '$_SESSION[cname]',
    pmonth = \"$pmonth\",
    pday = \"$pday\",
    pyear = \"$pyear\",
    where vessel_id = '$_GET[vessel_id]' ";

    (Above is where I'm getting the error)


    $r3 = mysql_query($q3) or die(mysql_error());





    echo "<br><br><center><span class=BlackText>The vessel $name was updated.</span></center>";

    include_once('../footer.php');

    exit;

    }



    $q1 = "select * from vessel_info where vessel_id = \"$_GET[vessel_id]\" ";

    $r1 = mysql_query($q1) or die(mysql_error());

    $a1 = mysql_fetch_array($r1);



    ?>]

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    missing single quotes in the POST variables, for one.
    PHP Code:
    $_POST['name']
    //not  $_POST[name] 
    if that doesn't work, try extracting each variable from the POST array before putting it into the SQL statement.
    PHP Code:
    $name $_POST['name'];
    // etc. 
    I didn't check any further; try fixing those and see how it works. What error message are you getting?

  3. #3
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Could you show some of your HTML, particularly that with the <form> tag.

    If you are using
    HTML Code:
    <form method="POST">
    then that is why you are not picking up the vessel name, "POST" does not add the variables to the address bar.

    If you want to use the "POST" method, and get the vessel name, then add a hidden field to your form, eg

    HTML Code:
    <input name="vessel" type="hidden" value="vessel name here">
    You can set the value of this hidden field in a number of ways, js, php.

    If you don't want to do this then use <form method="GET">, you will then need to change your PHP $_POST's to $_GET's.

    You also need to take note of traq's comments

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •