Log in

View Full Version : update info in a database



captainjustin
10-05-2009, 09:06 PM
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);



?>]

traq
10-06-2009, 12:52 AM
missing single quotes in the POST variables, for one.

$_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.

$name = $_POST['name'];
// etc.
I didn't check any further; try fixing those and see how it works. What error message are you getting?

forum_amnesiac
10-06-2009, 08:20 AM
Could you show some of your HTML, particularly that with the <form> tag.

If you are using
<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


<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