Re: Multiline data Insert - Resolved

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mike,

Resolved it. Well, actually your code is a 'for' rather than a 'while' which
I realized a bit late. :-) And there were two fullstops that needed to be a
comma. Now it works.

Thanks a lot for your guidance.

Alp

"Alp" <alp.bekisoglu@xxxxxxxxxxxxxx> wrote in message
news:20050203051611.90151.qmail@xxxxxxxxxxxxxxxx
> Hi Mike,
>
> PHP returns a parse error indicating the line number for the while (.....)
!
> Code now is:
> 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;
>   }
>  while ($c=0;$c<count($_POST['tourid']):$c++) {
>   if ($_POST['tourid'][$c]!="" && $_POST['dayno'][$c]!="" &&
> $_POST['fromto'][$c]!="" && $_POST['bld'][$c]!="" &&
> $_POST['descrip'][$c]!=""){
>    $sql = "INSERT INTO tour_details ('tour_id'. 'dayno', 'fromto', 'bld',
> 'descrip') VALUES ('{$_POST['tourid'][$c]}'. '{$_POST['dayno'][$c]}',
> '{$_POST['fromto'][$c]}', '{$_POST['bld'][$c]}',
> '{$_POST['descrip'][$c]}')\n";
>   }
>   if (! mysql_query($sql, $link))
>    {
>    $dberror = mysql_error();
>    return false;
>    }
>  }
>  $lastinsertid = mysql_insert_id();
>
>  return true;
>  }
>
> Actually the form is posted to itself. What could be the problem now?
>
> Thanks in advance.
>
> Alp
>
> "Mike Smith" <mikeosmith@xxxxxxxxx> wrote in message
> news:d46325db050202033225f24987@xxxxxxxxxxxxxxxxx
> > > 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";
> >     }
> > }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux