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

  • Home
  • SEARCH
  • 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 8652181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:14:59+00:00 2026-06-12T14:14:59+00:00

I can’t get the syntax right for this. I’m trying to get the $nproj_hours

  • 0

I can’t get the syntax right for this. I’m trying to get the $nproj_hours value that is sumitted via a form to look-up the hours_id key value associated to it in the hours table, and put that numerical value in the summary table in a new row (I’ll be doing this for departments and projects as well, so if there’s a way to wrap them all up into one, I have a projects and departments table too).

Final Code:

if (isset($_POST['btnnew']))  

    {
    echo "<pre>Value of \$_POST:</br>";print_r($_POST);echo"</pre>";

        $nclarity_id    = $_POST['nclarity_id'];
        $nproj_hours    = $_POST['nproj_hours'];
        $ndept_name     = $_POST['ndept_name'];
        $proj_id        = $_POST['nclarity_id'];
        $hours_id       = $_POST['nproj_hours'];
        $dept_id        = $_POST['ndept_name'];

        $sql        = "INSERT INTO `summary` VALUES (null,'$proj_id','$hours_id','$dept_id',null)" 
                            or die ("couldn't update".mysql_error());
        $query = mysql_query($sql);

//echo "<pre>Value of \$sql:</br>";print_r($sql);echo"</pre>";
        if ($query)
{
echo "success!";
}
else
            {
        die('error inserting new record'.mysql_error());
    } // end of the nested if statement
}

?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
   <tr>
   <td align="center">&nbsp;</td>
   <td align="center"><strong>Clarity ID</strong></td>
   <td align="center"><strong>Hours</strong></td>
   <td align="center"><strong>Department</strong></td>
   </tr>
<form name="form1" method="post" action="stupid.php">
<tr>
<td>&nbsp;</td>
<select name="nclarity_id">

<?php
$sql = "SELECT proj_id, clarity_id FROM projects " . "ORDER by clarity_id";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['proj_id']."\">".$row['clarity_id']."</option>\n  ";
}
?>

</select>
<select name="nproj_hours">
<?php
$sql = "SELECT hours_id, proj_hours FROM hours";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['hours_id']."\">".$row['proj_hours']."</option>\n  ";
}
?>
</select>

<select name="ndept_name">

<?php
$sql = "SELECT dept_id, dept_name FROM departments";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['dept_id']."\">".$row['dept_name']."</option>\n  ";
}
?>
</select>
   <input type="submit" name="btnnew" value="Enter New Record">
</tr>
</table>

<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="500" border="1" cellspacing="0" cellpadding="3">
</tr>


<?php
while($rows=mysql_fetch_array($res))
{

?>

<?php
}

?>

</table>
</td>
</tr>
</table>


<?php
mysql_close();
?>
  • 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-06-12T14:15:00+00:00Added an answer on June 12, 2026 at 2:15 pm

    You have to change your query – specifically remove the keyword VALUES and add the column names. Refer the spec for the exact syntax and details. I have just put in colname1, colname2, colname3, colname4 – you need to replace that with the actual column names from your summary table

    INSERT INTO summary (colname1, colname2, colname3, colname4) 
       SELECT NULL, NULL, proj_hours, NULL
       FROM hours 
       WHERE proj_id ='$nproj_hours
    

    As per usual, the disclaimer to avoid using such queries due to possibility of SQL Injection is applicable. Please google sql injection / prepared statements / parameterized queries etc if you are not aware of the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can anyone explain to me why this program: for(float i = -1; i <
Can you please clarify me, what's the best practice for this example: Activity1 does
Can this be done in Javascript? I am converting a java wiki page to
Can I run this in a Windows command prompt like I can run it

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.