Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Архив1 / docx56 / курсач(11).docx
Скачиваний:
41
Добавлен:
01.08.2013
Размер:
69.91 Кб
Скачать

Insert_link.Php

<?php session_start(); ?>

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Chemistry LAB - free service</title>

<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="functions.js"></script>

</head>

<body>

<div id="wrap">

<div id="header">

<h1 id="sitename">Chemistry LAB</h1>

</div>

<div id="page">

<div id="menu">

<div id="sidemenu">

<h2 align="center">Регистрация </h2>

<ul>

<?php include_once ("register.php");?>

<!-- ****************-->

</ul>

<ul>

<h2 align="center">Меню</h2>

<li><a href="index.php">Главная</a> </li>

<li><a href="result.php">Сервис</a></li>

<?php

if (!empty($_SESSION['login']))

{

print<<< HERE

<li><a href="insert.php">Добавление вещества</a></li>

<li class="active"><a href="insert_ch.php">Добавление реакции</a></li>

<li><a href="del_ch.php">Удаление вещества</a></li>

<li><a href="insert_admin.php">Добавление админа</a></li>

HERE; }?>

</ul>

</div>

</div>

<div id="content">

<h2align="center">Добавить новое вещество</h2>

<p>

<form action="link_go.php" method="GET">

<table width="60%" border="0">

<tr>

<td>Задать связь для элемента:</td>

<td><input name="elem1" type="text" size="50" /></td>

</tr> <tr>

<td>С элементом:</td>

<td><input name="elem2" type="text" value="" size="50" maxlength="255" /><br /></td>

</tr> <tr>

<td>Результат(формула):</td>

<td><input name="short" type="text" size="50" /><br /></td>

</tr> <tr>

<td>Результат(краткое описание):</td>

<td><input name="long" type="text" size="50" /></td>

</tr> <tr>

<td>Результат(дополнительная информация):</td>

<td><textarea name="info" id="textarea1" cols="45" rows="5"></textarea></td>

</tr> </table>

<input type="submit" value="GO" />

</form></p></div>

<div class="clear"></div>

<div id="browse">

<h2 class="subhead"></h2>

</div></div>

</div>

</body>

</html>

link_go.php

<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Chemistry LAB - free service</title>

<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="functions.js"></script>

</head>

<body>

<div id="wrap">

<div id="header">

<h1 id="sitename">Chemistry LAB</h1>

</div>

<div id="page">

<div id="menu">

<div id="sidemenu">

<h2 align="center">Регистрация </h2>

<ul>

<?php include_once ("register.php");?>

<!-- ****************--></ul>

<ul>

<h2 align="center">Меню</h2>

<li><a href="index.php">Главная</a> </li>

<li><a href="result.php">Сервис</a></li>

<?php

if (!empty($_SESSION['login']))

{

print<<< HERE

<li><a href="insert.php">Добавление вещества</a></li>

<li class="active"><a href="insert_ch.php">Добавление реакции</a></li>

<li><a href="del_ch.php">Удаление вещества</a></li>

<li><a href="insert_admin.php">Добавление админа</a></li>

HERE;}?>

</ul>

</div>

</div>

<div id="content">

<h2align="center">Новая химическая реакция</h2>

<?php

require_once("config.php");

$i = $_GET['elem1'];

$y = $_GET['elem2'];

$short = $_GET['short'];

$long = $_GET['long'];

$info = $_GET['info'];

$strSQL = "SELECT `id` FROM `elements` WHERE `short_name`='$i'";

$rs = mysql_query($strSQL);

while($row = mysql_fetch_array($rs)) {

$r=$row['id'] ;

}

$strSQL = "SELECT `id` FROM `elements` WHERE `short_name`='$y'";

$rs = mysql_query($strSQL);

while($row = mysql_fetch_array($rs)) {

$t=$row['id'] ;

}

$strSQL = "SELECT `short_name` FROM `result` WHERE `id1`=$r AND `id2`=$t OR `id1`=$t AND `id2`=$r";

$rs = mysql_query($strSQL);

while($row = mysql_fetch_array($rs)) {

$k=$row['short_name'] ;

}

if($r==0OR$t==0)echo"Одного из элементов нет в БД, добавьте его!";

else{

if (!$k){

mysql_query("set character_set_client='utf8'");

mysql_query("set character_set_results='utf8'");

mysql_query("set collation_connection='utf8_general_ci'");

$strSQL = "INSERT INTO `chemistry`.`result` (`id1`, `id2`, `short_name`, `long_name`, `info`) VALUES ('$r', '$t', '$short', '$long', '$info');";

if(!mysql_query($strSQL))

{

echo "Ошибка добавления связей!";

}

elseecho"Связь добавлена успешно!";}

elseecho"Такая реакция уже есть.";

}?>

</p>

</div>

<div class="clear"></div>

<div id="browse">

<h2 class="subhead"></h2>

</div>

</div>

</div>

</body>

</html>