954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

post submitting values not working?

My earlier post works ok now to display I have been working on how to transfer the info to be displayed on another page. I can't get it to work in theory i thik it should be working can anyone give me an idea what I have done wrong.

on the display page I call data from the data base it explodes on echo and displays 9 news headlines. the ["newsTit"] is the whole news article headline ["newsMn"] is the main news article text.

here is the code i have put on the display page.

<p>
<table cellspacing="0" cellpadding="2" border="0">
<form name="news" method="post" action="news.php">

<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc"; 
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$tradeaid = $row["intnewsID"];
$accountid = $row["intAccountID"];
$stitle = $row["newsshTit"];
$mtitle = $row["newsTit"];
$nmain = $row["newsMn"];
$updated = $row["dtAddedOn"];

echo'<input name="tradeaid" type="hidden" id="tradeaid" value="<?=tradeaid?>">';
echo'<input name="mtitle" type="hidden" id="mtitle" value="<?=mtitle?>">';
echo'<input name="nmain" type="hidden" id="nmain" value="<?=nmain?>">';
echo '<tr><td width="90% align=left"><a onclick="submit();">'. $stitle. '</s></td></tr>';


}
?>

</table>
</form>


</p>


displays ok it also goes to the news.php when the article is clicked on but when the news.php opens it remain blank here is the code which i have used on many other pages and it works and displays posted data ok but not in this case why???

<? 
session_start();
error_reporting(PCT);
include("secure/global/connection.php");

$tradeaid		=   stripslashes($_POST["tradeaid"]);
$mtitle		=	stripslashes($_POST["mtitle"]);
$nmain		      =	stripslashes($_POST["nmain"]);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>

<body>

<p><b><?=$ntitle?></b></p>
<p><?=$nmain?></p>

</body>
</html>
shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 
echo''; echo''; echo'';


missing $ in the values.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

ok i tried that made no change still doesn't work ti now looks like this

<p>
<table cellspacing="0" cellpadding="2" border="0">
<form name="news" method="post" action="news.php">

<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc"; 
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$tradeaid = $row["intnewsID"];
$accountid = $row["intAccountID"];
$stitle = $row["newsshTit"];
$mtitle = $row["newsTit"];
$nmain = $row["newsMn"];
$updated = $row["dtAddedOn"];

echo'<input name="tradeaid" type="hidden" id="tradeaid" value="<?=$tradeaid?>">';
echo'<input name="mtitle" type="hidden" id="mtitle" value="<?=$mtitle?>">';
echo'<input name="nmain" type="hidden" id="nmain" value="<?=$nmain?>">';
echo '<tr><td width="90% align=left"><a onclick="submit();">'. $stitle. '</a></td></tr>';


}
?>

</table>
</form>


</p>


second page is still the same and also doesn't work

<? 
session_start();
error_reporting(PCT);
include("secure/global/connection.php");

$tradeaid = stripslashes($_POST["tradeaid"]);
$mtitle = stripslashes($_POST["mtitle"]);
$nmain = stripslashes($_POST["nmain"]);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>

<body>

<p><b><?=$ntitle?></b></p>
<p><?=$nmain?></p>

</body>
</html>
shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Try this.

echo'<input name="tradeaid" type="hidden" id="tradeaid" value="'.$tradeaid.'">';
echo'<input name="mtitle" type="hidden" id="mtitle" value="'.<$mtitle.'">';
echo'<input name="nmain" type="hidden" id="nmain" value="'.nmain.'">';
echo '<tr><td width="90% align=left"><a onclick="submit();">'. $stitle. '</s></td></tr>';


I think its a bad practice to use <?=$varname instead of <?php echo $varname; ?>

Edit: And please use code tags while posting your code. It really helps.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

mmm tried that everything in the echo displays everything all the news articles not just the headlines like before on the 1st page doesn't even submit to the news.php using that.
I think my submit is in the wrong place as when it did submit it is trying to submit all the echos and can't distinguish one of them so displays nothing????

shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

i will try this with the script in [] tags i think that is what you meant.

I have almost solved it the following works in that it diplays a news ad headline and main text on the news.php just as i want it to the problem is it does not display the news ad i click on or want to display it always displays the last one in the list.

here is my new revised code on the main page it does not seem to seperate the 9 displayed artices and will always link to the last one if i change the desc to asc it displays the first one not quite what i wanted but almost i want it to post the one i click on any ideas?

<table cellspacing="0" cellpadding="2" border="0">
<form name="news" method="post" action="news.php">

