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
INSERT INTO ~~ Problem
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: INSERT INTO ~~ Problem
Your quotes are incorrect!
use...
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
thanks a lot jaoude...im going to test it now...
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: INSERT INTO ~~ Problem
cool, let me know how you get on.
Re: INSERT INTO ~~ Problem
IT WORKS!!
thanks a lot jaoude !
hehe....next i wanna learn how to use session_key for the security.....
thanks
azhan
thanks a lot jaoude !
hehe....next i wanna learn how to use session_key for the security.....
thanks
azhan