Selection and Insertion to a table

Nandhu
2008-04-18 15:10:02
Selection and Insertion to a table
table_primarytest.php:=
---------------------
<?
$LoginRequired="No";
include("templates/npes_supheader.php");
?>

<form method=post name=subf action="test_appln.php" >
<table>
<tr>
<td>Roll NO</td>
<td><input type=text name=no value=""></td>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=name value=""></td>
</tr>
<tr>
<td>Material Name</td>
<td><select name=material_name>
<option>select 1</option>
<?
$q=db_query("SELECT * FROM `abranch_table`");
while($r=db_fetch_object($q))
{
?>
<option value="<?=$r->material_name?>">
<?=$r->material_name?>
</option>
<?
}
?>
</select>
</td>
</tr>
</table>
<Br>
<table align=center>
<tr><td>&nbsp;</td><td><input type=submit name=submit value="Send Request"><input type=reset name=reset value="Clear Form"></td></tr>
</table>

</form>


test_appln.php:=
---------------

<?
require_once("classes/db_lib.inc");
$c1=db_connect();

//echo $material_name;
$m= "select material_id from abranch_table where material_name='$material_name';
$res=db_fetch_object($m);

//echo $res;
$q="insert into amain_table(Roll_id,Name,material_id)
values
('$no','$name','$res')";
$req=db_query($q);
?>
<br>
<br>
<br>
<h2><center>inserted</h2></center>
<br>
<br>
<a href="table_primarytest.php"> Home </a>


Among these 2 php files,first file works properly and the queries in test_appln.php is working. But the Database table is not getting updated... I tried to echo the 'echo $res;' and
'echo $material_name;' but dat too is not working...

Can u help me?
Veselin
2008-04-18 15:32:06
Re:
I think you should use $_POST["no"], $_POST["name"], $_POST["material_name"] to get the values of the submitted form.
Nandhu
2008-04-22 12:40:35
Re:
I've tried as follows... But i cud not get it...
Is there anything wrong with my coding?

<?
require_once("classes/db_lib.inc");
$c1=db_connect();

$no=$_POST["no"];
$name=$_POST["name"];
$material_name=$_POST["material_name"];

echo $material_name;
$m= "select material_id from abranch_table where material_name='$material_name';
$res=db_fetch_object($m);

//echo $res;
$q="insert into amain_table(Roll_id,Name,material_id)
values
('$no','$name','$res')";
$req=db_query($q);
?>
<br>
<br>
<br>
<h2><center>inserted Posted</h2></center>
<br>
<br>
<a href="table_primarytest.php"> Home </a>



Veselin
2008-04-22 13:12:31
Re:
please try this
$q = "insert into amain_table(Roll_id,Name,material_id) values ('".mysql_escape_string($no)."','".mysql_escape_string($name)."','".mysql_escape_string($res)."')";
$req = mysql_query ($q) or die ('request "Could not execute SQL query" '.mysql_errno($req));
and let me know if you see any error message
Nandhu
2008-04-22 13:30:07
Re:
Sorry... I don't recieve any error message.
Nothing is displayed in the browser...
Nandhu
2008-04-22 13:43:14
Re: Hi I got it ! Thanks a lot...
echo $material_name;
$m= "select material_id from abranch_table where material_name='$material_name';
---
$res=db_fetch_object($m);

See i've made a syntax error at the place ive underlined... Ive missed the close quotes...

Now that ive checked..... It's working...

Thanks a lot for suggesting this POST method !
Reply
Title:
Your name:
Your email: (email address will not be posted on the web site)
Reply:
Verification