dapcigar Posted May 21, 2014 Share Posted May 21, 2014 Am trying to update a table called "budget_request" and also inserting the data of that table into another table called "Budget". The Update works but it is not inserting into the other table. please help me out.. check my code below <?php$id = $_GET['id'];?><?phpinclude('mysql_connect.php');$q = mysql_query("UPDATE budget_request SET status = 'Approved' WHERE id = '$id'") or die(mysql_error());// send the details to the budget database$query = mysql_query("SELECT * FROM budget_request WHERE id = '$id' ") or die (mysql_error()); $dat = mysql_fetch_array($query); $department = $dat['department']; $amount = $dat['amount']; // Add the data to the Budget DB $que = (" INSERT INTO budget (id, department, amount, actual) VALUES ( ' ','$department', '$amount', '$amount')" ) or die(mysql_error()); header("Location: add_budget.php");?> Quote Link to comment https://forums.phpfreaks.com/topic/288645-not-saving-to-table/ Share on other sites More sharing options...
Solution IanA Posted May 21, 2014 Solution Share Posted May 21, 2014 In your budget table, is ID a primary key? Following your previous two queries, you are missing mysql_query from your INSERT query. I would recommend moving your code over to updated extensions such as PDO or mysqli as the method you're using is depricated and does not protect against SQL injections. Quote Link to comment https://forums.phpfreaks.com/topic/288645-not-saving-to-table/#findComment-1480263 Share on other sites More sharing options...
dapcigar Posted May 21, 2014 Author Share Posted May 21, 2014 Yeah, it worked.. thanks.. Ama ctually a newbie.. Will go over some tutorials on PDO.. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/288645-not-saving-to-table/#findComment-1480266 Share on other sites More sharing options...
IanA Posted May 21, 2014 Share Posted May 21, 2014 No problem, glad your issue is resolved. Please mark it as answered. Quote Link to comment https://forums.phpfreaks.com/topic/288645-not-saving-to-table/#findComment-1480267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.