Forum Moderators: coopster

Message Too Old, No Replies

insert

         

franches

2:32 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



hi,
sorry if my post is too long I think these are all important. My problem is that after the user press the add button it doesn't insert in my database but it refreshes the page and it doesn't even display the message ("DATA ADDED SUCCESSFULLY!")but i tried to check the hidden field/data if the data inputed exists and it data are there but the data are not inserted in my database. any idea where in my code is wrong? I am having hardtime tracing it. hope someone could help me.


<head>
<script language="javascript">
//some functions here

function addButtonUp_onclick() {
NewDataForm.addButtonUp.disabled = true;
s = "NewData1209.php?tempDateValue="+NewDataForm.DateLog.value+ "&tempProjValue="+NewDataForm.NewPrjSelect.value+"&tempPrjCodeValue="+ NewDataForm.PrjCode.value+"&tempMapNumberValue="+ NewDataForm.MapNumber.value+"&tempDivisionValue="+ NewDataForm.Division.value+"&tempActValue="+ NewDataForm.NewActivityNameSelect.value+"&tempActCodeValue="+ NewDataForm.NewActivityNameSelect.value+"&tempMedValue="+ NewDataForm.NewMediumNameSelect.value+"&tempMedCodeValue="+ NewDataForm.MediumCodeBox.value+"&addButtonUpTemp="+ NewDataForm.addButtonUp.value+"&tempTotalRegValue="+ NewDataForm.TotalRegHrsBox.value+"&tempTotalOtValue="+ NewDataForm.TotalOtHrsBox.value+"&tempPStatusValue="+ NewDataForm.PStatusBox.value+"&tempRegValue="+ NewDataForm.RegHrsBox.value+"&tempOtValue="+NewDataForm.OtHrsBox.value+"";
window.open(s,"dataview");
}
</script>
</head>
<body>
<form name="NewData1209.php" method="POST">
<?
//hidden fields containing the inputed data
//if statements if the user filled up all the data then it will insert

$DBConn=mysql_connect("localhost","root");
mysql_select_db("TEST",$DBConn);
$SQLString="select * from StatusTable";
$rs=mysql_query($SQLString);
$SQLString="INSERT INTO StatusTable (ActDate,PIN,PrjCode,MapNumber";
$SQLString=$SQLString."ActCode,MediumCode,RegHrs,OTHrs,PStatus,P_id,DataFiled) VALUES ";
$SQLString=$SQLString."('".$_POST["tempDateValue"]."',";
$SQLString=$SQLString." '".$tempUserNameNew2."',";
$SQLString=$SQLString." '".$_POST["tempPrjCodeValue"]."',";
$SQLString=$SQLString." '".$_POST["tempMapNumberValue"]."',";
$SQLString=$SQLString." '".$_POST["tempActCodeValue"]."',";
$SQLString=$SQLString." '".$_POST["tempMedCodeValue"]."',";
$SQLString=$SQLString." '".round($_POST["tempTotalRegValue"],2)."',";
$SQLString=$SQLString." '".round($_POST["tempTotalOtValue"],2)."',";
$SQLString=$SQLString." '".round($_POST["tempPStatusValue"],2)."',";
$SQLString=$SQLString." '".$_SESSION['username']."',";
$SQLString=$SQLString." '".$dateToday."')";

$NewDataToggle="Added";
?>
<script language="javascript">
<!--
if (NewDataForm.AddDataToggleNew.value == "Added")
{
alert("DATA ADDED SUCCESSFULLY!")
document.NewDataForm.submit()
}
-->
</script>

<input class=button style="width:100%" type="button" value="ADD" id="addButtonUp" name="addButtonUp" title="Add Record" onclick="return addButtonUp_onclick()">
</body>

[edited by: jatar_k at 9:18 pm (utc) on Dec. 10, 2004]
[edit reason] fixed sidescroll [/edit]

bloke in a box

3:00 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



You're using $SQLString to select everything from the database, then running the SQL command to do it.

Then you're just telling PHP what $SQLString consists of without actually running the $rs=mysql_query($SQLString); again :)

franches

6:31 am on Dec 13, 2004 (gmt 0)

10+ Year Member



what do you mean?

i tried to change my code this way


$DBConn=mysql_connect("localhost","root");
mysql_select_db("TEST",$DBConn);
$SQLString="INSERT INTO StatusTable (ActDate,PIN,PrjCode,MapNumber" ...
$rs=mysql_query($SQLString);
$NewDataToggle="Added";

and when i press the add button it refreshes the page but the data are not yet inserted into my database.

franches

8:30 am on Dec 15, 2004 (gmt 0)

10+ Year Member



thanks for taking the time to read my post. i got it already i just missed some codes.