Solved

PHP Mysql Insert from url value

Posted on 2011-09-13
3
350 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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