ChristinaMandle
Mitglied
Hi zusammen,
bin schon wieder an meine Grenzen gestossen (das passiert bei mir ziemlich schnell ). Ich habe zwei Tage lang versucht die Werte die der User in Datei "insertcd.php" eingibt durch "insertcd1.php" in meine Datenbank einzutragen aber es klappt nicht!
Ich sehe dass der Screen refresht und die insertcd1.php aufruft aber dann schmeisst er mich wieder auf die insertcd.php zurueck (als wuerde der header tatsaechlich ein leeres Feld finden - was aber nicht der Fall ist). Kann mir bitte jemand helfen und den vermutlich offensichtlichen Fehler finden?
Vielen Dank!
insertcd.php sehr lang!
insertcd1.php
bin schon wieder an meine Grenzen gestossen (das passiert bei mir ziemlich schnell ). Ich habe zwei Tage lang versucht die Werte die der User in Datei "insertcd.php" eingibt durch "insertcd1.php" in meine Datenbank einzutragen aber es klappt nicht!
Ich sehe dass der Screen refresht und die insertcd1.php aufruft aber dann schmeisst er mich wieder auf die insertcd.php zurueck (als wuerde der header tatsaechlich ein leeres Feld finden - was aber nicht der Fall ist). Kann mir bitte jemand helfen und den vermutlich offensichtlichen Fehler finden?
Vielen Dank!
insertcd.php sehr lang!
PHP:
<?php
if ($_COOKIE[success]=="1")
{
$print="<p>You are successfully logged in</p>";
} else {
//go back to login if not successful
header("Location: login.php");
exit;
}
$connection=mysql_connect("localhost","someone","project") or die(mysql_error());
mysql_select_db("cdcat", $connection) or die(mysql_error());
$display = "
<form method=\"post\" action=\"insertcd1.php\">
<p><strong>CD Description/Title:</strong><br>
<input type=\"text\" name=\"desc\" size=60 maxlength=80>
</p></form>";
$getOS = "select os from os order by os";
$getOSRes = mysql_query($getOS, $connection) or die(mysql_error());
if (mysql_num_rows($getOSRes) <1) //checks to see if there is more than 1 os in db
{
// if there are no operating systems
$display .= "<p>Sorry, there are no operating systems in the database yet </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<strong>Operating System:</strong><br>
<select name=\"os_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getOSRes query
while ($record = mysql_fetch_array($getOSRes))
{
$id = $record['os'];
//cleans any special characters out of db
$os = stripslashes ($record['os']);
//to the already created display1, adds os to the menu
$display .="<option value=\"$id\"> $os </option>";
}
$display .= "</select></form>";
}
$getLang = "select language from languages order by language";
$getLangRes = mysql_query($getLang, $connection) or die(mysql_error());
if (mysql_num_rows($getLangRes) <1) //checks to see if there is more than 1 language in db
{
// if there are no languages
$display .= "<p>Sorry, there are no languages in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Language:</strong><br>
<select name=\"lang_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getLangRes query
while ($record = mysql_fetch_array($getLangRes))
{
$id = $record['language'];
//cleans any special characters out of db
$lang = stripslashes ($record['language']);
//to the already created display, adds language to the menu
$display .="<option value=\"$id\"> $lang </option>";
}
$display .= "</select></p></form>";
}
$getProd = "select prodname from products order by prodname";
$getProdRes = mysql_query($getProd, $connection) or die(mysql_error());
if (mysql_num_rows($getProdRes) <1) //checks to see if there is more than 1 product in db
{
// if there are no products
$display .= "<p>Sorry, there are no products in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Product:</strong><br>
<select name=\"prod_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getProdRes query
while ($record = mysql_fetch_array($getProdRes))
{
$id = $record['prodname'];
//cleans any special characters out of db
$prod = stripslashes ($record['prodname']);
//to the already created display, adds product to the menu
$display .="<option value=\"$id\"> $prod </option>";
}
$display .= "</select></p></form>";
}
$getVer = "select versionname from versions order by versionname";
$getVerRes = mysql_query($getVer, $connection) or die(mysql_error());
if (mysql_num_rows($getVerRes) <1) //checks to see if there is more than 1 version in db
{
// if there are no products
$display .= "<p>Sorry, there are no versions in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Version:</strong><br>
<select name=\"ver_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getVerRes query
while ($record = mysql_fetch_array($getVerRes))
{
$id = $record['versionname'];
//cleans any special characters out of db
$ver = stripslashes ($record['versionname']);
//to the already created display, adds version to the menu
$display .="<option value=\"$id\"> $ver </option>";
}
$display .= "</select></p></form>";
}
$display .= "
<form method=\"post\" action=\"insertcd1.php\">
<p><strong>Folder #/Location:</strong><br>
<input type=\"text\" name=\"folder\" size=3 maxlength=3>
</p></form>";
$getFP = "select folderpagenr from folderpages order by folderpagenr";
$getFPRes = mysql_query($getFP, $connection) or die(mysql_error());
if (mysql_num_rows($getFPRes) <1) //checks to see if there is more than 1 folderpage in db
{
// if there are no products
$display .= "<p>Sorry, there are no folder pages in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Folder page #:</strong><br>
<select name=\"fp_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getFPRes query
while ($record = mysql_fetch_array($getFPRes))
{
$id = $record['folderpagenr'];
//cleans any special characters out of db
$fp = stripslashes ($record['folderpagenr']);
//to the already created display, adds folder page to the menu
$display .="<option value=\"$id\"> $fp </option>";
}
$display .= "</select></p></form>";
}
$getDate = "select printdate from dates order by printdate";
$getDateRes = mysql_query($getDate, $connection) or die(mysql_error());
if (mysql_num_rows($getDateRes) <1) //checks to see if there is more than 1 date in db
{
// if there are no dates
$display .= "<p>Sorry, there are no dates in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Print date:</strong><br>
<select name=\"date_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getDateRes query
while ($record = mysql_fetch_array($getDateRes))
{
$id = $record['printdate'];
//cleans any special characters out of db
$date = stripslashes ($record['printdate']);
//to the already created display, adds date to the menu
$display .="<option value=\"$id\"> $date </option>";
}
$display .= "</select></p></form>";
}
$getUse = "select inuseby from used order by inuseby";
$getUseRes = mysql_query($getUse, $connection) or die(mysql_error());
if (mysql_num_rows($getUseRes) <1) //checks to see if there is more than 1 user in db
{
// if there are no users
$display .= "<p>Sorry, there are no users in the database </p>";
} else {
$display .= "
<form method=\"POST\" action=\"insertcd1.php\"><br>
<p><strong>Currently used by:</strong><br>
<select name=\"use_id\">
<option value=\"\"> -- Select one --</option>";
//starts a while loop which iterates through each row found from the $getUseRes query
while ($record = mysql_fetch_array($getUseRes))
{
$id = $record['inuseby'];
//cleans any special characters out of db
$use = stripslashes ($record['inuseby']);
//to the already created display, adds user to the menu
$display .="<option value=\"$id\"> $use </option>";
}
$display .= "</select></p></form>";
}
$display .= "
<form method=\"post\" action=\"insertcd1.php\">
<p><strong>Comments:</strong><br>
<textarea name =\"comments\" cols=35 rows=3 wrap=virtual></textarea>
</p>
<input type=\"submit\" name=\"submit\" value=\"Insert the CD\"></form>";
?>
<html>
<head><title>Insert a CD</title></head>
<LINK REL=stylesheet TYPE="text/css" HREF="project.css">
<body>
<br><br><br><br><br><br><br>
<center>
<h2>Insert a CD</h2></center>
<?php echo $display .=""; ?>
</body>
</html>
insertcd1.php
PHP:
<?php
$connection=mysql_connect("localhost","someone","project") or die(mysql_error());
mysql_select_db("cdcat", $connection) or die(mysql_error());
//checking that all required fields are filled
if (($_POST[desc] == "")||($_POST[os_id] == "")||($_POST[lang_id] == "")||($_POST[prod_id] == "")||($_POST[ver_id] == "")||($_POST[folder] == "")||($_POST[fp_id] == "")||($_POST[date_id] == ""))
{
header("Location:insertcd.php");
exit;
}
$display="
input type=\"hidden\" name=\"desc\" value=\"".$_POST[desc]."\">
input type=\"hidden\" name=\"os_id\" value=\"".$_POST[os_id]."\">
input type=\"hidden\" name=\"prod_id\" value=\"".$_POST[prod_id]."\">
input type=\"hidden\" name=\"ver_id\" value=\"".$_POST[ver_id]."\">
input type=\"hidden\" name=\"lang_id\" value=\"".$_POST[lang_id]."\">
input type=\"hidden\" name=\"folder\" value=\"".$_POST[folder]."\">
input type=\"hidden\" name=\"fp_id\" value=\"".$_POST[fp_id]."\">
input type=\"hidden\" name=\"date_id\" value=\"".$_POST[date_id]."\">
input type=\"hidden\" name=\"use_id\" value=\"".$_POST[use_id]."\">
input type=\"hidden\" name=\"comments\" value=\"".$_POST[comments]."\">";
$desc=$_POST['desc'];
$comments=$_POST['comments'];
$folder=$_POST['folder'];
$prod_id=$_POST['prod_id'];
$ver_id=$_POST['ver_id'];
$date_id=$_POST['date_id'];
$os_id=$_POST['os_id'];
$lang_id=$_POST['lang_id'];
$use_id=$_POST['use_id'];
$fp_id=$_POST['fp_id'];
$sql = "insert into cds values ('',$desc, $comments, $folder, $prod_id, $ver_id, $date_id, $os_id, $lang_id, $use_id, $fp_id)";
$result = mysql_query($sql, $connection) or die(mysql_error());
$display = "<p>CD added successfully!</p><br>Would you like to <a href=\"insertcd.php\">Add another?</a><br>Or go back to the <a href=\"admin1.php\">Admin login page</a>?";
?>
<html><head><title>Insert new cd</title></head>
<body>
<H2>Insert new cd</h2>
<?php echo "$display"; ?>
</body>
</html>