i figurd if im working with a lot of simler data typs in this system i might as well have some kind of template code that i can change a little to fit to all the data types (blog,comments,links, pictures, category,etc).
in general its a very good idea instead of writing everything 100 times...the problem im having i think is something with the sql query.
here is the code,if you dont understand anything please ask ill explain.
Code: Select all
<?php
include 'functions.php';
checkLogin();
//the conect to db is in functions
$user_id= $_SESSION['id'];
//i did this so i can use this page for other data typs
$page=$_GET['page'];
if(isset($_POST['submit'])){
if($page='blog'){
$table=$page;
$title=$_POST['title'];
$content=$_POST['content'];
if(isset($_POST['active'])){
$active=1;}else{$active=0;}
$date=$_POST['date'];
$column="title,content,active,date";
$yourvars="'$title','$content','$date'";
}
//query for table
$add=mysql_query("INSERT into $table ($column) VALUES($yourvars)");
$topicid = mysql_insert_id();
$column="id_user,type,id_type";
$yourvars="'$user_id','$page','$topicid'";
//query relations between user and data
$add_relation=mysql_query("INSERT into relations($column) VALUES ($yourvars)");
}
if ($page=='blog'){
echo $echo=<<<form
<form id="form1" name="form1" method="post" action="">
<p>
<label>title
<input type="text" name="title" id="title" />
</label>
</p>
date
<input type="text" name="date" id="title" />
<p>
<label>content
<textarea name="content" id="content" cols="45" rows="5"></textarea>
</label>
</p>
<p>
<label>
<input type="checkbox" name="active" value="1" id="poblish" />
poblish </label>
</p>
<input type="submit" name="submit" />
</form>
form;
}
?>
Code: Select all
/*
$table="name";
$column="col,col2,col3";
$yourvars="'$somthing','$somthing2','$somthing3'";
*/
function add($table,$column,$yourvars){
$add=mysql_query("INSERT into $table($column) VALUES ($yourvars)");
if (!$add )
exit($add);
}