Jump to content

[SOLVED] how to recollect the vaues of echoed table data to write to a database?


shadiadiph

Recommended Posts

Hi as I had my problem solved earlier I would like to know how to collect the data when it posts it must post the values of the form which I am posting here.

 


<table class="newsletter">
<form name="newsletter" method="post" action="submitnewsletter.php">
<tr><td colspan="2">SUBJECT</td></tr>
<tr><td colspan="2"><input type="text" name="subject" /></td></tr>
<tr><td colspan="2"><strong>CURRENTLY DISPLAYED NEWS ARTICLES</strong></td></tr>

<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc limit 20";
$i=0; 
$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><input type="checkbox" name="news'.$i.'"  value="'. $tradeaid. '"  /></td><td width="90% align="left">'. $mtitle. '</td></tr>';
$i++;
}
?>

<tr><td colspan="2">
<input name="submit" type="submit" class="button" value="Submit" />
<input name="reset" class="button" type="reset" value="Reset" />
</td>
</tr>
</form>
</table>

 

but not the articles that were checked i want to store to a database usually I use this method to write to a database

 

<?PHP
include("checkadminlogin.php");
include("../global/connection.php");



$subject     		=     stripslashes($_POST["subject"]);
$news1      		=     stripslashes($_POST["news[]"]);
$news2        	      =	stripslashes($_POST["news[]"]);
$news3		      =	stripslashes($_POST["news[]"]);
$news4		      =	stripslashes($_POST["news[]"]);
$news5			=	stripslashes($_POST["news[]"]);




		$insertsql = " insert into tblnewsletterdetails (subject, news1, news2, news3, news4, news5, dtAddedOn) values ('".addslashes($subject)."','".addslashes($news1)."','".addslashes($news2)."','".addslashes($news3)."','".addslashes($news4)."','".addslashes($news5)."','".date("y-m-d h:m:s")."')";
		$DB_site->query($insertsql);
		$accountid = mysql_insert_id();




?>


The form will post the value subject but will post a hidden amount of values from the statement name="news'.$i.'"  value="'. $tradeaid. '"  they are not know values??

Link to comment
Share on other sites

kind of not working only seems to work if i use

 

$news1      		=	stripslashes($_POST["news0"]);

 

the desired result was to be able to use something like

 

$news1      = stripslashes($_POST["news[]"]);

 

and to only be able to get the selected values from the form??

 

Link to comment
Share on other sites

I now have the following codes implemented but it only seems to post the final two news articles into the database the news list rows news1 and news2 on the submitnewsletter form even if i select articles 1 and 3 on the the form it only posts articles 2 and 3? All the other fields submit and are read fine.

 

here is the php webpage page code and the submit code i have.

 

php webpage

 

<table class="newsletter">
<form name="newsletter" method="post" action="submitnewsletter.php">
<tr><td colspan="2">SUBJECT</td></tr>
<tr><td colspan="2"><input type="text" name="subject" /></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">INTRODUCTION PARAGRAPH</td></tr>
<tr><td colspan="2"><textarea name="headerp" /></textarea></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2"><strong>CURRENTLY DISPLAYED NEWS ARTICLES</strong></td></tr>

<? 
$sql = "SELECT * FROM tblnewsdetails order by intnewsID desc limit 20";
$i=0; 
$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><input type="checkbox" name="news'.$i.'"  value="'. $mtitle. '"  /></td><td width="90% align="left">'. $mtitle. '</td></tr>';
$i++;
}
?>

<tr><td colspan="2">FOOTER PARAGRAPH</td></tr>
<tr><td colspan="2"><textarea name="footer" /></textarea></td></tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2">
<input name="submit" type="submit" class="button" value="Submit" />
<input name="reset" class="button" type="reset" value="Reset" />
</td>
</tr>
</form>
</table>

 

 

and the submit form

 

<?PHP
include("checkadminlogin.php");
include("../global/connection.php");

$new = $_GET["news.''."];
if($news!="")
{

$subject     		=     stripslashes($_POST["subject"]);
$headerp			=	stripslashes($_POST["headerp"]);
$news1      		=	stripslashes($_POST["news.''."]);
$news2        	      =	stripslashes($_POST["news.''."]);
$news3		      =	stripslashes($_POST["news.''."]);
$news4		      =	stripslashes($_POST["news.''."]);
$news5			=	stripslashes($_POST["news.''."]);
$footer   		      =	stripslashes($_POST["footer"]);

}


		$insertsql = " insert into tblnewsletterdetails (subject,headerp, news1, news2, news3, news4, news5, footer, sent, dtAddedOn) values ('".addslashes($subject)."','".addslashes($headerp)."','".addslashes($news1)."','".addslashes($news2)."','".addslashes($news3)."','".addslashes($news4)."','".addslashes($news5)."','".addslashes($footer)."','".addslashes(N)."','".date("y-m-d h:m:s")."')";
		$DB_site->query($insertsql);
		$accountid = mysql_insert_id();




