Jump to content

Html

Members
  • Content Count

    533
  • Joined

  • Last visited

Community Reputation

7 Neutral

About Html

  • Rank
    Invested Member
  • Birthday 03/17/1989

Profile Information

  • Gender
    Male
  • Location
    Greater London
  • Interests
    Trying php.

Recent Profile Visitors

15,371 profile views
  1. 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 ) ; ?>
  2. 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 ) ; ?>
  3. 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.
  4. <?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.
  5. Well I'd like to store them in the directory that is where the files are, may be in images folder, I have one already, it is setup from the example files, that is images/file.jpg is.
  6. <?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" ;
  7. 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.
  8. Right okay, that has worked, so the example of having an image uploaded, does this mean that it goes within the main folder of the files? Thank you.
  9. 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? I just got this idea from the other day while viewing the files, so I'm all over the place with this.
  10. 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: #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?
  11. 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.
  12. Why imageurl? I got the idea from the /images/file.png table of the cart. 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.
  13. 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 );
  14. 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.
  15. Html

    Remove data

    # 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 ) {
×
×
  • Create New...