Jump to content

Html

Members
  • Posts

    640
  • Joined

  • Last visited

Posts posted by Html

  1. 14 hours ago, justsomeguy said:

    Like I said, the opening bracket before require does not have a closing bracket, and you're missing a semicolon.  I am not talking about parentheses, I'm talking about curly brackets.

    Your computer does not have a finite supply of newline characters, format your code so that it's easy to read.  There's no prize for having the fewest lines of code.

    
    if (!isset($_SESSION['user_id'])) 
    { 
      require('login_tools.php'); 
      load()

    What is missing from this picture?  It should be pretty obvious.

    I removed the curly brace and there was no error reported in the php checker

  2. I've not messed with any of the files, you stated yourself I lacked basics, and get going around in circles. If I can get through this example, I may try doing a php 7 and what ever variation of it as a login system. I'm using this dated stuff because it is what is there, and complete, and somehow needs a few tweaks to it.

  3. Everything I have is from the Source files, I just viewed one file, and got the idea to put these bits of code together. So I don't know the ins and outs, but I thought I was onto something by doing this, I tried this before, but I don't remember what I did or perhaps I did this before, I don't recall now.

    I only tried remove the brace ones that made the errors go away. You have two opening braces blah blah.

  4. Ah right, that don't know about that, I am only going on from what I've seen in the core files of the login system. It is listed there, and in the register.php file dbc, q is also listed at the end after closing connection.

    {
        $q = "SELECT user_id FROM users WHERE email='$id'" ;
        $r = @mysqli_query ( $dbc, $q ) ;
        if ( mysqli_num_rows( $r ) != 0 ) ;
      }
      
      # On success register user inserting into 'users' database table.
      if ( empty( $errors ) ) 
      {
        $q = "INSERT INTO images (id, images) VALUES ('$id', '$images')";
        $r = @mysqli_query ( $dbc, $q ) ;
        if ($r)
      
        # Close database connection.
        mysqli_close($dbc); 

    Hmm, this would be better, insert, not select, that is aim.😩

    <?php
    
    # Access session.
    session_start() ; 
    
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM images WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
       echo 'File upload failed!' ; }
      
    # Close database connection.
    mysqli_close( $dbc ) ;
    ?> 

     

  5. I didn't think about that, since I haven't made any scratch made code. I have only used example code is what I am focusing on now and trying to get something working, it should work out okay, if not well worth a try.

    Okay I have corrected that, every page does have that at the top.

    As for the any more errors line 15 is the returning one.

    <?php
    
    # Access session.
    session_start() ; 
    
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM images WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
       echo 'File upload failed!' ; }
      
    # Close database connection.
    mysqli_close( $dbc ) ;
    ?> 

     

  6. Sure, I thought, yeah may be this may work, I don't remember what I didn't do the last time when I tried this. I get you're point.

    I think I messed with the files I had, and didn't do certain things with it properly.

    I got this setup, it wasn't the first user site I setup, but this is what I did so far, I run out of any credible ideas, I just made this generic. aboringsocialnetworksite.epizy.com

    I'm going to tinker with what I can, I loaded in duplicated files that were not edited, and they work, when i tried with the old files I had, I don't think I have a backup, but it was inferior in functions compared to this as the whole files. I was trying to do my own stuff with it, but it wouldn't work, the code is dated, and structured a certain way with $q as one user on here helped me with this months ago.

    But anyway, I probably made errors with the first files that caused them to stop working when I loaded them as a backup.

     

     

  7. <?php
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Access session.
    session_start() ; 
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM images WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
      { echo 'File upload failed!' ; }
    } 
    ?> 


    Okay, well nothing displays.

    <?php
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Access session.
    session_start() ; 
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM images WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
      { echo 'File upload failed!' ; }
      
    # Close database connection.
    mysqli_close( $dbc ) ;
    ?> 

    I tried removing the top curly brace

    if ( mysqli_num_rows( $r ) == 1 )
    {
    $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
     

    I removed the bottom as the code above displays, no change.

  8. <?php
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Access session.
    session_start() ; 
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM umages WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
      { echo 'File upload failed!' ; }
    } 
    ?> 

    This appears to be better, sure the same error for the $q = "SELECT * FROM umages WHERE id = $id" ;

  9. 21 hours ago, justsomeguy said:

    I see 3 syntax errors in your code that will stop anything from running, and 2 runtime errors that will cause problems if you actually get it to run.  To start with, count the opening and closing brackets.  Those should be the same number.

    Yeah, you've got several syntax errors in that too.  You've got commas where they shouldn't be, and missing commas where they should be.

     

     

    Even that has syntax errors.  You've got an opening double quote, where's the double quote to close the string?  And the SQL query in your PHP has 2 syntax errors. There's only 9 words in it.

    You really need to pay attention to this stuff.  Syntax errors stop any code from running.  And yes, adding just a single syntax error in a piece of code because you aren't paying attention means that now nothing works.

    I decided to do a check on the code. It now states the only error so far is $q, of course this is used in the code numerous times from the example files, I imagine it is key to getting anything done with any of the files.

  10. 14 hours ago, Mudsaf said:

    What you are trying to do isn't going to work with the table you just created. You need to make 3 more columns to your database table to be able to fill the rest of information in your query.

    Example scenario account information

    id int auto_increment primary key | username varchar(50) | password varchar(128) | email (varchar150) unique

    So lets pretend that the table we created with the "create table" query. So we wound have to do insert query like below.

    
    insert into accounts (username,password,email) values (value1,value2,value3)

     

    The whole point was just show where I got the whole view from. So id and images is what I need, so three, so what is the third one?

     

    3 hours ago, dsonesuk said:

    Could you please stick with single SQL statement to get that to work, instead of introducing every sql statement you find on the internet, you'll never reach your goal if you continuously move the goal posts.

    I just got this idea from the other day while viewing the files, so I'm all over the place with this.

  11. CREATE TABLE IF NOT EXISTS images (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    img VARCHAR(20) NOT NULL
    PRIMARY KEY (item_id)
    );
    INSERT INTO images
    (img)
    VALUES
    ("images")

    Error

    SQL query:

    CREATE TABLE IF NOT EXISTS images(

    id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
    img VARCHAR( 20 ) NOT NULL PRIMARY KEY ( item_id )

    );
     

     

    MySQL said: Documentation

    #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 '(item_id)
    )' at line 4

     

    I guess id alone won't work for creating a new table?

  12. I tried this,

    CREATE TABLE IF NOT EXISTS images (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    img VARCHAR(20) NOT NULL
    )
    INSERT INTO images
    (img)
    VALUES
    ("images")

    #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 'INSERT INTO images (img) VALUES ("images")' at line 5
     
    VALUES ( "Rhino", "A friendly jungle buddy.", "images/rhino.png",29.99 );
     
    This is the example from the sql file.
  13. 9 minutes ago, Mudsaf said:

    As for SQL try this

    
    CREATE TABLE IF NOT EXISTS images (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    img VARCHAR(20) NOT NULL
    )
    
    INSERT INTO images
    (img)
    VALUES
    ("imageurl")

     

    Why imageurl? I got the idea from the /images/file.png table of the cart.

     

    12 minutes ago, justsomeguy said:

    I see 3 syntax errors in your code that will stop anything from running, and 2 runtime errors that will cause problems if you actually get it to run.  To start with, count the opening and closing brackets.  Those should be the same number.

    Yeah, you've got several syntax errors in that too.  You've got commas where they shouldn't be, and missing commas where they should be.

     

     

    Even that has syntax errors.  You've got an opening double quote, where's the double quote to close the string?  And the SQL query in your PHP has 2 syntax errors. There's only 9 words in it.

    You really need to pay attention to this stuff.  Syntax errors stop any code from running.  And yes, adding just a single syntax error in a piece of code because you aren't paying attention means that now nothing works.

    Hmm, I haven't tried it, but I was thinking I doubt this would work right off what I just thought up. The cart.php file gave me the thought.

    There are six of these { on the outer part of the code.

  14. The upload is simply from a example file on how to upload a file, but I want to obviously store an uploaded image in a db, which is linked with a particular user who is logged in, so I am just guessing the above should work with these added code snippets taken from a core file. The image upload code works completely fine as is, I tried this in the past, but I didn't know what to do, so I've posted what I think is perhaps the way to get this working.

    As for the problem currently getting the table created by using the sql example, I just edited to two columns, id, and image

    CREATE TABLE IF NOT EXISTS images (
    id id UNSIGNED NOT NULL AUTO_INCREMENT
    img VARCHAR(20) NOT NULL,
    )

    INSERT INTO images
    ( id, images,)
    VALUES
    ( "id","images/")

    Something about the top just won't create. Even if I include ; after the bracket.

    As for insert, you are referring to this part?

    # Retrieve selective item data from 'images' database table. 
    $q = "INSERT * INTO images WHERE (id, images,)VALUES ('id','images');
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );

     

  15. Hi,

    I want to get this code to have some connection with a db,

    I tried to get these in the db, but it won't create, I used it from a sql example.

    CREATE TABLE IF NOT EXISTS images (
    id id UNSIGNED NOT NULL AUTO_INCREMENT
    img VARCHAR(20) NOT NULL,
    )

    INSERT INTO images
    ( id, images,)
    VALUES
    ( "id","images/")

    I want to store an uploaded image, so an id and where it would be stored. Since the code has been setup a particular way with what I am using, I'll need to add some bits from the other.

     

    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>PHP File Upload</title>
    </head>
    <body>
    <form method="POST" action="<?php $_SERVER[ 'PHP_SELF' ] ?>" enctype="multipart/form-data">
    Select an image to upload :
    <input type="file" name="image" >
    <input type="submit" value="Upload Image" >
    </form>   
    <?php
      # Open database connection.
    require ( 'connect_db.php' ) ;
      
    # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Access session.
    session_start() ; 
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()
      
      # Retrieve selective item data from 'images' database table. 
    $q = "SELECT * FROM umages WHERE id = $id" ;
    $r = mysqli_query( $dbc, $q ) ;
    if ( mysqli_num_rows( $r ) == 1 )
    {
      $row = mysqli_fetch_array( $r, MYSQLI_ASSOC );
      
    if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
    {
      $name = $_FILES[ 'image' ][ 'name' ] ;
      $temp = $_FILES[ 'image' ][ 'tmp_name' ] ;
      $size = $_FILES[ 'image' ][ 'size' ] ;
      $ext = pathinfo( $name , PATHINFO_EXTENSION ) ;
      $ext = strtolower( $ext ) ;
      if( $ext != 'png' && $ext != 'jpg' && $ext != 'gif' )
      { echo 'Format must be PNG, JPG, or GIF' ; exit() ; }  
      if( $size > 512000)
      { echo 'File size must not exceed 500Kb' ; exit() ; }
      if( file_exists( $name ) )
      { echo 'File '.$name.' already uploaded' ; exit() ; }
      try
      {
        move_uploaded_file( $temp , $name ) ;
        echo 'File uploaded : '.$name ;
        echo '<br><img src="'.$name.'">' ;
      }
      catch( Exception $e )
      { echo 'File upload failed!' ; }
    } 
    ?> 
    </body>
    </html>
    <?php # DISPLAY COMPLETE LOGGED IN PAGE.
    
    # Access session.
    session_start() ; 
    
    # Redirect if not logged in.
    if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load()

    I've added in the following, since all the files tend to have that common pieces of php, I am guessing this is the way it works. Tried in the past using what ever, and didn't work.

    I got this bit of code from added.php which is a file linked with a shop/cart system, I never viewed those example files, since I didn't need them or want to know what they were, I was only trying to use what I want and add to it, I've realised that the whole example files are structured a certain way and there isn't much bending to only break them, and they don't even work if they are backups to load into a new account. So its really try them and be stuck with them, and hope the free host doesn't vanish anytime soon.

    # Get passed product id and assign it to a variable.
    if ( isset( $_GET['id'] ) ) $id = $_GET['id'] ;

    That there is what I'd need for a profile index page. I looked further into the example files and found a actual id, name, and forum, while it wasn't any different than the Php 7 book I have from the small company that sold it, the other does contain at least what I wanted, just lacks an actual individual profile to view linked comments to a logged in user.

  16. On 3/11/2019 at 5:39 PM, Html said:

    The current code is this,

    And yes I am still on this, fortunately, I made progress with removing my header image I had on the index page, a couple of others, and replaced it with CSS code🙂 Now that is a first, I had a book years ago on that, I never understood CSS. I am trying to remember what it is called, but I can't think of it. From 2006.

    So that will save some bandwidth.

    As for the function code this is still what I have got. The videos show two different ways of doing a function, so I don't know what is wrong or right with what I have.😩

    Neither narrators responded to my query with example code.

     

    
    <?php
    # Connect to the database.
      require ('connect_db.php');
    
    # Access session.
    session_start() ;
    
    function deleteRecord(mysqli $dbc, $user_id){
    $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'";
    $result = $db->query($sql);
    if(!result){
    
    throw new Exception('Cannot  delete' );
    
         }
    }
    ?>

    That is remove.php When I click on this from the image link, only a blank screen then loads, so it doesn't work. The logged in user isn't removed from the db instantly, I will want to add a timer to three days after remove.php has been clicked.

    # Function to create and execute a MySQL query.
    function show_records( $dbc )
    {
      $q = 'SELECT * FROM watches' ;
      $r = mysqli_query( $dbc , $q ) ;
      $num = mysqli_num_rows( $r ) ;
       if ( $num > 0 )
      {

    This may be the edit the code I tried in the past requires, from an example I viewed in the files.

    function deleteRecord(mysqli $dbc, $user_id){
    $sql ="DELETE FROM 'users' WHERE id ='".$user_id."'";
    $result = $db->query($sql);
    if(!result){

     

    function deleteRecord( $dbc )
    {
      $q = 'SELECT * FROM users' WHERE id ='".$user_id."'";
      $r = mysqli_query( $dbc , $q ) ;
      $num = mysqli_num_rows( $r ) ;
       if ( $num > 0 )
      {

  17. I don't know what to do get the result. I thought that by having the code Select from email, using the the other option, what ever it is called now, I don't remember, on the previous page, https://www.w3schools.com/sql/func_mysql_isnull.asp

×
×
  • Create New...