?>
	<script>
		document.location.href="newsletter_view.php"
	</script>

 

 

 

Link to comment
Share on other sites

Try this please...

<?php
   
include("checkadminlogin.php");
   
include("../global/connection.php");
   

$new = $_GET["news.''."];

if($news!=" "){

$subject=mysql_real_escape_string($_POST["subject"]);
$headerp=mysql_real_escape_string($_POST["headerp"]);
$news1=mysql_real_escape_string($_POST["news.''."]);
$news2=mysql_real_escape_string($_POST["news.''."]);
$news3=mysql_real_escape_string($_POST["news.''."]);
$news4=mysql_real_escape_string($_POST["news.''."]);
$news5=mysql_real_escape_string($_POST["news.''."]);
$footer=mysql_real_escape_string($_POST["footer"]);



$insertsql = " insert into tblnewsletterdetails (subject,headerp, news1, news2, news3, news4, news5, footer, sent, dtAddedOn)
values ('$subject)','$headerp)','$news1','$news2','$news3','$news4','$news5','$footer',
'N','NOW()')";

$DB_site->query($insertsql);

$accountid = mysql_insert_id();
         
} //dont no where to stick this condition end.
?>

<script>
document.location.href="newsletter_view.php"
</script>

Link to comment
Share on other sites

$headerp=mysql_real_escape_string($_POST["headerp"]); <<why dont they all look like this.

 

echo out the variables they look strange, then show us the variables echoed please..

 

try agin

 

edited

 

<?php
   
include("checkadminlogin.php");
   
include("../global/connection.php");
   

$new = $_GET["news.''."];

