PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
session_start();
require "connect.php";
$title = $_GET['title'];
$startdate = $_GET['startdate'];
$query = "insert into project values (0,'".$title."','".$startdate."')";
$result = mysql_query($query, $connection)
or die(mysql_error());
$projid = mysql_insert_id($connection);
foreach($_SESSION['group'] as $key => $person){
$query = "insert into member values(".$_SESSION['group'][$key]['pid'].",".$projid.",'".$_SESSION['group'][$key]['job']."')";
$result = mysql_query($query, $connection)
or die(mysql_error());
}
unset($_SESSION['group']);
header("Location:viewgroups.php");
exit();
?>
There is a problem with the > in the for loop which automatically matches the <?php tag and does not allow any of the code following it to be used. How can i get round this problem?
There is a problem with the > in the for loop which automatically matches the <?php tag and does not allow any of the code following it to be used. How can i get round this problem?
[/quote]
I don't see how using the standard => syntax in the foreach causes a problem but I do see a problem with your query.
You are missing single quotes around all but the last of your values. Why doesn't it work, do you get an error or could you show some output?
EDIT: $_SESSION['group'] is an array itself is it?
Last edited by Chris Corbyn on Wed Mar 16, 2005 7:38 am, edited 1 time in total.
The column names are optional if you are providing values for all columns and in the same order as the columns exist in the db. I do like to provide them for code readability, though.