Page 1 of 1

Query string not working???

Posted: Tue Jan 30, 2007 8:48 pm
by cturner
When I test the code that is below, only the date appears in the query string. I know that the month and year are in the database. Can someone please make a suggestion to what could be wrong? Thanks in advance.

Code: Select all

require "config.php";
$id = $_GET['id'];
	  $select = mysql_query("SELECT * FROM newsletters WHERE id = '$id'") or die ("Could not query because: ".mysql_query());
	  while($r = mysql_fetch_array($select)) {
	  	echo '<a href=newsletter.php?date='.$r['date'].'&month='.$r['month'].'&year='.$r['year'].'>'.$r['date'].' '.$r['month'].' '.$r['year'].'</a>';
	}
if (mysql_affected_rows() == 0) {
	print "No newsletters to be displayed.";
}
mysql_close();

Posted: Tue Jan 30, 2007 9:14 pm
by feyd
var_dump($r) help tell you anything?

mysql_affected_rows() is not for selects. I think you want mysql_num_rows().

$id has not been validated or escaped...

Posted: Tue Jan 30, 2007 9:35 pm
by cturner
When I place var_dump($r); into my code it just displays int(1) continuously down the page. That is after I replace mysql_affected_rows() with mysql_num_rows(). I have tried mysql_fetch_assoc() and mysql_fetch_array() but the query string still doesn't display properly. When I try mysql_fetch_assoc() with var_dump($r) it displays:

Code: Select all

array(18) { 
	["id"]=>
	  string(1) "2" 
	["date"]=>
	  string(11) "Monday 25th" 
	["month"]=>
	  string(8) "December" 
	["year"]=>
	  string(4) "2006" 
	["select1"]=>
	  string(16) "The Wool Market-" 
	["txt1"]=>
	  string(17) "show me the money" 
	["select2"]=>
	  string(14) "Sale Position-" 
	["txt2"]=>
	  string(17) "show me the money" 
	["select3"]=>
	  string(12) "Merchandise-" 
	["txt3"]=>
	  string(17) "show me the money" 
	["select4"]=>
	  string(18) "Christmas Trading-" 
	["txt4"]=>
	  string(17) "show me the money" 
	["select5"]=>
	  string(8) "General-" 
	["txt5"]=>
	  string(17) "show me the money" 
	["select6"]=>
	  string(18) "The Cattle Market-" 
	["txt6"]=>
	  string(17) "show me the money" 
	["select7"]=>
	  string(14) "Some to Quote-" 
	["txt7"]=>
	  string(17) "show me the money"
}
When I try mysql_fetch_array() with var_dump($r) it displays:

Code: Select all

array(36) {
	[0]=>
	  string(1) "2" 
	["id"]=>
	  string(1) "2" 
	[1]=>
	  string(11) "Monday 25th" 
	["date"]=>
	  string(11) "Monday 25th" 
	[2]=>
	  string(8) "December" 
	["month"]=>
	  string(8) "December" 
	[3]=>
	  string(4) "2006" 
	["year"]=>
	  string(4) "2006" 
	[4]=>
	  string(16) "The Wool Market-" 
	["select1"]=>
	  string(16) "The Wool Market-" 
	[5]=>
	  string(17) "show me the money" 
	["txt1"]=>
	  string(17) "show me the money" 
	[6]=>
	  string(14) "Sale Position-" 
	["select2"]=>
	  string(14) "Sale Position-" 
	[7]=>
	  string(17) "show me the money" 
	["txt2"]=>
	  string(17) "show me the money" 
	[8]=>
	  string(12) "Merchandise-" 
	["select3"]=>
	  string(12) "Merchandise-" 
	[9]=>
	  string(17) "show me the money" 
	["txt3"]=>
	  string(17) "show me the money" 
	[10]=>
	  string(18) "Christmas Trading-" 
	["select4"]=>
	  string(18) "Christmas Trading-" 
	[11]=>
	  string(17) "show me the money" 
	["txt4"]=>
	  string(17) "show me the money" 
	[12]=>
	  string(8) "General-" 
	["select5"]=>
	  string(8) "General-" 
	[13]=>
	  string(17) "show me the money" 
	["txt5"]=>
	  string(17) "show me the money" 
	[14]=>
	  string(18) "The Cattle Market-" 
	["select6"]=>
	  string(18) "The Cattle Market-" 
	[15]=>
	  string(17) "show me the money" 
	["txt6"]=>
	  string(17) "show me the money" 
	[16]=>
	  string(14) "Some to Quote-" 
	["select7"]=>
	  string(14) "Some to Quote-" 
	[17]=>
	  string(17) "show me the money" 
	["txt7"]=>
	  string(17) "show me the money"
}

feyd | :roll: