473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Simple beginners question about inserting data via an URL

Hi all,

For a couple of nights I have been trying to figure something out..

I am trying insert a couple of fields into a database. My url looks
something like this;

www.site.com/addlog.php?var1=blah&var2=blah

The addlog.php script looks like this;

<?php
$dbhost = 'xx';
$dbuser = 'xx';
$dbpass = 'xx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or
die ('Error connecting to mysql');

$dbname = 'xx';

mysql_select_db($dbname);
$query = "INSERT INTO log values('$var1','$var2');";
print_r($_GET);
mysql_query($query) or die('Error, insert query failed');

mysql_close($conn);
?>

The var1 variable gets passed on just fine (I even see it echoed back
with the print command).. but var2 seems to dissapear.. It never gets
passed to anywhere..
What am I missing here? When I make the url www.site.com/addlog.php?var2=blah&var1=blah
I just see var2.. so it seems to only accept the 1st variable..?

Alex

Oct 10 '07 #1
9 1491
To see if they are coming though the URL to the script okay, which
they should be.

echo $_GET['var1'] . "<br />" . $_GET['var2'];


Try

$var1 = mysql_real_escape_string($_GET['var1']);
$var2 = mysql_real_escape_string($_GET['var2']);

$query = "INSERT INTO log VALUES ('$var1','$var2')";
mysql_query($query,$conn) or die(mysql_error());

Oct 10 '07 #2
I tried both ideas.. but neither of them return me the string that I
had in the url :(

What I dont understand is that I can pass 1 string, just not multiple
strings from the URL.
On Oct 10, 7:54 pm, macca <ptmcna...@googlemail.comwrote:
To see if they are coming though the URL to the script okay, which
they should be.

echo $_GET['var1'] . "<br />" . $_GET['var2'];

Try

$var1 = mysql_real_escape_string($_GET['var1']);
$var2 = mysql_real_escape_string($_GET['var2']);

$query = "INSERT INTO log VALUES ('$var1','$var2')";
mysql_query($query,$conn) or die(mysql_error());

Oct 11 '07 #3
de**@icepick.com wrote:
On Oct 10, 7:54 pm, macca <ptmcna...@googlemail.comwrote:
>To see if they are coming though the URL to the script okay, which
they should be.

echo $_GET['var1'] . "<br />" . $_GET['var2'];

Try

$var1 = mysql_real_escape_string($_GET['var1']);
$var2 = mysql_real_escape_string($_GET['var2']);

$query = "INSERT INTO log VALUES ('$var1','$var2')";
mysql_query($query,$conn) or die(mysql_error());


I tried both ideas.. but neither of them return me the string that I
had in the url :(

What I dont understand is that I can pass 1 string, just not multiple
strings from the URL.

(Top posting fixed)

If your URL is really something like:

http://www.example.com?var1=blah&var2=blah

Then $_GET['var1'] will contain the first value, and $_GET['var2'] will
contain the second value. If it doesn't work, either your url is wrong
or you're not accessing the data correctly.

P.S. Please don't top post. And when using examples, use example.com as
the domain - that's what it's reserved for.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 11 '07 #4
If you are using a form, check your html form and make sure that you
dont have a spelling mistake for the input name.
Oct 11 '07 #5
If your URL is really something like:
>
http://www.example.com?var1=blah&var2=blah

Then $_GET['var1'] will contain the first value, and $_GET['var2'] will
contain the second value. If it doesn't work, either your url is wrong
or you're not accessing the data correctly.

P.S. Please don't top post. And when using examples, use example.com as
the domain - that's what it's reserved for.
Jerry,
I simplified my webpage to

<?php
echo $_GET['var1'];
echo $_GET['var2'];
echo $_GET['var3'];
?>

And the url I use now to test is (besides the example part)
http://www.example.com/php/blah.php?...lah&var3=candy

When I do this it only returns one variable.
There must be something simple I am missing here..
Oct 12 '07 #6
In our last episode, <11*********************@y27g2000pre.googlegroups. com>,
the lovely and talented de**@icepick.com broadcast on comp.lang.php:
Jerry,
I simplified my webpage to
><?php
echo $_GET['var1'];
echo $_GET['var2'];
echo $_GET['var3'];
?>
And the url I use now to test is (besides the example part)
http://www.example.com/php/blah.php?...lah&var3=candy
When I do this it only returns one variable.
There must be something simple I am missing here..
Are you doing this from the command line? If so, you should single quote
the url because your shell is interpreting the ampersand, not passing it
through.

so for example in bash or sh:

Fri Oct 12 02:49:34 bash3.2:ttyp0:lars
debranded~$lynx -dump http://localhost/~work/index.php?var1=test&var2=blah\
blah&var3=candy
[1] 5661
[2] 5662
Fri Oct 12 02:51:12 bash3.2:ttyp0:lars
debranded~$test
You got test as expected by setting var1, but the shell has done its own
thing with everything after the first &.

Single quote it and it will pass the whole url through:

Fri Oct 12 02:54:33 bash3.2:ttyp0:lars
debranded~$lynx -dump 'http://localhost/~work/index?var1=test&var2=blah\
blah&var3=candy'
testblahblahcandy

Fri Oct 12 02:56:03 bash3.2:ttyp0:lars
debranded~$

Which is the right answer.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?
Oct 12 '07 #7
de**@icepick.com wrote:
>If your URL is really something like:

http://www.example.com?var1=blah&var2=blah

Then $_GET['var1'] will contain the first value, and $_GET['var2'] will
contain the second value. If it doesn't work, either your url is wrong
or you're not accessing the data correctly.

P.S. Please don't top post. And when using examples, use example.com as
the domain - that's what it's reserved for.

Jerry,
I simplified my webpage to

<?php
echo $_GET['var1'];
echo $_GET['var2'];
echo $_GET['var3'];
?>

And the url I use now to test is (besides the example part)
http://www.example.com/php/blah.php?...lah&var3=candy

When I do this it only returns one variable.
There must be something simple I am missing here..
OK, what do you get if you do the following:

<pre>
<?php
print_r($_GET);
echo "\n" . $_SERVER['QUERY_STRING'] . \n";
?>
</pre>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 12 '07 #8
On Oct 12, 10:02 am, Lars Eighner <use...@larseighner.comwrote:
In our last episode, <1192164404.526476.12...@y27g2000pre.googlegroups. com>,
the lovely and talented d...@icepick.com broadcast on comp.lang.php:
Jerry,
I simplified my webpage to
<?php
echo $_GET['var1'];
echo $_GET['var2'];
echo $_GET['var3'];
?>
And the url I use now to test is (besides the example part)
http://www.example.com/php/blah.php?...lah&var3=candy
When I do this it only returns one variable.
There must be something simple I am missing here..

Are you doing this from the command line? If so, you should single quote
the url because your shell is interpreting the ampersand, not passing it
through.

so for example in bash or sh:

Fri Oct 12 02:49:34 bash3.2:ttyp0:lars
debranded~$lynx -dumphttp://localhost/~work/index.php?var1=test&var2=blah\
blah&var3=candy
[1] 5661
[2] 5662
Fri Oct 12 02:51:12 bash3.2:ttyp0:lars
debranded~$test

You got test as expected by setting var1, but the shell has done its own
thing with everything after the first &.

Single quote it and it will pass the whole url through:

Fri Oct 12 02:54:33 bash3.2:ttyp0:lars
debranded~$lynx -dump 'http://localhost/~work/index?var1=test&var2=blah\
blah&var3=candy'
testblahblahcandy

Fri Oct 12 02:56:03 bash3.2:ttyp0:lars
debranded~$

Which is the right answer.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?

Thanks everyone.. this turned out to be the problem indeed.. I tested
it with WGET instead of with a regular web browser..
I got it working now.. thanks a lot.

Oct 13 '07 #9
..oO(de**@icepick.com)
>Thanks everyone.. this turned out to be the problem indeed.. I tested
it with WGET instead of with a regular web browser..
Well, from the server's point of view even WGET is a "regular browser".
It's a user agent that speaks HTTP - like any other browser. So it was
most likely the mentioned shell escaping problem.

Micha
Oct 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
0
by: Leszek Dubiel | last post by:
----------------------------------------- BACKGROUND In my company (www.glass.biz) we use ERP software to compute what has to be done to do products for our customers. Main algorithm takes data...
1
by: J Belly | last post by:
Hi, all: I'm a newbie trying to understand the concept of referential integrity and dealing with Primary and Foreign Keys. I'm sure mine is a simple problem... I've created 3 tables as...
1
by: Tim | last post by:
I can't seem to figure out why this very simple linked list wont build.. I mean, there is no intelligence, just add to end. Anyway, please let me know if something i can do will make head (the...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
7
by: Materialised | last post by:
Hi Folks, Just a quickie, I am inserting some records (individually) into a SQL Server Table. I am wondering how can I detect primary key violations on this data which I am inserting into the...
6
by: Lars | last post by:
Hi all If this is the wrong list for beginners trouble I apologize. please refer to me the correct list in such case. I am trying to create a simple linked list but I keep getting segmentation...
5
by: Kardon Coupé | last post by:
Dear All, I'm bemused, I'm moving an application I've written from VB6 into VS2005, and I'm getting all the fundamentals over before I delve into the hard part, like getting the forms layout...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.