PrinceTaz
-
Posts
63 -
Joined
-
Last visited
Posts posted by PrinceTaz
-
-
I have a full understanding of what a blog does, the problem is knowing how to do it. For example, I have all the ingredients but I don't have the recipe to put it all together. I know that programming doesnt exactly have a recipe and you can code all types of ways but the basic recipe. Like how to retrieve information from a database and that sort of stuff.
-
<html>
<head>
<title>
</title>
Javascript can go here as well
</head>
<body>
<?php
echo "PHP can go here";
?>
</body
</html> -
Do you have any examples of a very simple blog script which I can look at? I don't want anything too advanced.
-
Thanks everybody. I will attempt to build this from scratch again and will post back if I have issues, feel free to post tips that will help me out. I don't want to start off with bad habits.
-
I see, I can make that work. So how can I style the $title in css? It is currently
echo "<h1>" . $title . "</h1>\n";
echo "<p>" . $content . "</p>\n";
echo "<p>By:" . $author . "</p>\n";
}, how can I style it.
EDIT: I am having trouble displaying the date. I have this:
$title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_SPECIAL_CHARS); $content = filter_input(INPUT_POST, 'post', FILTER_SANITIZE_SPECIAL_CHARS); $author = filter_input(INPUT_POST, 'author', FILTER_SANITIZE_SPECIAL_CHARS); $date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_SPECIAL_CHARS); //index.php while (mysqli_stmt_fetch($stmt)) { echo "<h1>" . $title . "</h1>\n"; echo "<p>" . $content . "</p>\n"; echo "<p>By:" . $author . "</p>\n"; echo "<p>By:" . $date . "</p>\n"; } //but I get this error Notice: Undefined variable: timestamp in C:\wamp\www\test\index.php on line 35
-
I see, I can make that work. So how can I style the $title in css? It is currently
echo "<h1>" . $title . "</h1>\n"; echo "<p>" . $content . "</p>\n"; echo "<p>By:" . $author . "</p>\n"; }
, how can I style it. -
So i am going recode this from scratch and test out just how much I've learned from you.
EDIT: How can I add a date to when the author posts.
-
Thanks a lot!!
Ok so instead of this:
// This gets executed first in your script $connection = mysqli_connect(data); // your function declaration function read_stuff($connection, $data) { // query } // use the function (i.e. in index.php) read_stuff($connection, "data");
can I do this instead:
// This gets executed first in your script require "connect.php"; // your function declaration function read_stuff($connection, $data) { // query } // use the function (i.e. in index.php) read_stuff($connection, "data");
And the above script, I'm guessing that its in the index?
So let me ask this, lets say I use a script to grab information in a different file like this:
//information grabber, grabber.php <?php //grabs informaition $title = *SELECT FROM 'article', 'title'; $content = *SELECT FROM 'article', 'content'; $author = *SELECT FROM 'article', 'author'; ?> //displays data <?php include "grabber.php' echo "<p>$title</p>"; ?>
Basically Im asking if I can share variables within different files.
Also the script to SELECT FROM is probably wrong because I guessed it from looking at your code.
-
So let me get this straight, when I am writing the code to grab the data from the database, within the same script, I can display that data? Well the way you say makes it really simple, but going to my code, its like a hot mess. Somehow the script executes successfully, but modifying is hard because there is a bunch of code everywhere.
-
Oh my gosh it worked. Thanks a lot. But if its no trouble, can you explain to me why you used the "stmt" stuff? I have never seen it before. Basically the script you wrote to grab information, I need to know how and why it works, please.
Test it here: http://mybbdevelopers.net/test/
-
Ok I have made the database. So how should I go about doing this? I currently have a "include "connect.php"", where do I put the variables? On the index.php or on the connect page. Basically, where do I request the database information and where do I post it?
-
Wow thanks for the explanations. I attempted this as people said it would help me out. In the database you said make an auto increment. I didn't do that. My tutor wasn't on so all I did in mysql was make a table and 3 columns. The table being 'article', and the three columns, 'title', 'content', and 'author'. But its not a registration based. I'm not advanced so I want everybody to be able to post blogs and see it on the home page. How do I make it auto increment?
-
New error
( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\test\index.php on line 14 Call Stack # Time Memory Function Location 1 0.0000 240560 {main}( ) ..\index.php:0 2 0.0590 251064 mysqli_query ( ) ..\index.php:14 ( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\test\index.php on line 16 Call Stack # Time Memory Function Location 1 0.0000 240560 {main}( ) ..\index.php:0 2 0.0620 251232 mysqli_query ( ) ..\index.php:16 ( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\test\index.php on line 18 Call Stack # Time Memory Function Location 1 0.0000 240560 {main}( ) ..\index.php:0 2 0.0660 251496 mysqli_query ( ) ..\index.php:18
-
So I started a blog project just to help me out with learning php.
This is my post form<form action="insert.php" method="post"> Title: <input type="text" name="title"> <br> Post: <input type="text" name="post"> <br> Author: <input type="text" name="author"> <br> <input type="submit"> </form>
Insert.php<?php $con = mysqli_connect("localhost","test","","test"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $title = mysqli_real_escape_string($con, $_POST['title']); $content = mysqli_real_escape_string($con, $_POST['post']); $author = mysqli_real_escape_string($con, $_POST['author']); $sql="INSERT INTO article (title, content, author) VALUES ('$title', '$content', '$author')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>
But when I try to display that information here:<h1>Title: </h1> <?php echo $title; ?> <h2>Content: </h1> <?php echo $content; ?> <h3>Posted by: </h1> <?php echo $author; ?>
It doesn't work and I get this:( ! ) Notice: Undefined variable: title in C:\wamp\www\test\index.php on line 33 Call Stack # Time Memory Function Location 1 0.0000 239144 {main}( ) ..\index.php:0 Content: ( ! ) Notice: Undefined variable: content in C:\wamp\www\test\index.php on line 34 Call Stack # Time Memory Function Location 1 0.0000 239144 {main}( ) ..\index.php:0 Posted by: ( ! ) Notice: Undefined variable: author in C:\wamp\www\test\index.php on line 35 Call Stack # Time Memory Function Location 1 0.0000 239144 {main}( ) ..\index.php:0
The form works because when I looked at the database, the information was there. The problem is getting that information and displaying it in the right place, how can i fix that?
Just in case, this is my index:<?php include ('connect.php'); include ('header.php'); ?> <div id="container"> <div id="rightcol"> <form action="insert.php" method="post"> Title: <input type="text" name="title"> <br> Post: <input type="text" name="post"> <br> Author: <input type="text" name="author"> <br> <input type="submit"> </form> </div> <div id="content"> <h1>Title: </h1> <?php echo $title; ?> <h2>Content: </h1> <?php echo $content; ?> <h3>Posted by: </h1> <?php echo $author; ?> </div> </div> <?php include "footer.php"; ?> </div>
Forum Pioneer
in Job Offerings
Posted
Site Name: Forum Pioneer
Link to site: http://forumpioneer.com/ (Down Currently)
Positions Available:
2 Admin
Super and Normal Moderators
phpBB Support Team
MyBB Support Team
IPB Support Team
vBulletin Support Team
XenForo Support Team
Forum Pioneer is a resource site and webmasters central for forum software. I intend for it to be a collection of the best and the most useful modifications that forum owners need. Pm me for more info. We are currently on phpBB, but I intend to migrate to IPB when the forum gets bigger.