Solved

PHP Mysql Insert from url value

Posted on 2011-09-13
3
348 Views
Last Modified: 2012-06-21
I have a page that returns a value to itself in the url 'searchvalue' if this value is not null I want to insert this into a database table 'searchedfor' with colums: 'date,searchvalue'

Can anyone point me to the correct information on how I can do this please?
0
Comment
Question by:tonypearce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36530012
Grab a copy of this book - you will love it.
http://www.sitepoint.com/books/phpmysql4/

Show us how the page returns a value to itself.  I think it's a GET method request, but I want to be sure.  You can find the values that are URL parameters in $_GET.  You can use var_dump($_GET) to see what is in there.
0
 
LVL 4

Expert Comment

by:mustang83
ID: 36530042
Here is the link to the w3 php get pages.

http://www.w3schools.com/php/php_get.asp

Hope this helps
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36530049
Regarding this part database table 'searchedfor' with colums: 'date,searchvalue' you do not want to use a MySQL reserved word for the name of a column, so you might want to change date to searchdate.

The general design pattern would probably be something like this:

$sv = mysql_real_escape_string($_GET['searchvalue']);
$dt = date('c');
$sql = "INSERT INTO searchedfor (searchdate, searchvalue) VALUES ( '$dt', '$sv')";
$res = mysql_query($sql) or die( "$sql FAILED " . mysql_error() );
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
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 …

749 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