-
insert problem
hi,
i created a table
CREATE TABLE emp_details (
id int(10) NOT NULL auto_increment,
projektnr varchar(100) NOT NULL default '',
hvorgang varchar(100) NOT NULL default '',
uvorgang varchar(100) NOT NULL default '',
soll varchar(100) NOT NULL default '',
status varchar(100) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM
now the problem is im trying to insert the values for hvorgang and uvorgang for particular id thru application for that i created a text field and submit button im using php4.0.6
PHP Code:
$nr +=0;
if (isset($HTTP_POST_VARS['add'])){
mysql_query("INSERT into emp_details SET hvorgang = '".$HTTP_POST_VARS['newhvorgang']."' WHERE id = $nr");
mysql_query("INSERT into emp_details SET uvorgang = '".$HTTP_POST_VARS['newuvorgang']."' WHERE id = $nr");
}
but im not able to get iserted teh value in database anybody help me out be appreciable
thanks in advance
-
i am not a php guy, but looking at the SQL statement (if i read it correctly) you are mixing up INSERT and UPDATE statements.
insert should be something like:
INSERT INTO table_name VALUES (value1, value2, ...)
the SET and WHERE clause are not envolved in an INSERT. these are usually used in an UPDATE statement.
sometimes it is good to just try the statement from outside the application and see what kind of errors you are getting if the application doesn't trap them.
-
thanks alot but plz have a look at the below link
http://server2.vitodesign.com/scripts/drop.phtml
then how i can insert the values in drop down thru application for both fields at same time if not clear shall i post my code so that it will be more clear
-
if i understand the php formating you insert should be something like:
mysql_query("INSERT into emp_details (hvorgang,uvorgang) VALUES ('".$HTTP_POST_VARS['newhvorgang']."','".$HTTP_POSTVARS['newuvorgang']."'");
-
it works but in database it inserts twice plz have a look at the link
$nr +=0;
if (isset($HTTP_POST_VARS['add'])){
mysql_query("INSERT INTO emp_details(id, hvorgang, uvorgang) VALUES(".$nr.", ' ".$HTTP_POST_VARS['newhvorgang']." ', ' ".$HTTP_POST_VARS['newuvorgang']." ')");
}
and delete function wont works dont no why
if (isset($HTTP_POST_VARS["remove"])){
mysql_query("DELETE FROM emp_details WHERE id = $nr");
}
and in MYSQL database it prints like this
id hvorgang uvorgang
1 test test1
2 test test1
3 gfgf fgfgf
hope this is clear
-
i am not a php guy
i did go to the site and hit the add button a few times. delete the rows from the table and try again to see if you are truly getting multiple rows for the insert. if so, you will have to check your logic in the code.
i am not a php guy
but if the delete statement should follow the insert statement format i think you have missplaced a few characters. might be:
mysql_query("DELETE FROM emp_details WHERE id = ".$nr.);
-
[thanks alot for ur sincere advice
now it works fine actually i modified but anybody plz help me how to update the selected value from drop down let say if i select test and it will display in text field and then when i change it to any name let say FORUM then this name be replaced hope this is clear
plz have a look at this link http://server2.vitodesign.com/scripts/drop.phtml for more clearity
i want update to work rest is working add and delete
PHP Code:
<?
include("../settings.php");
/* Connecting, selecting database */
$link = mysql_connect("$dbhost", "$dbuser", "$dbpw")
or die("Could not connect");
mysql_select_db("$dbuser") or die("Could not select database");
#ADD ITEM
if (isset($HTTP_POST_VARS["add"]))
{
if (isset($HTTP_POST_VARS["NEWuvorgang"]) && $HTTP_POST_VARS["NEWuvorgang"]!="")
{
mysql_query("INSERT INTO uvorgang SET name = '".$HTTP_POST_VARS["NEWuvorgang"]."'");
}
elseif (isset($HTTP_POST_VARS["NEWhvorgang"]) && $HTTP_POST_VARS["NEWhvorgang"]!="")
{
mysql_query("INSERT INTO hvorgang SET name = '".$HTTP_POST_VARS["NEWhvorgang"]."'");
}
}
#REMOVE ITEM
if (isset($HTTP_POST_VARS["remove"]))
{
if (isset($HTTP_POST_VARS["uvorgang"]))
{
mysql_query("DELETE FROM uvorgang WHERE name = '".$HTTP_POST_VARS["uvorgang"]."'");
}
elseif (isset($HTTP_POST_VARS["hvorgang"]))
{
mysql_query("DELETE FROM hvorgang WHERE name = '".$HTTP_POST_VARS["hvorgang"]."'");
}
}
?>
<TABLE border="1" width="170" height="1" bgcolor="#666666" align="left" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF">
<TR bordercolor="#FFFFFF" bgcolor="#333333">
<TD height="1" colspan="3">
<P align="center"><B><FONT face="Arial" size="2" color="#FF6600">Hauptvorgang</FONT></P>
</TD>
</TR>
<TR bordercolor="#FF6600">
<TD nowrap>Enter Option Name:
<?
$queryH = mysql_query("SELECT * FROM hvorgang");
echo " <form name=FORMhvorgang action='' method=post>
<input type=text size=10 name=NEWhvorgang>
<SELECT name=hvorgang>";
while($hvorgang=mysql_fetch_object($queryH))
{
echo "<option>$hvorgang->name</option>";
}
echo " </SELECT> <input type=submit name=add value=add>
<input type=submit name=remove value=remove></form>";
?>
</TD>
</TR>
<TR bordercolor="#FFFFFF" bgcolor="#333333">
<TD height="1" colspan="3">
<P align="center"><B><FONT face="Arial" size="2" color="#FF6600">Untervorgang</FONT></P>
</TD>
</TR>
<TR bordercolor="#FF6600">
<TD nowrap>Enter Option Name:
<?
$queryU = mysql_query("SELECT * FROM uvorgang");
echo " <form name=FORMuvorgang action='' method=post>
<input type=text size=10 name=NEWuvorgang>
<SELECT name=uvorgang>";
while($uvorgang=mysql_fetch_object($queryU))
{
echo "<option>$uvorgang->name</option>";
}
echo " </SELECT> <input type=submit name=add value=add>
<input type=submit name=remove value=remove></form>";
?>
</TD>
</TR>
</TABLE>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|