insert to db form(not so simple)[solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adamrain
Forum Newbie
Posts: 15
Joined: Thu Jun 03, 2010 5:35 am

insert to db form(not so simple)[solved]

Post by adamrain »

no meters found the problem myself.

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;
}
?>


oh i almost forgot i had an add function that didnt work if anyone can tell why it would be great!

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);
  
}
Post Reply