6 Replies - 382 Views - Last Post: 31 March 2011 - 07:43 PM Rate Topic: -----

#1 joerdie  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-April 10

The other end of a $_GET .

Posted 31 March 2011 - 05:51 PM

Hello all. When on my website, the index.php sends a query to my database that returns a bunch of pictures that are then formatted into links like so.

function home_query() {
		
	mysql_connect('localhost', 'USERNAME', 'PASSWORD') or die(mtsql_error());
	mysql_select_db("DATABASE NAME") or die(mtsql_error());
		$home_query = mysql_query("SELECT * FROM tPost WHERE showPostID = 1 OR postDate > DATE_SUB(NOW(), INTERVAL 30 DAY) ORDER BY postDate DESC") or die(mtsql_error());
	
		while($row = mysql_fetch_array($home_query)) {
			echo '<a href="www.joerdiesucks.com/single_post.php?postID=' . $row['postID'] . '">' . $row['postImage'] . '</a>' . "<br />" . $row['post'] . "<br />"; }
		
}



On the single_post page, there is a function called postPicked() that is called. I want the $_GET method to pull the postID and display the post. Here is what I have that does not work.

function postPicked() {
	
	mysql_connect('localhost', 'USERNAME', 'PASSWORD') or die(mtsql_error());
	mysql_select_db("DATABASE NAME") or die(mtsql_error());
		echo $_GET["postID"];	
}



I have tried many versions if this and seem to just not $_GET it. (huh) Would something like this work?


echo $_GET['postImage'] . "<br />"
echo $_GET['post'];




If so, what part of my code is not working properly?

Very confused. Thanks a ton.

Is This A Good Question/Topic? 0
  • +

Replies To: The other end of a $_GET .

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2988
  • Posts: 10,326
  • Joined: 08-August 08

Re: The other end of a $_GET .

Posted 31 March 2011 - 06:02 PM

$_GET has nothing to do with database queries. It is a means of sending data from the client to the server.
Was This Post Helpful? 1
  • +
  • -

#3 joerdie  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-April 10

Re: The other end of a $_GET .

Posted 31 March 2011 - 06:10 PM

Is there a better way to do what I want?
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: The other end of a $_GET .

Posted 31 March 2011 - 06:18 PM

You were starting but you never finished...
function postPicked() {
	
	mysql_connect('localhost', 'USERNAME', 'PASSWORD') or die(mtsql_error());
	mysql_select_db("DATABASE NAME") or die(mtsql_error());
	$id = mysql_real_escape_string[$_GET["postID"]];
        $query = "SELECT * FROM yourtable WHERE postID = '$id'";
	//... you get the point
}


Was This Post Helpful? 1
  • +
  • -

#5 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: The other end of a $_GET .

Posted 31 March 2011 - 06:37 PM

I realize these are simple typos but figured I would point them out. In a few places you have
or die mystl_error();



that should of course be
or die mysql_error();


Was This Post Helpful? 1
  • +
  • -

#6 joerdie  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-April 10

Re: The other end of a $_GET .

Posted 31 March 2011 - 07:25 PM

View Postcodeprada, on 31 March 2011 - 06:18 PM, said:

You were starting but you never finished...
function postPicked() {
	
	mysql_connect('localhost', 'USERNAME', 'PASSWORD') or die(mtsql_error());
	mysql_select_db("DATABASE NAME") or die(mtsql_error());
	$id = mysql_real_escape_string[$_GET["postID"]];
        $query = "SELECT * FROM yourtable WHERE postID = '$id'";
	//... you get the point
}



Wow that helps a ton. Thanks. I fixed a few errors. (the a href pointer was going to the full web addy when it should have just gone to the new page, and Jstall rightfully pointed out that I had written mtsql instead of mysql all over the place. Thanks Jstall.)

I was able to get all of the errors out of the code according to Dreamweaver with this function.


function postPicked() {
	
	mysql_connect('localhost', 'joerdie', 'tosTNGds9vgrent') or die(mysql_error());
	mysql_select_db("joerdie_joerdie") or die(mysql_error());
		$id = $_GET["postID"];
		$query = ("SELECT * FROM tPost WHERE postID = '$id'") or die(mysql_error());
		
			while($row = mysql_fetch_array($query)) {
				echo '<a href="/single_post.php?postID=' . $row['postID'] . '">' . $row['postImage'] . '</a>' . "<br />" . $row['post'] . "<br />"; }
		
}




When I call the function I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/joerdie/public_html/includes.php on line 206.

Line 206 is,


while($row = mysql_fetch_array($query)) {




This while loop worked well before. Any reason why it isn't working now? Thanks.
Was This Post Helpful? 0
  • +
  • -

#7 joerdie  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 06-April 10

Re: The other end of a $_GET .

Posted 31 March 2011 - 07:43 PM

Never mind! I fixed the issue by placing "mysql_query" before the SELECT statement.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1