Solved

Insert data into postgres Database script needed

Posted on 2011-03-09
2
517 Views
Last Modified: 2012-05-11
Hi all,

I need some simple code that does just the following:

Hope the below describes what I need:

<a href="">Save to Database Table</a> //A link here to activate the saving

var $value1='200';  
var $value2='blablabla';

etc...

...then something like:

pg_query("INSERT INTO myTable VALUES ('$value1','$value2','$fvalue3','$value4')");

echo 'Data has been saved';

//the end

Can anyone help put a script together to do the above please?

Thanks


0
Comment
Question by:error77
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35081642
Maybe like this:

<?php

if(isset($_GET[save]) && $_GET[save] == 1){
$conn = pg_pconnect("dbname=yourdb");
$query = "INSERT INTO myTable VALUES ('$value1','$value2')";
pg_query($conn, $query);
echo"saved";
}
?>

<?php
    var $value1='200';  
    var $value2='blablabla';
    
    echo"values: v1: $value1, v2: $value2";
?>

<a href="index.php?save=1">Save to Database Table</a> //A link here to activate the saving

Open in new window

0
 

Author Closing Comment

by:error77
ID: 35083799
Perfect! thanks a lot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question