<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc"; 
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$tradeaid = $row["intnewsID"];
$accountid = $row["intAccountID"];
$stitle = $row["newsshTit"];
$mtitle = $row["newsTit"];
$nmain = $row["newsMn"];
$updated = $row["dtAddedOn"];
?>


<?
echo '<tr><td width="90% align=left"><a onclick="submit();">'. $stitle. '</a></td></tr>';
}
?>

<input name="mtitle" type="hidden" id="mtitle" value="<?=$mtitle?>">
<input name="nmain" type="hidden" id="nmain" value="<?=$nmain?>">
</table>
</form>

When i change desc to asc it stops showing headlines it shows headlines and whole news articles?

shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

got this script to a state where when i hover over each headline it gives me the links as having id numbers associated eample news.php?id=4 for the 4th headline id=5 for the 5th now I need to know how to carry the data to the news.php

here is my new script

<table cellspacing="0" cellpadding="2" border="0">


<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc limit 9"; 
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$tradeaid = $row["intnewsID"];
$accountid = $row["intAccountID"];
$stitle = $row["newsshTit"];
$mtitle = $row["newsTit"];
$nmain = $row["newsMn"];
$updated = $row["dtAddedOn"];
?>


<?

echo '<tr><td width="90% align=left"><a href=news.php?id='. $tradeaid. '>'. $stitle. '</a></td></tr>';
echo '<input name="mtitle" type="hidden" id="mtitle" value="<?=$mtitle?>">';
echo '<input name="nmain" type="hidden" id="nmain" value="<?=$nmain?>">';
}
?>


</table>
shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

In news.php, request id's value and fetch the data from the table for that particular id.
For example, news.php?id=4

//news.php
//db connection
$id = mysql_real_escape_string($_GET['id']);
$query = "select * from newstable where id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print_r($row); //display the news for id = 4
?>
nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

hi do i put that i the head or body as i keep gettig this error message

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E: with

<? 
session_start();
error_reporting(EWO);
include("secure/global/connection.php");

$id = mysql_real_escape_string($_GET['id']);
$query = "select * from tblnewsdetails where id = '$id'"; 
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print_r($row); //display the news for id = 4
?>
shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Change the table name (and column name) !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

almost there only problem is it displays like this???

Array ( [0] => 7 [intnewsID] => 7 [1] => [intAccountID] => [2] => Ecuador offers to buy out oil companies [newsshTit] => Ecuador offers to buy out oil companies [3] => Ecuador offers to buy out oil companies [newsTit] => Ecuador offers to buy out oil companies [4] => Sat May 17, 7:32 PM ET 
President Rafael Correa says Ecuador wants to buy out private oil companies unwilling to negotiate new deals with his government.
Correa has asked companies now suing over an October decree that slashed their share of windfall oil profits to 1 percent to drop their lawsuits.
Ecuador on Friday offered to boost those companies' share of soaring windfall profits to 30 percent. If companies aren't happy with that offer, Correa says his government will buy their assets at "a fair price."
France's Perenco Gabon SA, U.S.-based Murphy Oil Corporation and ConocoPhillips-subsidiary Burlington Resources are among those to file claims against Ecuador.
Windfall profits are unexpected earnings on oil sold for more than the price fixed in a company's contract.
[newsMn] => Sat May 17, 7:32 PM ET 
President Rafael Correa says Ecuador wants to buy out private oil companies unwilling to negotiate new deals with his government.
Correa has asked companies now suing over an October decree that slashed their share of windfall oil profits to 1 percent to drop their lawsuits.
Ecuador on Friday offered to boost those companies' share of soaring windfall profits to 30 percent. If companies aren't happy with that offer, Correa says his government will buy their assets at "a fair price."
France's Perenco Gabon SA, U.S.-based Murphy Oil Corporation and ConocoPhillips-subsidiary Burlington Resources are among those to file claims against Ecuador.
Windfall profits are unexpected earnings on oil sold for more than the price fixed in a company's contract.
[5] => 2008-05-18 [dtAddedOn] => 2008-05-18 )
shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Yes. It displays everything it fetches for that particular id. You can limit your output by choosing what to print. As you can see, $row is an array. $row['intnewsID'] will have 7, $row['newsTit'] will have "Ecuador offers to buy out oil companies" and so on.. Check this out.
http://nl3.php.net/mysql_fetch_array
This is how you can print only newsTit value.

//news.php
//db connection
$id = mysql_real_escape_string($_GET['id']);
$query = "select * from newstable where id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print $row['newsTit'];
?>
nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

cheers awsome thanx 4 the assistace

shadiadiph
Junior Poster
119 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

You are welcome :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You