got somthing but not work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
madu
Forum Commoner
Posts: 32
Joined: Sat Dec 25, 2010 3:19 am
Location: india

got somthing but not work

Post 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>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: got somthing but not work

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply