Solved

PHP Mysql Insert from url value

Posted on 2011-09-13
3
343 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
  • 2
3 Comments
 
LVL 108

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now