Jump to content

Recommended Posts

Posted

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

  • Administrators
Posted

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);

Posted

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.

  • Administrators
Posted

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.

Posted

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);
?> 

  • 1 month later...
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...