if($news!=" "){

if(isset($_POST['submit'])){

$subject=mysql_real_escape_string($_POST["subject"]);
$headerp=mysql_real_escape_string($_POST["headerp"]);
$news1=mysql_real_escape_string($_POST["news.''."]);
$news2=mysql_real_escape_string($_POST["news.''."]);
$news3=mysql_real_escape_string($_POST["news.''."]);
$news4=mysql_real_escape_string($_POST["news.''."]);
$news5=mysql_real_escape_string($_POST["news.''."]);
$footer=mysql_real_escape_string($_POST["footer"]);



$insertsql = " insert into tblnewsletterdetails (subject,headerp, news1, news2, news3, news4, news5, footer, sent, dtAddedOn)
values ('$subject)','$headerp)','$news1','$news2','$news3','$news4','$news5','$footer',
'N','".date("y-m-d h:m:s")."' ";

$DB_site->query($insertsql);

}
}

$accountid = mysql_insert_id();
         
?>

<script>
document.location.href="newsletter_view.php"
</script>

Link to comment
Share on other sites

tried that wouldn't even submit this time got the following error message emailed to me

 

Database error in website.com: Invalid SQL:  insert into tblnewsletterdetails (subject,headerp, news1, news2, news3, news4, news5, footer, sent, dtAddedOn)  values ('help)','help me)','','','','','','help me please',

'N','08-12-09 03:12:18'

mysql error: 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 3 mysql error number: 1064

Date: Tuesday 09th 2008f December 2008 03:23:18 AM

Script: /secure/webadmin/submitnewsletter.php

 

 

Link to comment
Share on other sites

without $GET it returns nothing doesn't print anything to the data base but i just figured out this must be where the problem is as i just tried it with

$news = $_GET["doggydo.''."];

if($news!="")

{

 

and it still retured the same crazy writing instance of wrong article wrong column

??

Link to comment
Share on other sites

here is how the html views when i view source i just used a website to copy some news articles to test it

 

 

<table class="newsletter">

<form name="newsletter" method="post" action="submitnewsletter.php">

<input type="hidden" name="intNewsID" value="accountid" />

<tr><td colspan="2">SUBJECT</td></tr>

<tr><td colspan="2"><input type="text" name="subject" /></td></tr>

<tr><td colspan="2"> </td></tr>

<tr><td colspan="2">INTRODUCTION PARAGRAPH</td></tr>

<tr><td colspan="2"><textarea name="headerp" /></textarea></td></tr>

<tr><td colspan="2"> </td></tr>

<tr><td colspan="2"><strong>CURRENTLY DISPLAYED NEWS ARTICLES</strong></td></tr>

 

<tr><td><input type="checkbox" name="news0"  value="Mitsubishi UFJ Rises After Pricing 400 Billion Yen Share Sale"  /></td><td width="90% align="left">Mitsubishi UFJ Rises After Pricing 400 Billion Yen Share Sale</td></tr>

<tr><td><input type="checkbox" name="news1"  value="Greek Police Battle With Rioters for Third Night"  /></td><td width="90% align="left">Greek Police Battle With Rioters for Third Night</td></tr>

<tr><td><input type="checkbox" name="news2"  value="Hedge Fund Adviser Tozai to Close After Redemptions"  /></td><td width="90% align="left">Hedge Fund Adviser Tozai to Close After Redemptions</td></tr>

<tr><td><input type="checkbox" name="news3"  value="Asian Stocks Gain for Third Day, Led by Commodities, Cosco"  /></td><td width="90% align="left">Asian Stocks Gain for Third Day, Led by Commodities, Cosco</td></tr>

<tr><td><input type="checkbox" name="news4"  value="BCE Hires Second Auditor to Sway KPMG in Bid to Salvage Buyout"  /></td><td width="90% align="left">BCE Hires Second Auditor to Sway KPMG in Bid to Salvage Buyout</td></tr>

<tr><td><input type="checkbox" name="news5"  value="Asian Commodity, Shipping Stocks Rise; Commonwealth Bank Falls"  /></td><td width="90% align="left">Asian Commodity, Shipping Stocks Rise; Commonwealth Bank Falls</td></tr>

<tr><td><input type="checkbox" name="news6"  value="Oil Ends Six Days of Declines as OPEC Signals Big Output Cut"  /></td><td width="90% align="left">Oil Ends Six Days of Declines as OPEC Signals Big Output Cut</td></tr>

<tr><td><input type="checkbox" name="news7"  value="test"  /></td><td width="90% align="left">test</td></tr>

<tr><td colspan="2">FOOTER PARAGRAPH</td></tr>

<tr><td colspan="2"><textarea name="footer" /></textarea></td></tr>

<tr><td colspan="2"> </td></tr>

<tr>

<td colspan="2">

<input name="submit" type="submit" class="button" value="Submit" />

<input name="reset" class="button" type="reset" value="Reset" />

</td>

</tr>

</form>

</table>

Link to comment
Share on other sites

What I am trying to achieve is to get the five artices that will be selected on the form page to pass to the submit page and write to the database which has 5 news columns.

 

I now have them posting in the correct columns by using this.

 

php form page

 

<table class="newsletter">
<form name="newsletter" method="post" action="submitnewsletter.php">
<input type="hidden" name="intNewsID" value="accountid" />
<tr><td colspan="2">SUBJECT</td></tr>
<tr><td colspan="2"><input type="text" name="subject" /></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">INTRODUCTION PARAGRAPH</td></tr>
<tr><td colspan="2"><textarea name="headerp" /></textarea></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2"><strong>CURRENTLY DISPLAYED NEWS ARTICLES</strong></td></tr>

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

echo '<tr><td><input type="checkbox" name="news'.$i.'"  value="'. $mtitle. '"  /></td><td width="90% align="left">'. $mtitle. '</td></tr>';
$i++;
}
?>

<tr><td colspan="2">FOOTER PARAGRAPH</td></tr>
<tr><td colspan="2"><textarea name="footer" /></textarea></td></tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2">
<input name="submit" type="submit" class="button" value="Submit" />
<input name="reset" class="button" type="reset" value="Reset" />
</td>
</tr>
</form>
</table>

 

 

and the submit code which is where the problem is when it is received as the name values are hard to determine.

 

<?PHP
include("checkadminlogin.php");
include("../global/connection.php");





$subject     		=     stripslashes($_POST["subject"]);
$headerp			=	stripslashes($_POST["headerp"]);
$article0      		=	($HTTP_POST_VARS["news0"]);
$article1        	      =	($HTTP_POST_VARS["news1"]);
$article2		      =	($HTTP_POST_VARS["news2"]);
$article3		      =	($HTTP_POST_VARS["news3"]);
$article4			=	($HTTP_POST_VARS["news4"]);
$footer   		      =	stripslashes($_POST["footer"]);
$accountid   	      =	stripslashes($_POST["intNewsID"]);




		$insertsql = " insert into tblnewsletterdetails (subject,headerp, news1, news2, news3, news4, news5, footer, sent, dtAddedOn) values ('".addslashes($subject)."','".addslashes($headerp)."','".addslashes($article0)."','".addslashes($article1)."','".addslashes($article2)."','".addslashes($article3)."','".addslashes($article4)."','".addslashes($footer)."','".addslashes('N')."','".date("y-m-d h:m:s")."')";
		$DB_site->query($insertsql);
		$accountid = mysql_insert_id();



?>
<script>
document.location.href="newsletter_view.php"
</script> 

 

 

but when i check artices 1, 3 ,5, 7, 9 i only get 1 3 5 posted in the news columns as article1 is named news0 on the form.

So the passed name vales are news0, news2, news4,news7 and news9.

 

What I am tring to achieve is that only the 5 selected articles on the form are posted.

which means i need to find away to automatically renumber ($HTTP_POST_VARS["news0"]);

this part so only the values carried are posted.

 

Or find a way to rename the numbers before they get to this submit form??

 

does that make any sense.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.