Jump to content

How to insert into db


dimitris

Recommended Posts

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

Link to comment
Share on other sites

  • Administrators

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

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...