SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 48
-
Jan 5, 2006, 12:46 #1
GET value and execute it as query
my opolagies if this is considered as a dublicated thread.
Q is this code is to get the category id from a table and display it
as a link.
PHP Code:while ($row = mysql_fetch_assoc($result)) {
echo '<a href="Displaycategory.php?category_id='
. '">'
. $row['category_id']
. '</a>' . '<br />';
where the product id = Whats in GET
PHP Code:$result = mysql_query("select * from products where category_id = '". $_GET['category_id'] ."'");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result) != 0)
{
while($rows = mysql_fetch_assoc($result)) {
echo $rows['description'] .'<br />';
}
}
else
{
echo "no results";
}
from the table and display it as a link.
but when its clicked it execute the secound script but it does nothing
-there are few records in the tables.
is this the write method to use it as a query.?
help please.
-
Jan 5, 2006, 13:01 #2
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:while ($row = mysql_fetch_assoc($result)) { $category_id = ['category_id']; $title = ['category_title']; $output .= "<a href=\"Displaycategory.php?category_id=$category_id\">$title" ; } echo $output;
intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 13:08 #3
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Have you tried to echo $_GET["category_id"]?
Try also to dump the results of the query..-- Jelena --
-
Jan 5, 2006, 13:14 #4
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In some cases, php might be generating an error from a problem in the second script, displaying the error messages in white text on a white background. Try running clicking on the link and press CTL+A, select all on the page and see if their are any error messages. This white on white effect doesn't occur on my local apache server, but, does occur on my hosted server.
intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 13:27 #5
i get this error
Parse error: parse error, unexpected '[' in
am trying.
after modifing the code all i get is the error above.
-
Jan 5, 2006, 13:31 #6
sorry the error is on this line
PHP Code:while ($row = mysql_fetch_assoc($result)) {
--error--------------$category_id = ['category_id'];
$title = ['category_title'];
$output .= "<a href=\"Displaycategory.php?category_id=$category_id\">$title" ;
}
-
Jan 5, 2006, 13:38 #7
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by hisham777
More than likely, if your getting a parse error your probably leaving out ), }, ; somewhere.intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 13:57 #8
i get this massge
Resource id #2
-
Jan 5, 2006, 14:05 #9
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How about pm me your code.
intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 14:11 #10
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why not just use mysql_fetch_array()?
Field names returned mysql_fetch_assoc() are case-sensitive.intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 14:37 #11
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Run this simplified script...
PHP Code:$category_id = $_GET['category_id'];
echo $category_id;
$sql = "select * from products where category_id = ". $category_id;
echo $sql;
$query = mysql_query($sql) or die(mysql_error());
while($rows = mysql_fetch_assoc($query)) {
echo $rows['description'] .'<br />';
}
Spike
-
Jan 5, 2006, 15:09 #12
spikeZ after using the code i get this massge
select * from products where category_id = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
-
Jan 5, 2006, 15:18 #13
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Do you not get an echo from the $category_id?
-
Jan 5, 2006, 15:21 #14
no nothing the html source
</head>
<body>
select * from products where category_id = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
-
Jan 5, 2006, 15:22 #15
is it something have to do with global variable off or on .?
am using
php 5.0
mySQL 5.0
on IIS
-
Jan 5, 2006, 15:27 #16
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Stick in an :
exit;
right after echo $sql; in spikeZ code.
If $category_id is null your going to have an incomplete $sql statement which is going to generate the MySQL error before the value of your $sql is displayed on the screen.intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 15:57 #17
bit confused holmescreek
please exicuse my hembile knolewage of php & mysql
what do you mean
-
Jan 5, 2006, 16:10 #18
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:$category_id = $_GET['category_id']; $sql = "select * from products where category_id = ". $category_id; // --- debug echo "category_id : $category_id" . "<br>"; echo "sql statement : $sql"; exit; // --- end debug $query = mysql_query($sql) or die(mysql_error()); while($rows = mysql_fetch_assoc($query)) { echo $rows['description'] .'<br />'; }
intragenesis, llc professional web & graphic design
-
Jan 5, 2006, 16:21 #19
i get this
category_id :
sql statement : select * from products where category_id =
i think am to tired i been a wake 26 hours straight.
i need some rest
ill go to sleep.
thanks Spikez and holmescreek
-
Jan 5, 2006, 18:01 #20
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your on the right track! Notice your output above? category_id has no value. The value category_id is not being passed to your script correctly.
Try taking this code and save it as test.php and load it in your browser. The first time you load test.php, it will tell you that $category_id is not set, then provides you a link that sets category_id to a random number.
If this code fails to work then it is probably a setting in your php.ini file :
Code:<?php $_GET['category_id']; if($category_id){ echo "category_id : $category_id <br><br>"; } else { echo "category_id is not set...<br><br>"; } $some_value = rand(1,999); echo "<a href=\"test.php?category_id=$some_value\">click here to set category_id to $some_value</a>"; ?>
intragenesis, llc professional web & graphic design
-
Jan 6, 2006, 08:42 #21
holmescreek i tryed the code
it gives me this out put
category_id is not set...
click here to set category_id to 848
html source
<body>
category_id is not set...<br><br><a href="test.php?category_id=639">click here to set category_id to 639</a>
</body>
it means that there is no variable past to GET
my php.ini
is standard exept for the extention file i have changed it to point
to a folder were all my DLL files there
i installed the manual install
!!! ?????
-
Jan 6, 2006, 11:52 #22
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, run the code I gave you category_id shouldn't be set the first time, but if you click on the link each time, it should set category_id to some random value.
After clicking the link, if category_id is still not set let me know. $_POST is a php superglobal.
You stated your using PHP 5.0, I noted a bug in the change log where $_POST was not working in specific versions of PHP 5 : http://bugs.php.net/bug.php?id=32109
--- so try upgrading to the newest version of PHP 5.xintragenesis, llc professional web & graphic design
-
Jan 6, 2006, 11:58 #23
hi holmescreek
i tryed your code
i did click on the link but the variable is not set!!
am using php 5.1.1
and
mysql-essential-5.0.18
-
Jan 6, 2006, 12:23 #24
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by holmescreek
You might have to re-install php 5.1.1 is the only thing I can think of if this code doesn't work...if your running IIS, then it could be an issue with it, dunno, I run Apache.
Maybe try posting my code in a new thread and asking someone with your same php version, server etc, to test it. If it runs ok, then you know its got to be your install.intragenesis, llc professional web & graphic design
-
Jan 6, 2006, 12:41 #25
- Join Date
- Mar 2001
- Location
- Northwest Florida
- Posts
- 1,707
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Another shot, check the post_max_size directive (even though its typicall used to restrict the size uploded files) in your php.ini. If this is like 0, then $_POST will return empty.
intragenesis, llc professional web & graphic design
Bookmarks