...

View Full Version : $_POST not working!



rockinik
04-02-2010, 04:36 AM
Hey

My usageResult.php echos the $_POST('cat') and it doesnt work! Its just blank! I really cant understand why!!! PLEASE HELP!

Here is the usageForm.php.

Thanks SO SO SO SO MUCH!



<html>
<head>
<title>Usage Tracking</title>
<SCRIPT language=JavaScript>
function reload(form) {
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='UsageForm.php?cat=' + val ;
}
</SCRIPT>
</head>

<body>
<h2>Usage Tracking</h2>
<form action="UsageResult.php" method="post">
Category :
<select name="cat" onchange="reload(this.form)">
<option value="">-- All --</option>

<?php
$cat=$_GET['cat'];

$connect = mysql_connect('localhost', 'root', '');
if(!$connect) {
die('Could not connect: '.mysql_error());
}
mysql_select_db('phase3');

$result = mysql_query('
Select distinct description
from category
');

while($row = mysql_fetch_row($result)) {
print "<option value = \"$row[0]\" > $row[0] </option>";
}

mysql_close($connect);

?>

</select>

</br>
News Title :
<select name="newsTitle">


<?php
$connect = mysql_connect('localhost', 'root', '');
if(!$connect) {
die('Could not connect: '.mysql_error());
}
mysql_select_db('phase3');

if(!isset($cat)) {
$result = mysql_query("
Select distinct title
from news_article
");
} else {
$result = mysql_query("
select na.title
from news_article na,category c
where na.news_id = c.highlight_news_id
and c.description = '$cat'

union

select na.title
from news_article na,news_category nc,category c
where na.news_id = nc.news_id
and nc.category_id = c.category_id
and c.description = '$cat'
");
}


while($row = mysql_fetch_row($result)) {
print "<option value = \"$row[0]\" > $row[0] </option>";
}

mysql_close($connect);

?>

<input type="submit" value="Submit"/>
</form>



</body>
</html>

er4o
04-02-2010, 04:42 AM
Just test it with only this code inside UsageResult.php


echo $_POST['cat'];

You may try to change usageResult.php to UsageResult.php

rockinik
04-02-2010, 04:43 AM
Yes... :( still doesnt work!

er4o
04-02-2010, 04:50 AM
Edited my post ^^

rockinik
04-02-2010, 04:58 AM
Yeah thats exactly what i am doing...
and the file is named UsageResult.php

I made a typo earlier..
Thanks. But its still not working. I've been on this for three hours now!!

abduraooft
04-02-2010, 10:25 AM
My usageResult.php echos the $_POST('cat') and it doesnt work! Its just blank! I really cant understand why!!! PLEASE HELP!Where's the code in usageResult.php?

rockinik
04-02-2010, 06:57 PM
Its simply:



<html>
<body>
<?php
echo $_POST['cat'];
?>
</body>
</html>

skywalker2208
04-02-2010, 08:46 PM
To me it looks like you need to use $_GET because in the reload function you are placing the value in the url.

rockinik
04-03-2010, 04:25 PM
As in?
I use echo $_GET('cat') in my UsageResult.php file and keep everything else the same?

If i do so, I get this error
Notice: Undefined index: cat in C:\wamp\www\Project\UsageResult.php on line 4

This error disappears when i change echo $_GET('cat') to echo $_POST('cat')

echo $_POST('cat') shows a blank.. Nothing appears. I can see the cat variable in the address bar though..
Wish i could just grab it from there and put in on the webpage. lol.

abduraooft
04-03-2010, 04:38 PM
Here is the usageForm.php. [...]

while($row = mysql_fetch_row($result)) {
print "<option value = \"$row[0]\" > $row[0] </option>";
}
Check the parsed html output of your page from browser's view source option and make sure that the <option> tags are getting the right values from DB.

rockinik
04-03-2010, 07:12 PM
Yupp.. Everything is perfect. See Below:



<option value = "World" > World </option><option value = "Singapore" > Singapore </option><option value = "Asia-Pacific" > Asia-Pacific </option><option value = "Business" > Business </option><option value = "Sports" > Sports </option><option value = "Technology" > Technology </option><option value = "Entertainment" > Entertainment </option><option value = "Singapore News" > Singapore News </option><option value = "Business News" > Business News </option><option value = "Health" > Health </option><option value = "Politics" > Politics </option><option value = "Diet and Nutrition" > Diet and Nutrition </option><option value = "Disasters" > Disasters </option>


This is copy pasted from the source code.

OMG! I hope i can figure this out soon. My submission is in 24 hours time!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum