I had made some pages and they work but I'm not sure if I coded it in best way so I want your suggestions and ideas to make my code better.
connection.php
<?php
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_data = 'project_eye';
$connect = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or mysql_error();
$db_sele = mysql_select_db($mysql_data);
mysql_query("set names 'utf8'");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
mysql_query("SET character_set_database=utf8");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_server=utf8");
?>
phpCodes.php
:
It's a page that contain the header. I'm using it to call the function to my page.
<?php
function headerCode(){
echo '
<div class="header">
<div class="header-top">
<div class="logform">
';
accountLinks();
echo '
</div>
<div class="social-newtork">
<a><img src="images/f.png"></a>
<a><img src="images/t.png"></a>
<a><img src="images/g.png"></a>
</div>
</div>
<div class="menu-content">
<img src="images/eye.jpg">
<img src="images/compelete.jpg" style="width: 78.3%">
<div class="desc">
<span class="first">عينٌـــــــــ</span>
<span class="second">على الحقيقة</span>
</div>
</div>
<div class="menu">
<ul>
<li><a href="">محلية</a></li>
<li><a href="">عالمية</a></li>
<li><a href="">رياضية</a></li>
<li><a href="">طبية</a></li>
<li><a href="">طرائف</a></li>
</ul>
</div>
</div>
';
}
function accountLinks(){
if( !isset($_SESSION['id']) ){
echo '
<form method="post" action="index.php">
<input type="submit" name="submit" value="دخول" class="log">
<input type="password" id="password" name="password" placeholder="كلمة المرور" class="mem-information">
<input type="text" placeholder="اسم المستخدم" id="username" name="username" class="mem-information">
</form> ';
}else{
echo '
<form method="post" action="index.php">
<a href="controlpanel/" class="account">لوحة التحكم</a>
<input type="submit" href="" class="logout" name="logout" onclick="logout(this);" value="تسجيل الخروح">
</form>
';
}
}
?>
con.php
:
This page contains simple control panel and it didn't complete yet
<?php
ob_start();
session_start();
include('../includes/connect.php');
include('../includes/phpCodes.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>لوحة التحكم</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/mainstyle.css">
<link rel="stylesheet" type="text/css" href="css/controlstyle.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#tabs div').hide();
$('#tabs div:first').show();
$('#tabs ul li:first').addClass('active');
$('#tabs ul li a').click(function(){
$('#tabs ul li').removeClass('active');
$(this).parent().addClass('active');
var currentTab = $(this).attr('href');
$('#tabs div').hide();
$(currentTab).show();
return false;
});
});
</script>
</head>
<body>
<div class="wrapper">
<?php headerCode(); ?>
<div class="content">
<div id="tabs">
<ul>
<li><a href="#add">اضافة موضوع</a></li>
<li><a href="#remove">حذف موضوع</a></li>
<li><a href="#edit">تعديل موضوع</a></li>
<li><a href="#edit">التحكم بالاقسام</a></li>
</ul>
<div id="add">
<form method="POST" action="includes/add.php" dir="rtl" enctype="multipart/form-data">
<br>
حدد القسم : <select name="section">
<?php
$query = "SELECT * FROM `sections`";
$result = mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
echo "<option value='".$row['id']."'>".$row['sectionName']."</option>";
}
?>
</select><br>
عنوان الموضوع :<input type="text" name="title" class="mem-information"/><br>
الموضوع : <br /><textarea name="subject" rows="10" cols="50" class="mem-information" style="width: 500px"></textarea><br /><br>
الصورة :<input type="file" name="image"><br>
<input type="submit" value="إرسال" name="send" class="log" style="color: black">
</form>
</div>
<div id="remove">
<form method="POST" action="includes/remove.php" dir="rtl"><br>
حدد القسم :
<select name ="sectionsName">
<option value="">dd</option>
</select>
<input type="submit" value="حذف" name="send" class="log" style="color: black">
</form>
</div>
<div id="edit">
</div>
<div id="addDep">
</div>
</div>
</div>
</div>
</body>
</html>
add.php
:
It's job is to add values to database.
<?php
session_start();
include('../../includes/connect.php');
$sectionID = $POST["section"];
$title = $_POST['title'];
$subject = $_POST['subject'];
$visiable = 1;
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($_FILES["image"]["type"]);
$query = "insert into news (title, subject, visiable, image, section_id) values ('$title','$subject', '$visiable', '$imageData', '$sectionID')";
$result = mysql_query($query);
$id = mysql_insert_id();
$data = array(
'id' => $id
);
$base = '../../show.php';
$url = $base. '?' . http_build_query($data);
header("Location: $url");
exit();
?>
show.php
:
After adding to database this page will display the values.
<?php
ob_start();
session_start();
include('includes/connect.php');
include('includes/phpCodes.php');
function showNews(){
$id = $_GET['id'];
echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';
echo '
<h1><p class="subjecTitle">هنا العنوان</p></h1>
<div class="newsContent">
hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi
</div>
';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>عينٌ على الحقيقة</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/mainstyle.css">
<link rel="stylesheet" type="text/css" href="css/showstyle.css">
<script lang="javascript">
function logout(myFrame){
myFram.submit();
}
</script>
</head>
<body>
<div class="wrapper">
<?php headerCode(); ?>
<div class="content" dir="rtl">
<?php showNews(); ?>
</div>
</div>
</body>
</html>