Jump to content

Html

Members
  • Posts

    640
  • Joined

  • Last visited

Posts posted by Html

  1. I tried editing the files to remove the subject, once it gets to process.php no loading.

    All I did was remove subject and anything with it from all the files. Including removing the subject from the db. Just that small change which I think I've done correctly, and it doesn't work.😥

    I also was able to view example files from leaning php book, I really need the Learn php 7 easy steps kind of books, 😉 even though they aren't as informative, very simple.

    <?php
    $page_title = 'forum'
    include('includes/header.html');
    function fail($str)
    {
    echo"<p>Please enter a $str.</p>";
    echo '<p><a href="post.php">Post message</a>';
    include('includes/header.html');
    exit();
    }
    if( isset( $_POST[ 'message' ] ) )
    {
      if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
      { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
      else { fail( 'First Name' ) ; }
      if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
      { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
      else { fail( 'Last Name' ) ; }
      if ( !empty( trim( $_POST[ 'message' ] ) ) )
      { $message = addslashes( $_POST[ 'message' ] ) ; }
      else { fail( 'Message' ) ; }
      require ( '/connect_db.php' ) ;
      $sql = "INSERT INTO forum (first_name,last_name,message,post_date) 
              VALUES ('$first_name', '$last_name', '$message', NOW() )" ;
      $result = mysqli_query( $dbc, $sql ) ;
      if (mysqli_affected_rows($dbc) != 1) 
      { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
      else 
      { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
    }
    ?>
    <?php 
    $page_title = 'PHP Process Error' ;
    include ( 'includes/header.html' ) ;
    function fail( $str )
    {
      echo "<p>Please enter a $str.</p>";
      echo '<p><a href="post.php">Post Message</a>' ;
      include ( 'includes/footer.html' ) ;
      exit(); 
    }
    if( isset( $_POST[ 'message' ] ) )
    {
      if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
      { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
      else { fail( 'First Name' ) ; }
      if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
      { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
      else { fail( 'Last Name' ) ; }
      if ( !empty( trim( $_POST[ 'message' ] ) ) )
      { $message = addslashes( $_POST[ 'message' ] ) ; }
      else { fail( 'Message' ) ; }
      require ( 'connect_db.php' ) ;
      $sql = "INSERT INTO forum (first_name,last_name,message,post_date) 
              VALUES ('$first_name', '$last_name', '$message', NOW() )" ;
      $result = mysqli_query( $dbc, $sql ) ;
      if (mysqli_affected_rows($dbc) != 1) 
      { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
      else 
      { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
    }
    ?>
    <?php
    $page_title='php post message';
    include('includes/header.html');
    echo'<form action="process.php"
    method="POST" accept-charset=""uft-8">
    First Name:<input name="first_name" type="text">
    Last Name:<input name="last_name" type="text">
    <p>Message:<br>
    <textarea name="message" rows"5" cols="50">
    </textarea></p>
    <p><input type="submit" value="Submit"></p>
    </form>';
    echo '<p>
    <a href="forum.php">Forum</a></p>';
    include('includes/footer.html');
    ?>

    I've removed from forum, post, and process subject named as I stated. The error is column 1

    Works okay now. I guess it was just a server side process error.

  2. <?php 
    /* Main page with two forms: sign up and log in */
    require 'connect_db.php';
    session_start();
    ?>
    <!DOCTYPE html>
    <html>
    <head>
      <title>-Sign-Up/Login Form</title>
      <?php include 'css/css.html'; ?>
    </head>
    
    <?php 
    if ($_SERVER['REQUEST_METHOD'] == 'POST') 
    {
        if (isset($_POST['login'])) { //user logging in
    
            require 'login.php';
            
        }
        
        elseif (isset($_POST['register'])) { //user registering
            
            require 'proces.php';
            
        }
    }
    ?>
    <body>
    <img src="header20182.jpg">
    <center>
    <img src="userscopy.jpg">
    </center>
      <div class="form">
          
          <ul class="tab-group">
            <li class="tab"><a href="#signup">Sign Up</a></li>
            <li class="tab active"><a href="#login">Log In</a></li>
          </ul>
          
          <div class="tab-content">
    
             <div id="login">   
              <h1>Welcome!</h1>
              
              <form action="proces.php" method="post" autocomplete="off">
              
                <div class="field-wrap">
                <label>
                  Email Address<span class="req">*</span>
                </label>
                <input type="email" required autocomplete="off" name="email"/>
              </div>
              
              <div class="field-wrap">
                <label>
                  Password<span class="req">*</span>
                </label>
                <input type="password" required autocomplete="off" name="password"/>
              </div>
              
              <p class="forgot"><a href="forgot.php">Forgot Password?</a></p>
              
              <button class="button button-block" name="login" />Log In</button>
              
              </form>
    
            </div>
              
            <div id="signup">   
              <h1>Create an account today! </h1>
              
              <form action="proces.php" method="post" autocomplete="off">
              
              <div class="top-row">
                <div class="field-wrap">
                  <label>
                    First Name<span class="req">*</span>
                  </label>
                  <input type="text" required autocomplete="off" name='firstname' />
                </div>
            
                <div class="field-wrap">
                  <label>
                    Last Name<span class="req">*</span>
                  </label>
                  <input type="text"required autocomplete="off" name='lastname' />
                </div>
              </div>
    
              <div class="field-wrap">
                <label>
                  Email Address<span class="req">*</span>
                </label>
                <input type="email"required autocomplete="off" name='email' />
              </div>
              
              <div class="field-wrap">
                <label>
                  Six to eight character Password<span class="req">*</span>
                </label>
                <input type="password"required autocomplete="off" name='password'/>
              </div>
              
              <button type="submit" class="button button-block" name="register" />Register</button>
              
              </form>
    
            </div>  
            
          </div><!-- tab-content -->
          
    </div> <!-- /form -->
      <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    
        <script src="js/index.js"></script>
    <a href="privacy.html" target="_blank"><img src="privacy.jpg">
    <img src="bottomheader.jpg">
    </body>
    </html>

    Okay I'm trying to get this index page from the old files to work with a new register.php, which is from the php 7 book,

    So far the page goes to it after registration but recorded data in the db. Not sure if this was the correct way but consider it works to post data, seemed like the next best step.

    so proces.php

    <?php 
    $page_title = 'PHP Process' ;
    include ( 'includes/header.html' ) ;
    function fail( $str )
    {
      echo "<p>Please enter a $str.</p>";
      echo '<p><a href="post.php">Post Message</a>' ;
      include ( 'includes/footer.html' ) ;
      exit(); 
    }
    if( isset( $_POST[ 'message' ] ) )
    {
      if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
      { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
      else { fail( 'First Name' ) ; }
      if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
      { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
      else { fail( 'Last Name' ) ; }
      if ( !empty( trim( $_POST[ 'email' ] ) ) )
      { $subject = addslashes( $_POST[ 'email' ] ) ; }
      else { fail( 'email' ) ; }
      if ( !empty( trim( $_POST[ 'password' ] ) ) )
      { $subject = addslashes( $_POST[ 'password' ] ) ; }
      else { fail( 'password' ) ; }
      require ( 'connect_db.php' ) ;
      $sql = "INSERT INTO users (first_name,last_name,email,password) 
              VALUES ('$first_name', '$last_name', '$email', '$password' )" ;
      $result = mysqli_query( $dbc, $sql ) ;
      if (mysqli_affected_rows($dbc) != 1) 
      { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
      else 
      { mysqli_close( $dbc ) ; header('Location: profile.php') ;   }
    }

    So profile should be next, but only loads the includes header page heading.

  3. Okay, I copied the full, and pasted it in, now I get a process error, that is all that loads, the page header is also displayed. So something is working, no db info recorded.

    What could it?

    All the files are in the same folder, except for the includes folder files.

    Yes it was simply the forward slash I forgot about, I noticed that php code must be spaced. I'm a step closer to my goal of a working system with this. Now using what I had downloaded, and trying to change it to work with this code.😩

    Thanks for the responses.

  4. My last file to do is process, filled in the details, only a blank page loads, and no data entered into the db.

    <?php
    $page_title = 'forum'
    include('includes/header.html');
    function fail($str)
    {
    echo"<p>Please enter a $str.</p>";
    echo '<p><a href="post.php">Post message</a>';
    include('includes/header.html');
    exit();
    }
    if( isset( $_POST[ 'message' ] ) )
    {
      if ( !empty( trim( $_POST[ 'first_name' ] ) ) ) 
      { $first_name = addslashes( $_POST[ 'first_name' ] ) ; }
      else { fail( 'First Name' ) ; }
      if ( !empty( trim( $_POST[ 'last_name' ] ) ) )
      { $last_name = addslashes( $_POST[ 'last_name' ] ) ; }
      else { fail( 'Last Name' ) ; }
      if ( !empty( trim( $_POST[ 'subject' ] ) ) )
      { $subject = addslashes( $_POST[ 'subject' ] ) ; }
      else { fail( 'Subject' ) ; }
      if ( !empty( trim( $_POST[ 'message' ] ) ) )
      { $message = addslashes( $_POST[ 'message' ] ) ; }
      else { fail( 'Message' ) ; }
      require ( '/connect_db.php' ) ;
      $sql = "INSERT INTO forum (first_name,last_name,subject,message,post_date) 
              VALUES ('$first_name', '$last_name','$subject', '$message', NOW() )" ;
      $result = mysqli_query( $dbc, $sql ) ;
      if (mysqli_affected_rows($dbc) != 1) 
      { echo '<p>Error</p>'.mysqli_error($dbc); mysqli_close( $dbc ) ;  } 
      else 
      { mysqli_close( $dbc ) ; header('Location: forum.php') ;   }
    }
    ?>

     

  5. I am using Infinityfree which is very much the same as Advancedfree, infinityfree is Arizonan based from the information available.

    But yes, I typed in the msql server address, and the mysql  username,  password, and database which has the created forum table that I used from the above post. I had trouble with this host using the example files I downloaded, and edited and that didn't work on there service, but did work on Advancedfree and Heartinternet, the latter being paid.

    I did inquire on their forum, and an Admin was upset about me complaining, if that rubbish worked on those two hosts why this host so particular, could be that they have very over protective system.

    Yes, there is a password which is not the same as the user login, that was same as Heart. It seemed obvious with Heart than with this. Okay so far looks like this is up and running.

  6. I tried removing the bracket at the end, only then causes a T_logical error on line 4, and if I do remove another from line 4.

    You'll have to point to it, because I haven't a clue.

  7. <?php
    
    $dbc = mysqli_connect( 'localhost' , 'mike' , 'easysteps' , 'website_db' )
    OR die( mysqli_connect_error() ) ;
    
    mysqli_set_charset( $dbc , 'utf8' ) ;

    This is from the files you linked to,

     

    <?php
    $dbc=
    mysqli_connect( 'server', 'user', 'pass', 'db', )
    OR die ( mysqli_connect_error() );
    mysqli_set_charset($dbc,'utf-8');

     

  8. They are all in htdocs, there is an incudes folder with header, and footer html, with a <p> tag each. That is it.

    I see, I didn't know about that, I couldn't of guessed.

    Now line 3 is the problem, I thought may the ) was the problem as it states, no change.

    Ah I see, so there are example files, could it be the spacing of the code? n ) and so on?

  9. Other than the missing i, what else? That isn't the solution.

    Quote

    Warning: require(/connect_db.php): failed to open stream: No such file or directory in

    blah blah directory of free web host.

  10. Quote

    Fatal error: require(): Failed opening required '/connect_db.php' (include_path='.:/usr/share/pear/')

    That is after the trying the create_forum page, line 5 it also states.

    mysql_set_charset($dbc, 'utf-8');

     

  11. Ah, I see.

    I tried editing both pages, nothing.

    <?php
    $page_title = 'forum'
    include('includes/header.html');
    require ('/connect_db.php');
    $sql = 'SELECT * FROM forum';
    $result = mysql_query($dbc, $sql);
    if ( mysqli_num_rows($result)>0)
    {
    echo '<table><tr><th>Posted By</th>
    <th>Subject</th><th id="msg">Message</th></tr>';
    while ($rows=mysqli_fetch_array($result, MYSQLI_ASSOC))
    {
    echo '<tr><td>'.
    $row['first_name'].''.
    $row['last_name'].'<br>'.
    $row['post_date'].'</td><td>'.
    $row['subject'].''.
    $row['message'].''.
    }
    echo'</table>';
    else
    {
    echo '<p>There are currently no messages.</p>';
    }
    
    echo'<p><a href="post.php">Post Message</a></p>';
    mysqli_close($dbc);
    incluide('includes/footer.html');
    ?>

    There is no actual footer.html or anything, I doubt that would matter.

     

    <?php
    require ('/connect_db.php');
    if (mysqli_ping($dbc))
    {
    echo 'MySQL Server', mysqli_get_server_info($dbc)
    'on', mysqli_get_host_info($dbc);
    }
    ?>

    That was correct already.

  12. Right okay,

    So this is what it should be,

    <?php
    require('\connect_db.php');
    
    $sql='CREATE TABLE IF NOT EXISTS forum('.
    'post_id INT UNSIGNED NOT NULL AUTO_INCREMENT,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'last_name VARCHAR(40) NOT NULL,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'subject VARCHAR(60) NOT NULL,'.
    'message TEXT NOT NULL,'.
    'post_date DATETIME NOT NULL,'.
    'PRIMARY KEY (post_id))';
    
    if(mysqli_query($dbc, $sql)===True)
    {
    echo'Table "forum" created successfully';
    }
    else
    {
    echo 'Error Creating table:'.mysqli_error($dbc);
    }
    mysqli_close($dbc);
    ?>

    The page doesn't do anything when i try to load it, which is obviously how the table would be loaded into the db.

  13. Okay I tried using func code that created a table.

    <?php
    $page_title = 'forum'
    include('includes/header.html');
    require ('\connect_db.php');
    $sql = 'SELECT * FROM forum';
    $result = mysql_query($dbc, $sql);
    if ( mysqli_num_rows($result)>0)
    {
    echo '<table><tr><th>Posted By</th>
    <th>Subject</th><th id="msg">Message</th></tr>';
    while ($rows=mysqli_fetch_array($result, MYSQLI_ASSOC))
    {
    echo '<tr><td>'.
    $row['first_name'].''.
    $row['last_name'].'<br>'.
    $row['post_date'].'</td><td>'.
    $row['subject'].''.
    $row['message'].''.
    }
    echo'</table>';
    else
    {
    echo '<p>There are currently no messages.</p>';
    }
    
    echo'<p><a href="post.php">Post Message</a></p>';
    mysqli_close($dbc);
    incluide('includes/footer.html');
    ?>

    So this is forum.php

    doesn't display anything.

    <?php
    require ('/connect_db.php');
    if (mysqli_ping($dbc))
    {
    echo 'MySQL Server', mysqli_get_server_info($dbc)
    'on', mysqli_get_host_info($dbc);
    }
    ?>

    require.php

    And create_forum.php

    <?php
    require('\connect_db.php');

    $sql='CREATE TABLE IF NOT EXISTS forum('
    'post_id INT UNSIGNED NOT NULL AUTO_INCREMENT,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'last_name VARCHAR(40) NOT NULL,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'subject VARCHAR(60) NOT NULL,'.
    'message TEXT NOT NULL,'.
    'post_date DATETIME NOT NULL,'.
    'PRIMARY KEY (post_id))';

    if(mysqli_query($dbc, $sql)===True)
    {
    echo'Table "forum" created successfully';
    }
    else
    {
    echo 'Error Creating table:'.mysqli_error($dbc);
    }
    mysqli_close($dbc);
    ?>

  14. What column?

    It was Post_id, so either way it doesn't work. The php pages don't display anything, I copied from the book, so not sure what is going on here. The book is from the series by Mike Mcgrath php 7 in easy steps.

    As for the index.html, what is that about? forum.php should load without the need for a db?

  15. I created the files, except for the last which is called process.php, the tutorial uses a localhost, so not sure if these files would work fine on any host. The forum.php, nothing does display.

    It displays an index.html, but there is no step on that, require.php outside of a includes folder along with index.html, and before that htdocs which is on any free host or paid host, and that has connect_db.php

    includes contains a header.html, and footer, as well css file.

     

    I also tried to create the table in the database. So I can't create the table manually or using the page create_forum, nothing loads for that either.

    Quote

    Error

    SQL query:

    CREATE TABLE `epiz_22739806_text`.`forum` (

    `id ` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
    `first_name` VARCHAR( 20 ) NOT NULL ,
    `last_name` VARCHAR( 40 ) NOT NULL ,
    `subject` VARCHAR( 60 ) NOT NULL ,
    `message` TEXT NOT NULL ,
    `post_date` DATE NOT NULL ,
    PRIMARY KEY ( `id ` )

    ) ENGINE = MYISAM ;

     

     

     

    MySQL said: Documentation

    #1166 - Incorrect column name 'id '

     

  16. No,  but this example in the book won't create a table, unless it means out the sql instructions in the page? I doubt it. I've continued with making the php files, still have to finish step 5 of one, forum.php or create_forum.php

     

  17. I have a copy of Php 7 a basic book on creating php files, this is a basic forum page where the following will be sent to a db.

    I'm just doing what the book has shown.

    I decided to just try this, as the other book Learning Php doesn't make much sense to me, and I can't get anything done for free what I'm trying to get working, a user login system, post comments and so on. By trying out the chapter in the easy book, I hope to use that as a stepping stone for a user to post comments on their own profile index page.

    Page 162 creating a forum, so it states

     

    require.php

    <?php
    require ('/connect_db.php');
    if (mysqli_ping($dbc))
    {
    echo 'MySQL Server', mysqli_get_server_info($dbc)
    'on', mysqli_get_host_info($dbc);
    }
    <?php
    require ('/connect_db.php');
    if (mysqli_ping($dbc))
    {
    echo 'MySQL Server', mysqli_get_server_info($dbc)
    'on', mysqli_get_host_info($dbc);
    }

    connect_db

    Then the step two of the forum chapter, assign SQL so then the following in my first post.

    Then states after now add a test report, whether the table was created successfully or describe the error on failure

    if(mysqli_query($dbc, $sql)=== TRUE)

    {

    echo 'table "forum" created successfully and so on.

  18. CREATE DATABASE accounts;

    CREATE TABLE `accounts`.`users`
    (
        `id` INT NOT NULL AUTO_INCREMENT,
        `first_name` VARCHAR(50) NOT NULL,
         `last_name` VARCHAR(50) NOT NULL,
        `email` VARCHAR(100) NOT NULL,
        `password` VARCHAR(100) NOT NULL,
        `hash` VARCHAR(32) NOT NULL,
        `active` BOOL NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`)
    );

    This is from an example php files i have, this works, without the db section. Why wouldn't the book example work, I am using a free web host, but that shouldn't matter.

    Quote

    CREATE TABLE .`forum`
    (
        `id` INT NOT NULL AUTO_INCREMENT,
        `first_name` VARCHAR(50) NOT NULL,
         `last_name` VARCHAR(50) NOT NULL,
        `first_name VARCHAR(20) NOT NULL,
        `subject VARCHAR(60) NOT NULL,
        `message TEXT NOT NULL,
        `post_date DATETIME NOT NULL,
    PRIMARY KEY (`id`)

     

    I tried this,

    Quote

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'subject VARCHAR(60) NOT NULL, `message TEXT NOT NULL, `post_date DATET' at line 6

     

  19. I now get this from your sql table code

    Quote
    #1060 - Duplicate column name 'first_name'

    The example I used was from a book, which is a beginners book for php 7.

    Thanks.

  20. Hi,

    This error is given when I try to create a table for a db.

    $sql='CREATE TABLE IF NOT EXISTS forum('
    'post_id INT UNSIGNED NOT NULL AUTO_INCREMENT,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'last_name VARCHAR(40) NOT NULL,'.
    'first_name VARCHAR(20) NOT NULL,'.
    'subject VARCHAR(60) NOT NULL,'.
    'message TEXT NOT NULL,'.
    'post_date DATETIME NOT NULL,'.
    'PRIMARY KEY (post_id))';
    Quote

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$sql='CREATE TABLE IF NOT EXISTS forum(' 'post_id INT UNSIGNED NOT NULL AUTO_IN' at line 1

    Thanks.

×
×
  • Create New...