Solved

Insert data into postgres Database script needed

Posted on 2011-03-09
2
516 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

778 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