Jump to content

PHP UPDATE/INSERT


monkeypaw201

Recommended Posts

i have the following code that spits a blank page at me.. any ideas?

 

<?php
if($_POST['select'] == 'Approved']{

if($_POST['old_status'] == 'Approved']
{

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}else{

$thours = $_POST['time_pilot_total']+$_POST['time'];
$mhours = $_POST['time_pilot_member']+$_POST['time'];
$pireps = $_POST['total_pireps']+1;
$vmoney = $_POST['current_money']+$_POST['route_money'];
}

}elseif($_POST['select'] == 'Filed']{

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}elseif($_POST['select'] == 'Denied']{

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}

$con = mysql_connect("localhost","user","pass");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
 mysql_select_db("database", $con);

mysql_query("UPDATE users SET total_hous = '$thours',member_hours = '$mhours',total_pireps = '$pireps',virtual_money = '$vmoney' WHERE pilot_id = '$_POST[pilot_id]'");
mysql_close($con);

$con = mysql_connect("localhost","user","pass");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
 mysql_select_db("database", $con);

mysql_query("UPDATE pireps SET status=%s, date_approved=%s, staff_comments=%s, approved_by=%s WHERE id=%s WHERE id = '$_POST[id]'");
mysql_close($con);
?>

 

I know i dont need to open the connection twice, but i like it that way, so dont comment on it unless it is the problem

Link to comment
https://forums.phpfreaks.com/topic/92761-php-updateinsert/
Share on other sites

Also, you probably have a typo here

 

total_hous

 

I would think that would be total_hours for your UPDATE query.

 

Turn on error reporting so you will get errors instead of blank pages.

 

nope, its a typo in the database, too much hassle to update all the pages..

 

You're ending all of your parenthetical statements with brackets, which isn't right.  Otherwise, what are you expecting to be output?  This page would output nothing if it all went as it should.

 

I fixed this, the new top portion:

 

if($_POST['select'] == 'Approved'){

if($_POST['old_status'] == 'Approved']
{

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}else{

$thours = $_POST['time_pilot_total']+$_POST['time'];
$mhours = $_POST['time_pilot_member']+$_POST['time'];
$pireps = $_POST['total_pireps']+1;
$vmoney = $_POST['current_money']+$_POST['route_money'];
}

}elseif($_POST['select'] == 'Filed'){

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}elseif($_POST['select'] == 'Denied'){

$thours = $_POST['time_pilot_total'];
$mhours = $_POST['time_pilot_member'];
$pireps = $_POST['total_pireps'];
$vmoney = $_POST['current_money'];

}

 

Not sure if it's the cause, but look at this line.

 

}elseif($_POST['select'] == 'Filed']{

 

You are ending your statement with a square bracket instead of rounded -should be

 

}elseif($_POST['select'] == 'Filed'){

 

If it's not that, let me know!

 

Its not that.. :D

 

i suggest adding or die(mysql_error()) after your mysql_query()s. don't know why you'd open the connection twice.

 

As i said, i have my stupid habits, and thats one of them..

Link to comment
https://forums.phpfreaks.com/topic/92761-php-updateinsert/#findComment-475328
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.