Author Topic: Php help  (Read 14035 times)

0 Members and 1 Guest are viewing this topic.

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Php help
« on: February 24, 2013, 10:35:13 pm »
Hello. I wana make  1 page where a am putting some article, and i don't know how that article append in index page? when i click submit button the article will be appended on my index page. How to do that? help pls, sorry for my english
I am programmer and you are my source code

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: Php help
« Reply #1 on: February 24, 2013, 11:39:43 pm »
It's kind of difficult to understand what your asking for, but I'm guessing you want a system where you can write an article, and when you press submit it appears on the main page of your website? You need to use PHP/MySQL for that. In phpmyadmin, youd want to make a database->table-> and then start naming the columns in it. In your case, you may want to have user, title, and article as your three different columns.
When your user clicks the submit button, the code would look something like:
Code: [Select]
if(isset($_POST['submit'])){
$title = $_POST['title'];
$user = $_SESSION['usr'];
$article = $_POST['article'];
mysql_query("INSERT INTO table user, title, article VALUES ($user, $title, $article)", $con);
mysql_close($con);
}
After that, you'll want the code on the index page to display posts something like:
Code: [Select]
$result = mysql_query("SELECT * FROM table", $con);
if(mysql_num_rows($result)){
echo "No articles yet";
}else{
while($row = $mysql_fetch_assoc($result)){
$article = $row['article'];
$title = $row['title'];
name = $row['user'];
echo $user.":"$title."<br />"."$article";
}
}
That is of course just some pseudo code, im not going to write the whole thing for you :P To learn about this stuff research mysql, thats how you start doing things with posts and etc. Basically, though, you just have the user enter the users input into the database and then print it out. Remember to secure it if this is for public use. Use Google :)

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: Php help
« Reply #2 on: February 25, 2013, 12:07:20 am »
Thank you alot man :) this is it. I tried to search on google but i didn't find anything :) admin can close this :)
I am programmer and you are my source code

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: Php help
« Reply #3 on: February 25, 2013, 01:20:08 pm »
It's kind of difficult to understand what your asking for, but I'm guessing you want a system where you can write an article, and when you press submit it appears on the main page of your website? You need to use PHP/MySQL for that. In phpmyadmin, youd want to make a database->table-> and then start naming the columns in it. In your case, you may want to have user, title, and article as your three different columns.
When your user clicks the submit button, the code would look something like:
Code: [Select]
if(isset($_POST['submit'])){
$title = $_POST['title'];
$user = $_SESSION['usr'];
$article = $_POST['article'];
mysql_query("INSERT INTO table user, title, article VALUES ($user, $title, $article)", $con);
mysql_close($con);
}
After that, you'll want the code on the index page to display posts something like:
Code: [Select]
$result = mysql_query("SELECT * FROM table", $con);
if(mysql_num_rows($result)){
echo "No articles yet";
}else{
while($row = $mysql_fetch_assoc($result)){
$article = $row['article'];
$title = $row['title'];
name = $row['user'];
echo $user.":"$title."<br />"."$article";
}
}
That is of course just some pseudo code, im not going to write the whole thing for you :P To learn about this stuff research mysql, thats how you start doing things with posts and etc. Basically, though, you just have the user enter the users input into the database and then print it out. Remember to secure it if this is for public use. Use Google :)
You are on a hackers forum and you post unsafe code :D
~Factionwars

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: Php help
« Reply #4 on: February 25, 2013, 04:58:45 pm »
Don't worry for safety. But i forgot to ask one more question. When i have some article and  how to append in bottom another article with border and etc like prevoius post understand. Just append with all css elements with different article
I am programmer and you are my source code

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: Php help
« Reply #5 on: February 26, 2013, 01:36:37 am »
Lol factionwars i said it was just pseudo code :) I wouldnt write the whole thing for him lol
Stax, you mean how would you style each post? just put the style in the while loop and itll repeat it for each post. If thats not what you meant, sorry, lol, its kind of hard to understand the way you write. If your worried about security btw, make sure you google it, its fairly simple to defend basic attacks.