Page 1 of 1

INSERT INTO ~~ Problem

Posted: Tue Sep 09, 2008 11:57 am
by azhan
Hey guys,

Need some help,

Im trying to insert into a table where a user choose the table

example like this,
//this is the form
<form method="POST">
<input type="text" name="department" >
<input type="text" name="name" >
<input type="int" name="ic" >
<input type="varchar" name="diagnosis" >
</form>

//then insert into the table where the table itself chosen by the user

$insert = "INSERT INTO "'.$_POST['department'].'" ( name, ic, diagnosis);
$add= mysql_query($insert);

can i use the code that i had high lighted in BLUE in the INSERT INTO coding??

I try many times but when i check my database, no data where inserted into the chosen table
but if i replaced the BLUE coding with the name of the table DIRECTLY, it does work....

huhuhu...help me guys...


thanks
azhan

Re: INSERT INTO ~~ Problem

Posted: Tue Sep 09, 2008 12:15 pm
by jaoudestudios
Your quotes are incorrect!

use...

Code: Select all

 
$insert = "INSERT INTO ".$_POST['department']." SET name = '".$_POST['name']."', ic = '".$_POST['ic']."', diagnosis = '".$_POST['diagnosis']."'"; // dont forget to also protect your database!
 

Re: INSERT INTO ~~ Problem

Posted: Tue Sep 09, 2008 12:23 pm
by azhan
thanks a lot jaoude...im going to test it now...

Re: INSERT INTO ~~ Problem

Posted: Tue Sep 09, 2008 12:28 pm
by jaoudestudios
cool, let me know how you get on.

Re: INSERT INTO ~~ Problem

Posted: Tue Sep 09, 2008 2:32 pm
by azhan
IT WORKS!!

thanks a lot jaoude !

hehe....next i wanna learn how to use session_key for the security.....

thanks
azhan