hi m making a program n i want that when i want to add update a stock it get the name of product from data base and show it in drop down list so that i can select one of them which i want to update. my code for that form in which drop down list is :

<form id="form1" name="form1" method="post" action="add_stock_process.php">
            <p>Please select the product you want to add 
              <label>
			  
			  <?php 
			   $con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
	
	$query="SELECT name,product_name FROM rpms";
						$result = mysql_query ($query);
						echo "<select name=menu_name value=''><option>Menu Name</option>";
						while($menu=mysql_fetch_assoc($result)){
						echo "<option value=$menu[product_name]>$menu[product_name]</option>";
						}
						echo "</select>";
						?>
		
              </label>
</p>
            <p>Enter the amount of quantity received: 
              <label>
              <input type="number" name="quantity" />
              </label>
            </p>
            <p>
              <label>
              <input type="submit" name="Submit" value="Submit" />
              </label>
            </p>
          </form>

but this code is giving many errors. may b i have wrong position of php. can any1 guide plz

Code appears correct, what are your errors ?

now i have made it correct it works perfectly. n says that my query has been executed successfully but it doesnot update my code can anyone tell me what could be the reason

In line 14 the value should be enclosed with quotes ((X)HTML requirement), which should be escaped (since you double quotes are used as string identifiers), elements of an associative array enclosed in {} and associative index enclosed in single quotes:

echo "<option value=\"{$menu['product_name']}\">{$menu['product_name']}</option>";

If it still does not work check the if $menu has correct (or any at all) values:

print_r($menu);

' ' are not working. "" works and data comes from database and appears in drop down list but now the problem lies that when i select that and make changes those changes donot take affect in database

The problem might then be in add_stock_process.php file which is called upon submitting the form. Post the code of add_stock_process.php so we can help.

here is code for add_stock_process.php

<?php

session_start();

$con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
 
 $sql = "SELECT * FROM rpms ";
 $qur = mysql_query($sql);
 $row = mysql_fetch_array($qur);
 
$product_name=($_POST['product_name']);
$quantity=($_POST['quantity']);
$quantity_add = $row['quantity'] + $quantity;

 $query= "UPDATE rpms SET quantity = '$quantity_add' WHERE product_name='$product_name'";
 
 $result=mysql_query($query);
 if ($result)
 {
 echo "record updated successfully";
 }
 else
 {echo"Updation failed";
 }
 
 ?>

Insert the following code after row 17 to check what the query contains:

die(query);

This will display the query in your browser. Then check whether the query contains appropriate values. If yes, copy the displayed query and paste it into phpMyAdmin (or whichever client you use to access your db) to test what it returns. If there are errors correct them or post them here.

One question: shall your query in line 9 not be narrowed to select the quantity for a specific product? Sometnig like:

$sql = "SELECT `quantity` FROM `rpms` WHERE `product_name`='$product_name'";

yeah in browser the values are correct but now its giving errors that

undefined index

Your select element is named menu_name while you are using the index product_name in the POST array. Check what the indexes in POST array are in add_stock_process.php. Put something like this at the beginning.

print_r($_POST)

i have got same problem in my other file as well in which i want to create new order. m posting both files now

<?php

session_start();

