Hi folks,
I have this form which is supposed to collect exhibition info, artists, etc. It works fine except that it don't insert the first name in the 'artist' and 'curator' tables. If I tries to insert three names in each field it inserts no. 2 and 3 together with all the exhibit id's.
It looks i.e. like this in the table:
id - name - exhibitid
(6) - text2 - 22
(7) - text3 - 22
(8) - [blank] - 22
Here is my form code:
This is the add fields javascript:PHP Code:<?php include 'accesscontrol.php'; ?>
<!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">
<head>
<title>Legg til en utstilling</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="addtwofields.js"></script>
<script type="text/javascript" src="addtwofields2.js"></script>
<script type="text/javascript" src="CalendarPopup.js"></script>
</head>
<body>
<?php
if (isset($_POST['title'])):
// En utstilling har blitt lagt til
// via denne formen.
$r = mysql_query("SHOW TABLE STATUS LIKE 'exhibit' ");
$row = mysql_fetch_array($r);
$Auto_increment = $row['Auto_increment'];
mysql_free_result($r);
$exid = $Auto_increment;
$title = $_POST['title'];
$start = $_POST['start_date'];
$end = $_POST['end_date'];
$sql = "INSERT INTO exhibit SET
title='$title',
start_date='$start',
end_date='$end',
date=LOCALTIMESTAMP(),
galleryid='$gid'";
if (@mysql_query($sql)) {
echo '<p>En utstilling er lagt til</p>';
} else {
exit('<p>Feil ved innlegging av utstilling: ' . mysql_error() . '</p>');
}
if(count($_POST))
{
$len = count($_POST['aname']);
for ($i=1; $i < $len; $i++)
{
$aname = $_POST['aname'][$i];
$sql2 = "INSERT INTO artist SET
aname='$aname',
exhibitid='$exid'";
if (@mysql_query($sql2)) {
echo '<p>En kunstner er lagt til</p>';
} else {
exit('<p>Feil ved innlegging av kunstner: ' . mysql_error() . '</p>');
}
}
}
if(count($_POST))
{
$len = count($_POST['cname']);
for ($i=1; $i < $len; $i++)
{
$cname = $_POST['cname'][$i];
$sql3 = "INSERT INTO curator SET
cname='$cname',
exhibitid='$exid'";
if (@mysql_query($sql3)) {
echo '<p>En kurator er lagt til</p>';
} else {
exit('<p>Feil ved innlegging av kurator: ' . mysql_error() . '</p>');
}
}
}
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Legg til en ny utstilling</a></p>
<p><a href="exhibitionlist.php">Tilbake til utstillingsoversikten</a></p>
<?php
else: // Allow the user to enter a new exhibition
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><b>Utstillingstittel:</b><br />
<textarea name="title" rows="2" cols="60">
</textarea></p>
<p><SCRIPT LANGUAGE="JavaScript" ID="js2">
var cal2 = new CalendarPopup();
cal2.showYearNavigation();
</SCRIPT>
<b>Startdato</b><br />
<INPUT TYPE="text" name="start_date" value="" size="25">
<A HREF="#" onClick="cal2.select(document.forms[0].start_date,'anchor2','yyyy-MM-dd'); return false;" TITLE="cal2.select(document.forms[0].start_date,'anchor2','yyyy-MM-dd'); return false;" NAME="anchor2" ID="anchor2">velg</A>
</p>
<p><SCRIPT LANGUAGE="JavaScript" ID="js2">
var cal2 = new CalendarPopup();
cal2.showYearNavigation();
</SCRIPT>
<b>Sluttdato</b><br />
<INPUT TYPE="text" name="end_date" value="" size="25">
<A HREF="#" onClick="cal2.select(document.forms[0].end_date,'anchor2','yyyy-MM-dd'); return false;" TITLE="cal2.select(document.forms[0].end_date,'anchor2','yyyy-MM-dd'); return false;" NAME="anchor2" ID="anchor2">velg</A>
</p>
<div id="newlink">
<div>
<b>Kunstner:</b>
<input type="text" name="aname[]" size="60"><br/>
<input type="hidden" name="exhibitid[]" value="<?php echo "$exid"; ?>">
</div>
</div>
<p id="addnew">
<a href="javascript:new_link()">Legg til kunstner</a>
</p>
<!-- Template -->
<div id="newlinktpl" style="display:none">
<div>
<b>Kunstner:</b> <input type="text" name="aname[]" size="60"><br/>
<input type="hidden" name="exhibitid[]" value="<?php echo "$exid"; ?>">
</div>
</div>
<div id="newlink2">
<div>
<b>Kurator:</b>
<input type="text" name="cname[]" size="60"><br/>
<input type="hidden" name="exhibitid[]" value="<?php echo "$exid"; ?>">
</div>
</div>
<p id="addnew">
<a href="javascript:new_link2()">Legg til kurator</a>
</p>
<!-- Template -->
<div id="newlinktpl2" style="display:none">
<div>
<b>Kurator:</b> <input type="text" name="cname[]" size="60"><br/>
<input type="hidden" name="exhibitid[]" value="<?php echo "$exid"; ?>">
</div>
</div>
<input type="submit" value="LEGG TIL UTSTILLING" />
</form>
<?php endif; ?>
</body>
</html>
Appriciate any help.Code:var ct = 1; function new_link() { ct++; var div1 = document.createElement('div'); div1.id = ct; // link to delete extended form elements var delLink = '<div style="text-align:right;margin-right:65px"><a href="javascript:delIt('+ ct +')">Slett</a></div>'; div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink; document.getElementById('newlink').appendChild(div1); } // function to delete the newly added set of elements function delIt(eleId) { d = document; var ele = d.getElementById(eleId); var parentEle = d.getElementById('newlink'); parentEle.removeChild(ele); }
Thanks!










Bookmarks