PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #16  
Old June 26th, 2002, 09:29 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
RE: Variables giving me trouble!

Is this right?

<?php
// Keep in mind you aleady know what the variable names are.
if(isset($HTTP_POST_VARS['$id'])){
$id = $HTTP_POST_VARS['$id'];
}

$db = mysql_connect("localhost", "username", "password");
mysql_select_db("maraquita",$db);

$sql="SELECT * FROM variables";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;


echo "<ol>";

while ($num >= $cur) {

$row = mysql_fetch_array($result);

$id = $row["id"];
$title = $row["title"];
$content = $row["content"];

echo "<li>Id = $id<br>";
echo "Title of page = $title<br>";
echo "Content = $content</li>";

$cur++;
}

echo "</ol>";

?>

I type in the URL variables.php?id=1 and it comes up with nothing, but if I add 'WHERE id='$id'" to the SELECT line ... it doesn't work .. but it shows all the rows if i remove it. Why? Any ideas?

Reply With Quote
  #17  
Old June 26th, 2002, 09:40 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Variables giving me trouble!

You _CANNOT_ type that URL into the browser, as you pointed out it will _NOT_ work that way. You have to access that from a form that is using the "POST" method.

If you want to be able to access that script by typing it into the location bar of you browser, then you need to change $HTTP_POST_VARS to $HTTP_GET_VARS.

If you put the "WHERE" back into your query string and access the script via a form with method set to POST it will work as you had intended it to.

The reason why it shows the whole table is because $id never gets set since it is not a POST_VAR.

I hope that makes sense.

Reply With Quote
  #18  
Old June 26th, 2002, 09:48 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
Matt!

Matt,

What's your code for your database driven site?

EvilvE, any ideas, mine just don't seem to work. Is this as you said?

<?php
// Keep in mind you aleady know what the variable names are.
if(isset($HTTP_GET_VARS['$id'])){
$id = $HTTP_GET_VARS['$id'];
}

$db = mysql_connect("localhost", "username", "password");
mysql_select_db("maraquita",$db);

$sql="SELECT * FROM variables WHERE id='$id'";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;


echo "<ol>";

while ($num >= $cur) {

$row = mysql_fetch_array($result);

$id = $row["id"];
$title = $row["title"];
$content = $row["content"];

echo "<li>Id = $id<br>";
echo "Title of page = $title<br>";
echo "Content = $content</li>";

$cur++;
}

echo "</ol>";

?>

Reply With Quote
  #19  
Old June 26th, 2002, 09:48 AM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
Re: Variables giving me trouble!

Matt,

What's your code for your database driven site?

EvilvE, any ideas, mine just don't seem to work. Is this as you said?

<?php
// Keep in mind you aleady know what the variable names are.
if(isset($HTTP_GET_VARS['$id'])){
$id = $HTTP_GET_VARS['$id'];
}

$db = mysql_connect("localhost", "username", "password");
mysql_select_db("maraquita",$db);

$sql="SELECT * FROM variables WHERE id='$id'";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);
$cur = 1;


echo "<ol>";

while ($num >= $cur) {

$row = mysql_fetch_array($result);

$id = $row["id"];
$title = $row["title"];
$content = $row["content"];

echo "<li>Id = $id<br>";
echo "Title of page = $title<br>";
echo "Content = $content</li>";

$cur++;
}

echo "</ol>";

?>

Reply With Quote
  #20  
Old June 26th, 2002, 09:55 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Variables giving me trouble!

Replace:
$sql="SELECT * FROM variables WHERE id='$id'";

with:
$sql="SELECT * FROM variables WHERE id='".$id."'";

Reply With Quote
  #21  
Old June 26th, 2002, 12:54 PM
lgetreu lgetreu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, VIC, Australia
Posts: 56 lgetreu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to lgetreu
RE: Variables giving me trouble!

THANKS SO MUCH Mr. EvilvE!!!!

I have been trying to do that for the last god knows how many weeks!

Thanks again.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Variables giving me trouble!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway