INSERT INTO ~~ Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

INSERT INTO ~~ Problem

Post 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
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: INSERT INTO ~~ Problem

Post 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!
 
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

Re: INSERT INTO ~~ Problem

Post by azhan »

thanks a lot jaoude...im going to test it now...
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: INSERT INTO ~~ Problem

Post by jaoudestudios »

cool, let me know how you get on.
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

Re: INSERT INTO ~~ Problem

Post by azhan »

IT WORKS!!

thanks a lot jaoude !

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

thanks
azhan
Post Reply