Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Mysql Insert from url value

Posted on 2011-09-13
3
Medium Priority
?
355 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
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 dynamically set the form action using jQuery.
Suggested Courses

972 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