$con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>Home Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../../../Users/dfff/Documents/Unnamed Site 3/mm_travel2.css" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
//--------------- LOCALIZEABLE GLOBALS ---------------
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
//---------------   END LOCALIZEABLE   ---------------

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body bgcolor="#C0DFFD">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr bgcolor="#3366CC">
    <td colspan="3" rowspan="2"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_travel_photo.jpg" alt="Header image" width="382" height="127" border="0" /></td>
    <td height="63" colspan="3" id="logo" valign="bottom" align="center" nowrap="nowrap">insert website name</td>
    <td width="4">&nbsp;</td>
  </tr>

  <tr bgcolor="#3366CC">
    <td height="64" colspan="3" id="tagline" valign="top" align="center">OPTIONAL TAGLINE HERE</td>
	<td width="4">&nbsp;</td>
  </tr>

  <tr>
    <td colspan="7" bgcolor="#003366"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
  </tr>

  <tr bgcolor="#CCFF99">
  	<td colspan="7" id="dateformat" height="25">&nbsp;&nbsp;<script language="JavaScript" type="text/javascript">
      document.write(TODAY);	</script>	</td>
  </tr>
 <tr>
    <td colspan="7" bgcolor="#003366"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
  </tr>

 <tr>
    <td width="165" valign="top" bgcolor="#E6F3FF">
	<table border="0" cellspacing="0" cellpadding="0" width="165" id="navigation">
        <tr>
          <td width="165">&nbsp;<br />
		 &nbsp;<br /></td>
        </tr>
        <tr>
          <td width="165"><a href="javascript:;" class="navText">destinations</a></td>
        </tr>
        <tr>
          <td width="165"><a href="javascript:;" class="navText">airfare</a></td>
        </tr>
        <tr>
          <td width="165"><a href="javascript:;" class="navText">cruises</a></td>
        </tr>
        <tr>
          <td width="165"><a href="javascript:;" class="navText">specials</a></td>
        </tr>
        <tr>
          <td width="165"><a href="javascript:;" class="navText">contact</a></td>
        </tr>
      </table>
 	 <br />
  	&nbsp;<br />
  	&nbsp;<br />
  	&nbsp;<br /> 	</td>
    <td width="50"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="50" height="1" border="0" /></td>
    <td colspan="2" valign="top"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="305" height="1" border="0" /><br />
	&nbsp;<br />
	&nbsp;<br />
	<table border="0" cellspacing="0" cellpadding="0" width="685">
        <tr>
          <td width="685" class="pageName"><div align="center">NEW ORDER </div></td>
		</tr>

		<tr>
          <td class="bodyText"><p>To place a new order</p>
            <p>&nbsp;</p>
          <form name="form1" id="form1" action="order_entering.php">
			Select a product you want to choose:
			  <?php 
			 
	
	$query="SELECT product_id,product_name FROM product";
						$result = mysql_query ($query);
						   
               echo  '<select name="product_name" value="">';
                  echo "<option>";
				  if($result)
						{while($menu=mysql_fetch_assoc($result)){
						echo "<option value=$menu[product_name]>$menu[product_name]</option>";						}
						echo "</select>";
						}
						else
						{ 
						echo" failed";
						}
					
						
						?>      
						
            </p>
              <p>&nbsp;</p>
              <p>Enter the amount of product you want:
                <label>
                <input type="text" name="quantity" />
                </label>
              (It should not be less than 2000pieces) </p>
              <p>
                <label></label>
                <input type="submit" name="Submit2" value="Submit order" />
              </p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>
                <label></label>
</p>
              <p>&nbsp;  </p>
            </form>
            <p>&nbsp; </p>
          <p>&nbsp;</p></td>
        </tr>
      </table>
	   <br />	  </td>
    <td width="50"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="50" height="1" border="0" /></td>
        <td width="190" valign="top"><br />
		&nbsp;<br />
		<table border="0" cellspacing="0" cellpadding="0" width="190">
			<tr>
			<td colspan="3" class="subHeader" align="center">NEW DESTINATIONS</td>
			</tr>

			<tr>
			<td width="40"><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_spacer.gif" alt="" width="40" height="1" border="0" /></td>
			<td width="110" id="sidebar" class="smallText"><br />
			<p><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_travel_photo1.jpg" alt="Image 1" width="110" height="110" vspace="6" border="0" /><br />
			Include a short description here.<br />
			<a href="javascript:;">Read more &gt;</a></p>

			<p><img src="../../../Users/dfff/Documents/Unnamed Site 3/mm_travel_photo2.jpg" alt="Image 2" width="110" height="110" vspace="6" border="0" /><br />
			Include a short description here.<br />
			<a href="javascript:;">Read more &gt;</a></p>
			 <br />
			&nbsp;<br />
			&nbsp;<br />			</td>
			<td width="40">&nbsp;</td>
			</tr>
		</table>	</td>
	<td width="4">&nbsp;</td>
  </tr>
  <tr>
    <td width="165">&nbsp;</td>
    <td width="50">&nbsp;</td>
    <td width="167">&nbsp;</td>
    <td width="486">&nbsp;</td>
    <td width="50">&nbsp;</td>
    <td width="190">&nbsp;</td>
	<td width="4">&nbsp;</td>
  </tr>
</table>
</body>
</html>

<?php


?>

this was the code of form and now the code for its processing is;

<?php 
session_start();
print_r($_POST);
$name=$_SESSION['SESS_CUSTOMER_ID'];

$con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
	
	$product_id=$_POST['product_name'];
	echo "$product_id";
	$quantity=$_POST['quantity'];
	
	$query= "INSERT INTO order (customer_id, product_id, quantity) VALUES ('$name', '$product_id', '$quantity')";
	die($query);
	$result=mysql_query($query);
	
	if ($result)
	{
	echo " Your order has been passed to admin for acceptance/rejection";
	}
	else
	{
	echo " failed";
	}
	?>

What is actually the error now (post the error message)? Do not forget to comment out line 15 in the second script when testing.

these are the errors

( ! ) Notice: Undefined index: product_name in C:\wamp\www\pras\order_entering.php on line 10

( ! ) Notice: Undefined index: quantity in C:\wamp\www\pras\order_entering.php on line 12

Seems like order_entering.php script is not getting correct values in the POST array. Have you checked what is contained in the $_POST array (as I suggested insert the print_r($_POST) line in the beginning of the second script and tell us what it displays)?

yeah the problem was with _POST thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.