DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   post submitting values not working? (http://www.daniweb.com/forums/thread124772.html)

shadiadiph May 18th, 2008 6:46 am
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>

nav33n May 18th, 2008 6:53 am
Re: post submitting values not working?
 
Quote:

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?>">';

missing $ in the values.

shadiadiph May 18th, 2008 7:35 am
Re: post submitting values not working?
 
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>

nav33n May 18th, 2008 9:48 am
Re: post submitting values not working?
 
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.

shadiadiph May 18th, 2008 10:04 am
Re: post submitting values not working?
 
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 May 18th, 2008 10:23 am
Re: post submitting values not working?
 
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 May 19th, 2008 9:16 am
Re: post submitting values not working?
 
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>

nav33n May 19th, 2008 9:35 am
Re: post submitting values not working?
 
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
?>

shadiadiph May 19th, 2008 10:03 am
Re: post submitting values not working?
 
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
?>

nav33n May 19th, 2008 10:05 am
Re: post submitting values not working?
 
Change the table name (and column name) !


All times are GMT -4. The time now is 5:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC