Jump to content

Not saving to table


dapcigar
Go to solution Solved by IanA,

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.