dimitris Posted May 17, 2011 Report Share Posted May 17, 2011 Hey all! I m re-making a manual add-on to an easier db based add-on. Currently I have make the SELECT * FROM db but how I can make the INSERT INTO ? Please an example would be very helpful. I know exactly how to make it with simple php but not with that type from the phpVMS inside the functions. Thanks, Dimitris Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted May 17, 2011 Administrators Report Share Posted May 17, 2011 The sql syntax is the same as it would be in open php, then you can use the simple "DB::query(query)" to run the query within phpVMS without having to connect to the db and such. $query = 'INSERT INTO '.TABLE_PREFIX.'thetable (column) VALUES (data)'; DB::query($sql); Quote Link to comment Share on other sites More sharing options...
dimitris Posted May 18, 2011 Author Report Share Posted May 18, 2011 thanks simpilot! One more question, where I can use it ? Inside a function or into a class/module file ? As far as I know it is not possible to use it direct to tpl files. Quote Link to comment Share on other sites More sharing options...
Administrators simpilot Posted May 18, 2011 Administrators Report Share Posted May 18, 2011 It will work in the tpl file, controller, or model, but the design preference of MVC is to have all database interaction within the model. Quote Link to comment Share on other sites More sharing options...
dimitris Posted May 18, 2011 Author Report Share Posted May 18, 2011 So something like this? file.tpl <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> insert.php: <?php $query = "INSERT INTO '.TABLE_PREFIX.'thetable VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; DB::query($sql); ?> or: <form action="" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> <?php $query = "INSERT INTO '.TABLE_PREFIX.'thetable VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; DB::query($sql); ?> Quote Link to comment Share on other sites More sharing options...
dimitris Posted May 19, 2011 Author Report Share Posted May 19, 2011 someone ? Quote Link to comment Share on other sites More sharing options...
James142 Posted June 21, 2011 Report Share Posted June 21, 2011 someone ? I think you would have to use <?php $sql = "INSERT INTO ".TABLE_PREFIX."thetable (firstname, lastname, age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; ?> while having the tables: firstname, lastname, email, age in the table in the mySQL database. I think thats how you do it but I am no expert so it could be completely wrong.. James Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted June 21, 2011 Moderators Report Share Posted June 21, 2011 The easiest way to get the code your looking for is to use php myadmin, manually run the query and get the php code to be displayed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.