Page 1 of 1

got somthing but not work

Posted: Wed Jan 12, 2011 12:27 am
by madu
hi friends
now i have got partial code for my program,,,,still i cant insert value to database table,,,the table name should be taken from dropdown list ,,,,but no error comes,,,,help me

Code: Select all

<html>
<body>
<form name=for method=post onClick="showSelected();" action="<?php echo $_SERVER[PHP_SELF]; ?> " >
Enter the user name:&nbsp<input type=text name=uname style="position:absolute;left:160px"><br><br>
Enter the mail id:&nbsp<input type=text name=eid style="position:absolute;left:160px"> 
<input type=submit name=but style="position:absolute;left:140px;top:150px" value=Add Me><br>
</form>
<?php
session_start() or die("errror");
include "tacre.php";
//$rt=trim("None");
$da= "show tables";
$ds=mysql_query($da) or die("Error While retreiving tables". mysql_error());
$t=0;
$dar=array();

while($er=mysql_fetch_assoc($ds))
{
//print $er['Tables_in_gm']."<br>";
$dar[$t]=$er['Tables_in_gm'];
$t++;
}
echo "<br>";
echo "Select the group you want to add =>";
echo "<select id=ty name=group>";
echo "<OPTION > None</option>";
foreach ($dar as $key => $value)
{
echo "<OPTION > $value</option>";

}
echo "</select>";

$rt='<script language=javascript>
function showSelected()
{
var show=document.getElementById("ty").options[document.getElementById("ty").selectedIndex].value;
	document.write(show);
}
</script>';
//$_SESSION['tab']= $rt;

if(isset($_POST[but]))
 {
$un=$_POST['uname'];
$e=$_POST['eid'];
//print_r($rt);
if(mysql_query("insert into $rt values('".$un."','".$e."')" or die("error in insertion")))
echo "Successfully Added";
}
?>
</body>
</html>

Re: got somthing but not work

Posted: Wed Jan 12, 2011 3:05 am
by social_experiment
You don't give you option tags any value attributes, hence the no table problem.

Code: Select all

<?php
echo "Select the group you want to add =>";
echo "<select id=ty name=group>";
echo "<OPTION > None</option>";
foreach ($dar as $key => $value)
{
// no value attribute 
echo "<OPTION > $value</option>";
// this should be
// echo '<option value="'. $value .'" > '. $value .' </option>';

}
echo "</select>";
?>
You can also access the value using php ($_POST['group']). This will return the value of the table. The problem could also be in the javascript, or rather passing the value from the javascript to the php. Last point of interest, you seem to neglect using the correct html syntax to create your form. Probably not such an issue but you never know.