Reply to Re: [PHP] Multiline data Insert Into table from a generated form?

Your name:

Reply:


Posted by Alp on 10/04/22 11:07

Thank you Mike for your quick reply. I will try to incorporate it into the
function I'm using and let you know the result. The function code is also
given below.

Alp

function add_to_database( $tourid, $dayno, $fromto, $bld, $descrip,
&$dberror)
{
//user connection section--begin
$username="root";
$password="";
$database="nazardane";
$link = mysql_pconnect("localhost", $username, $password);
if ( ! $link )
{
$dberror = "Couldn't connect to MySQL server";
return false;
}
if ( ! mysql_select_db( $database, $link))
{
$dberror = mysql_error();
return false;
}
$sql = "INSERT INTO tour_details ( tour_id, dayno, fromto, bld, descrip )
VALUES ( '$tourid', '$dayno', '$fromto', '$bld', '$descrip' ) )";
if (! mysql_query($sql, $link))
{
$dberror = mysql_error();
return false;
}

return true;
}



"Mike Smith" <mikeosmith@gmail.com> wrote in message
news:d46325db050202033225f24987@mail.gmail.com...
> > Code:
> > print '<table width="545" border="0" cellspacing="0" cellpadding="0"
> > align="center"><tr>';
> > print '<form action="test1.php" method="POST">';
> > $i = 1;
> > while ($i <= $tour_days) {
> > print '<input type="hidden" name="tourdays" value="'.$tour_days.'">';
> > print '<input type="hidden" name="tourid'.$i.'"
value="'.$tour_id.'">';
> > $days = ("Day&nbsp;0".$i);
> > print $days;
> > print '<input type="hidden" name="dayno'.$i.'" value="'.$days.'">';
> > print '</td>';
> > print '<input type="text" name="fromto'.$i.'" size="50"></td>';
> > print '<input type="text" name="bld'.$i.'" size="10"></td></tr>';
> > print '<tr><td colspan="3">';
> > print '<textarea name="descrip'.$i.'" rows="5" cols="80"
> > wrap="virtual"></textarea></td></tr>';
> > $i++;
> > }
> > print '</table>';
> > print "<input type=\"submit\" value=\"submit!\">\n</form>\n";
>
> Change the field names to arrays (i.e. "tourid".$i becomes tourid[]
>
> When you POST loop through the array:
>
> while($c=0;$c<count($_POST['tourid']):$c++){
> If($_POST['tourid'][$c]!=""...){
> $sql = "INSERT INTO reservations ('tourid'...) VALUES
> ('{$_POST['tourid'][$c]}'...)\n";
> }
> }

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация