943,916 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 10831
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
May 14th, 2008
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
servis is offline Offline
82 posts
since May 2008
May 14th, 2008
0

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

Hmm.. Does it give any error ? print out the query and see whats being passed as values..
Quote ...
$name=$_POST['name']; //from the name form
$q_id=$_GET['id'];
What method have you specified for the form ? POST or GET ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
May 14th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
servis is offline Offline
82 posts
since May 2008
May 14th, 2008
0

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

So, is your form action is like this ?
php Syntax (Toggle Plain Text)
  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..
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
May 14th, 2008
0

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

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.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
May 14th, 2008
0

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

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...
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
servis is offline Offline
82 posts
since May 2008
May 14th, 2008
0

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

Umm.. so, what was the error ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
May 14th, 2008
0

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

His problem is quite simple actually. Here's his original code
PHP Syntax (Toggle Plain Text)
  1. $name=$_POST['name']; //from the name form
  2. $q_id=$_GET['id'];
  3. $sql="INSERT INTO `test`.`reply`(`rid`,`tid`,`name`)VALUES(NULL,'$q_id','$name')";
  4. $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:
PHP Syntax (Toggle Plain Text)
  1. $name=$_POST['name']; //from the name form
  2. $q_id=$_GET['id'];
  3. $sql="INSERT INTO `test`.`reply`(`rid`,`tid`,`name`)VALUES(NULL, $q_id ,'$name')";
  4. $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:
php Syntax (Toggle Plain Text)
  1. $q_id = mysql_real_escape_string($_GET['id']);
  2. $name = mysql_real_escape_string($_POST['name']);

Hope that helps you.
Reputation Points: 16
Solved Threads: 10
Junior Poster in Training
JRSofty is offline Offline
68 posts
since Dec 2007
May 14th, 2008
0

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

Quote ...
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!
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
May 14th, 2008
0

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

I have to agree with nav33n. That would not cause the problem.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Write a one echo statment from html
Next Thread in PHP Forum Timeline: help needed for my update.....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC