User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 375,207 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,314 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 820 | Replies: 16 | Solved
Reply
Join Date: May 2008
Posts: 23
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Newbie Poster

$_GET['id'] is not working?????

  #1  
May 14th, 2008
i am extemly newbie and don’t know whether I should post my problem here or somewhere else, however…
i have following problem in one of my php-mysql application
header link through browser is,
"http://localhost/test/reply.php?id=852"
and query is as follow,
 $name=$_POST['name'];   //from  the name form  
$q_id=$_GET['id'];
$sql="INSERT INTO `test`.`reply`(`rid`,`tid`,`name`)VALUES(NULL,'$q_id','$name')";
$result=mysql_query($sql);
The application does not pass any value related to $q_id in database table, the table view is as follow, The query does not insert any value to tid column except default value. What should I do…
rid 	tid	name 
1	0	karam
3	0	drupal
4	0	Shuja-u-Rehman

The table specification is as follow,
Field	Type	      Null	Default	Extra
rid	int(11)	      No		auto_increment
tid	int(11)	      No		
name	varchar(25)     No		

I have tried every method, I know but in vain.
Please any body helps me….

Shuja
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: $_GET['id'] is not working?????

  #2  
May 14th, 2008
Hmm.. Does it give any error ? print out the query and see whats being passed as values..

$name=$_POST['name']; //from the name form
$q_id=$_GET['id'];

What method have you specified for the form ? POST or GET ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: May 2008
Posts: 23
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Newbie Poster

Re: $_GET['id'] is not working?????

  #3  
May 14th, 2008
it does not give any error, $_GET['id'] is extracting from "http://localhost/test/reply.php?id=852"
and $_POST['name'] is coming from form using POST method, it is working well. But the $q_id=$_GET['id'] is not being inserted in database table.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: $_GET['id'] is not working?????

  #4  
May 14th, 2008
So, is your form action is like this ?
  1. <form method="POST" action="reply.php?id=852">
  2. </form>
If this is the case, then it should work fine. If not, then you should post your code..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 71
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: $_GET['id'] is not working?????

  #5  
May 14th, 2008
You need to isolate the problem. At this point, you don't know if the GET variable is not picking up the value or if the value is not being inserted into thte table.

add echo $q_id;

just after

$q_id=$_GET['id'];

also add echo $sql;

just before you assign the INSERT statement to $sql.

That will tell you right away where the problem lies.
Reply With Quote  
Join Date: May 2008
Posts: 23
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Newbie Poster

Re: $_GET['id'] is not working?????

  #6  
May 14th, 2008
i can not tell you, how much i am thankful to you. yes it was the error. thanks for your great hint. application is working like rocket...
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: $_GET['id'] is not working?????

  #7  
May 14th, 2008
Umm.. so, what was the error ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Location: Somewhere in Germany
Posts: 53
Reputation: JRSofty is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
JRSofty's Avatar
JRSofty JRSofty is offline Offline
Junior Poster in Training

Re: $_GET['id'] is not working?????

  #8  
May 14th, 2008
His problem is quite simple actually. Here's his original code
 $name=$_POST['name'];   //from  the name form  
$q_id=$_GET['id'];
$sql="INSERT INTO `test`.`reply`(`rid`,`tid`,`name`)VALUES(NULL,'$q_id','$name')";
$result=mysql_query($sql);

All he needs to do is remove the single quotes (' ') from around the $q_id in his SQL.

So his new code should look like this:
 $name=$_POST['name'];   //from  the name form  
$q_id=$_GET['id'];
$sql="INSERT INTO `test`.`reply`(`rid`,`tid`,`name`)VALUES(NULL, $q_id ,'$name')";
$result=mysql_query($sql);

He has declared the tid field as an integer and he is trying to pass it as a string. MySQL probably doesn't like it.

ALSO

Just to be on the safe side you really need to run the $_GET['id'] and the $_POST['name'] variables through the mysql_real_escape_string() function to prevent someone from doing nasty things to your database. Example:
  1. $q_id = mysql_real_escape_string($_GET['id']);
  2. $name = mysql_real_escape_string($_POST['name']);

Hope that helps you.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: $_GET['id'] is not working?????

  #9  
May 14th, 2008
He has declared the tid field as an integer and he is trying to pass it as a string. MySQL probably doesn't like it.
No.. That wouldn't be a problem.. You can pass an integer like a string, but not vice-versa.
I still believe its the form action which was causing the problem!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 71
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: $_GET['id'] is not working?????

  #10  
May 14th, 2008
I have to agree with nav33n. That would not cause the problem.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC