Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:51:02+00:00 2026-05-29T09:51:02+00:00

I am trying to use a value that I receive from a MySQL query

  • 0

I am trying to use a value that I receive from a MySQL query and then do an insert but it’s not working. I’m getting an syntax error but the Insert Query is correct.

The select query returns an amount which I’m checking and then the program should do the insert query.

    <?php
require 'header.php';

$resID = mysql_real_escape_string($_POST['resID']);
$materialen_id = mysql_real_escape_string($_POST['materialen_id']);
$aantal = mysql_real_escape_string($_POST['aantal']);
$effectief_gebruikt = mysql_real_escape_string($_POST['effectief_gebruikt']);
$opmerking = mysql_real_escape_string($_POST['opmerking']);
//$datum_van = date('d-m-Y', $_POST['datum_van']);
//$datum_tot = date('d-m-Y', $_POST['datum_tot']);
$datum_van = $_POST['datum_van'];
$datum_tot = $_POST['datum_tot'];


$sql = "SELECT `aantal_beschikbaar` 
        FROM `materialen` 
        WHERE `id` = $materialen_id";
        
$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
    $tot = $row['aantal_beschikbaar'];
    echo 'totaal: ' . $tot;
}



$sql2 = "SELECT `aantal` FROM `materialen_per_reservatie`
        WHERE `materialen_id` = $materialen_id";  
$result2 = mysql_query($sql2) or die(mysql_error());

while ($row = mysql_fetch_array($result2))
{
    //$aant = $row['aantal'];
    //echo $aant
    echo $row['aantal'];
}

$besch = ($tot - $aant);
echo 'beschikbaar: ' . $besch;



/*$sql3 = "SELECT * FROM `materialen_per_reservatie`
        WHERE `reservaties_id` = $resID
        AND   `materialen_id` = $materialen_id";
$result3 = mysql_query($sql3) or die(mysql_error());*/

if($besch > $aantal){



        $string2 = "INSERT INTO `materialen_per_reservatie`(`reservaties_id`, `materialen_id`, `aantal`, `effectief_gebruikt`, `opmerking`, `datum_van`, `datum_tot`) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')";
        mysql_query($string2) or die(mysql_error());  

        
}      
  
require 'footer.php';
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:51:04+00:00Added an answer on May 29, 2026 at 9:51 am

    Provided that the error is on only the insert query…

    Your insert query is missing a needed space:

    INSERT INTO `materialen_per_reservatie` (`reservaties_id`, `materialen_id`, `aantal`, `effectief_gebruikt`, `opmerking`, `datum_van`, `datum_tot`) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')
    

    Add a space after materialen_per_reservatie. And I’m not sure you need all of the quotes.

    INSERT INTO materialen_per_reservatie (reservaties_id, materialen_id, aantal, effectief_gebruikt, opmerking, datum_van, datum_tot) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Linq2Sql to return all rows that contain values from
I' trying to use a Linq query to find and set the selected value
I'm getting a Can't use an undefined value as a HASH reference error trying
I'm trying to read a value from a file and use it in a
I am trying to use a prepared statement that deletes from two (temporary) tables:
Iam trying to use a UserControl named CheckBoxControl as value for the ExpandControlID/CollapseControlID attributes
I am trying to use the actual numerical value for the month on a
I'm trying to use the CSS word-wrap property with break-word value. I want to
I'm trying to use MultiDataTriggers to enabled/disable a button based on the value of
I can successfully receive values from my web service so in that repect the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.