Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Mysql Insert from url value

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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 dynamically set the form action using jQuery.

721 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