Jump to content

PrinceTaz

Members
  • Posts

    63
  • Joined

  • Last visited

Everything posted by PrinceTaz

  1. 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.
  2. 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.
  3. 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/
  4. 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?
  5. 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?
  6. 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
  7. 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>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.