Jump to content

Not saving to table


dapcigar

Recommended Posts

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'];
?>
<?php



include('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");

?>

Link to comment
https://forums.phpfreaks.com/topic/288645-not-saving-to-table/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/288645-not-saving-to-table/#findComment-1480263
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.