Page 1 of 1

run statement

Posted: Fri Jan 22, 2010 4:47 am
by kyroolUnwar
who can help me???

for($x=0; $x<$rowsCount; $x++)
{
$sql = "INSERT INTO PRS_TEST
(
NO_KAD_PENGENALAN,
NAMA_PERIBADI,
NO_FAIL_KPM,
KOD_IPT
)
VALUES
(
".$_SESSION['loading']['content'][$x][0].",
'".$_SESSION['loading']['content'][$x][1]."',
'".$_SESSION['loading']['content'][$x][2]."',
'".$_SESSION['loading']['content'][$x][3]."',
'".$_SESSION['loading']['content'][$x][4]."'
)";

$myQuery->query($sql,'RUN');
}


Why when I run this, the output is:

INSERT INTO PRS_TEST (NO_KAD_PENGENALAN,NAMA_PERIBADI,NO_FAIL_KPM,KOD_IPT) VALUES( 843,'SHOB','A01/E520LP/R1','A01')

but it empty in database.. I not echo the statement.

Re: run statement

Posted: Fri Jan 22, 2010 9:26 pm
by JakeJ
Easy:

Turn this: "$_SESSION['loading']['content'][$x][0]"

In to this: '$_SESSION[loading][content][$x][0]'

Furthermore, you have specified 4 column names and 5 variable names (0-4 is 5), that will blow it up too.

I hope this helped.

Re: run statement

Posted: Sat Jan 23, 2010 8:21 am
by kyroolUnwar
ohh.. thanks.. i already correct that.. but it still not work.. but when I run the sql in database, it will stored the data.. I think the problem cause from $myQuery->query($sql,'RUN');

Re: run statement

Posted: Sat Jan 23, 2010 8:54 am
by JakeJ
kyroolUnwar wrote:ohh.. thanks.. i already correct that.. but it still not work.. but when I run the sql in database, it will stored the data.. I think the problem cause from $myQuery->query($sql,'RUN');

Ah, I didn't notice that at first. try this:

Code: Select all

mysql_query($sql)
Also, you're missing a semi-colon AND a close quote here:

Code: Select all

#This
$sql = "INSERT INTO PRS_TEST
#Should be this
$sql = "INSERT INTO PRS_TEST";

Re: run statement

Posted: Sat Jan 23, 2010 9:20 am
by kyroolUnwar
I don't sure, mysql_query($sql) can use for oracle database?

one more thing, my sql statement actually,

$sql = "INSERT INTO PRS_TEST (NO_KAD_PENGENALAN, NAMA_PERIBADI, NO_FAIL_KPM, KOD_IPT ) VALUES (".$_SESSION['loading']['content'][$x][0].",'".$_SESSION['loading']['content'][$x][1]."','".$_SESSION['loading']['content'][$x][2]."','".$_SESSION['loading']['content'][$x][3]."')";

$myQuery->query($sql,'RUN');

I actually familiar to php mysql database, this year, i try to learn php oracle database... it hard to me... I think oracle can do more then mysql can do.. so I try to learn oracle.. but... why this error happen..

Re: run statement

Posted: Sat Jan 23, 2010 9:40 am
by JakeJ
kyroolUnwar wrote:I don't sure, mysql_query($sql) can use for oracle database?

one more thing, my sql statement actually,

$sql = "INSERT INTO PRS_TEST (NO_KAD_PENGENALAN, NAMA_PERIBADI, NO_FAIL_KPM, KOD_IPT ) VALUES (".$_SESSION['loading']['content'][$x][0].",'".$_SESSION['loading']['content'][$x][1]."','".$_SESSION['loading']['content'][$x][2]."','".$_SESSION['loading']['content'][$x][3]."')";

$myQuery->query($sql,'RUN');

I actually familiar to php mysql database, this year, i try to learn php oracle database... it hard to me... I think oracle can do more then mysql can do.. so I try to learn oracle.. but... why this error happen..
I had no idea it was Oracle. Nevermind. It might also be helpful to assign your $_SESSION variables to something more reasonably named. for example: $session1 = "$_SESSION['loading']['content'][$x][2]"

I see you still have your single quote marks in the wrong place and you also need to eliminate the periods before and after the variable name. So then your SQL statment will be as follows,

Code: Select all

$sql = "INSERT INTO PRS_TEST (NO_KAD_PENGENALAN, NAMA_PERIBADI, NO_FAIL_KPM, KOD_IPT )  VALUES ('$session1', '$session2', '$session3', '$session4')";
That will make your statement much easier for you to read and is less prone to mistakes. And if you really wanted to get fancy, test each of your variables with an If(isset($var)) before attempting to write to the database.