Jump to content
Larry Ullman's Book Forums

Dark Prince

Members
  • Posts

    62
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Dark Prince

  1. Ok I'll try to explain this without making it nonsense... first the ID is unique for all the files uploaded and that ID is also the files new name in the uploads directory so it is a raw file with its ID as its name, now its actual name with extension is stored in the uploads database table. now the rest of the information that is not a file is stored in a main table with its files ID's that were uploaded with it so when I call a row I can see which files were uploaded to that row. so I'm displaying all that information in an html table so everything is displayed fine. But I need to take the first files ID in everyrow and display it as a thumbnail in the html table but every table row is going to have a different file id because its uploaded files are different from the next row in the database(like on this site if you goto members it will show all the members and the second column is a picture) i'm trying to do something very similar except the files are stored as its ID not as the original file that way a file that has the same name as another can exist in the same upload directory. why in my while loop for the images row I do the files information query then clear the result so the next row in the loop can call the information for its own files. but because the files name is changed to its ID I need to take that file and make it a temporary file with its orginal name and extension so it can be called like that in the <img src="$file"> so I need $file to be defined as the original file using the raw file in the uploads directory and the files original name and extension from the uploads table in the database, now in Larry's second edition he had a script that called the that raw file which was just an ID for a name and used the information entered into the database for it to download the file in its original form. I don't want to download the file I want to display it in a html table.
  2. The main problem is when the file is uploaded I use mysqli_insert_id so a file with the same name as another can be uploaded so all my uploaded files are files without extension or name, that is stored in the upload table So if there is no easy way to do this, how would I take that raw file out of my uploads directory and load it as a temporary file with the file name from the uploads table then display that tempory file as the image source? I gave my 2nd edition book to my friend and I used the file upload system from that books examples. now in the 3rd edition it doesn't have the same example where it takes multiple file uploads at once and stores them as a mysql id in the directory then the name in the uploads table.
  3. yes image_name is the original file name with extension. and yeah I'm on xp home and the and I believe I am using forward slashes because backslashes don't work in windows? because all my other scripts using uploads use forward slashes and work like these /, what I need to do is turn the imageid from the databases main table which fills the rest of the page table, the image id is stored in that table now that id links to the image id in the uploads table that has the name with extension and the type of file that it is. so I need to take the image id from the databases main table to display the image from the uploads directory using the image information in the uploads table. so in my uploads directory everthing is stored as a unique integer with no extensions or anything there information is stored in the uploads table with again a unique integer for an id that is stored to its corresponding row in the databases main table.
  4. aaahhh ok still getting the failed to login message for if ($u && $p) { $q = "SELECT userid, username, email FROM users WHERE (username='$u' AND password=SHA1('$p')) AND active=null"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br/>MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 1) { $_COOKIE = mysqli_fetch_array ($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'index.php'; ob_end_clean(); header("Location: $url"); exit(); } else { echo '<p class="error">You have entered and incorrect password or the user name does not exist or has not yet been activated.</p>'; } now I've checked the username and password and they are right and active=null in the database, the problem is in the query where it is AND active=null, without that line it works and redirects back to the main page.
  5. Yeah I've looked through that chapter but my setup is different and I don't want to show the images in another window but in a table row inside a table this is what I got but I'm stuck on getting it to display the image still ... in my uploads table the image is stored as a mysqli_insert_id when it is uploaded. this is my upload table imageid int(10) unsigned not null auto_increment image_name varchar(255) not null image_type varchar(6) not null primary key (imageid) now inside my while loop for the table I have this, I have cut out all the other table rows because they all work. $dir = 'D:/phpul/'; echo '<td align="left">'; $queryi = "SELECT image_name FROM uploads WHERE (imageid='$row[image1]')"; $resulti = mysqli_query ($dbc, $queryi); $rowi = mysqli_fetch_array($resulti, MYSQLI_ASSOC); $imageid = $row['image1']; $imagename = $rowi['image_name']; echo '<img src="' . $dir . $imagename . '"/></td></tr>'; mysqli_free_result ($resulti); } echo '</table>'; mysqli_free_result ($result); mysqli_close($dbc); what I need to do is take that imageid from my first query that returns the indexes for the other table rows and call the image by its ID for every row then convert it to a workable image source using the image query $queryi, so far it just shows the icon for an image type inside its colum on the table row, I know it would be easier to just store the image in the upload directory as its original file name without mysqli_insert_id because it would be saved in its proper type but then it will be replaced by another other file with the same name so I need to use mysqli_insert_id. when I debug it, it shows it is getting the file name from the $queryi now how can I use that in the <img src=""/> when its name is only stored in the database but the file in the upload directory is just an integer without an extension? this is part of the script that adds the file to the uploads table if (isset($_FILES['i1']) && ($_FILES['i1']['error'] != 4)) { $queryi1 = "INSERT INTO uploads (image_name, image_type) VALUES ('{$_FILES['i1']['name']}', '{$_FILES['i1']['type']}')"; $resulti1 = mysqli_query ($dbc, $queryi1); if ($resulti1) { $idi1 = mysqli_insert_id($dbc); move_uploaded_file($_FILES['i1']['tmp_name'], "D:/phpul/$idi1"); } } else { $idi1 = "NULL"; } there are 6 more like this because the script takes upto 6 uploads. but in the script I'm working on the page only needs to display the first image added but these 6 values are stored in the main table as $idi1 through $idi6 as image1 through image6 which you can see is how I get the imageid in my first query for $row['image1'] which returns as an integer referring to the file in the uploads directory as that same integer. would it be simpler to make a tempory file out of the one that is stored in the uploads directory if that is possible?
  6. Actually asked this wrong because every row will call a different file ID I need to put an image element in the tablerow where image1 is the $row['image1'] has the ID number from the uploads table I need to add type from that table a's well but the rest of my table rows are called from a nother database table
  7. hey its me again guys I'm getting frustrated, I need to post a thumbnail into a table using the while loop and $row now the query calls from one table that stores the files id number from the uploads table how would I get it to display the file which is an image type in a thumbnail. pretty much need too know how to define the image from the uploads for the table while getting the image id from another table. and then to display it using the while loop so far this is what I have. image1 is in another table stored as an ID number only <td align="left">' . $row['image1'] . '</td> it will display the images id number I need to get the file and type from the uploads table then thumbnail it. sorry for the vagueness but its 4:20 am and I'm past tired. so I would need to do something like this I would make a query that calls the information from the uploads table first then run this? $image1 = $row['image1'].$row['type']; ??? would that define $image1 as id.type? then how would I thumbnail it in the table row? i know html is not part of this forums topics but I just want to get past this prick in my neck... if you need any other info just ask.
  8. Haha told you I was a beginner I knew something was 32 characters but regardless thank you so much
  9. Ok guys the problem is in the database, I've run multiple select queries they all turn up empty when I include the password column but if I select other columns from the row without apending the password column to the where clause. (edit) it returns a result (edit) Could this be from using char instead of varchar? maybe because of the encryption of sha1 if its char sha1 uses a 32 character salt would it need an extra character like char(33)?
  10. I think i figured it out in the chapter 16 the database scheme larry put key (email, pass) I didn't put that key so in the query he had WHERE (email='$e' and pass=SHA1('$p')) since I didn't key my username and password my query should be WHERE username='$u' and password=SHA1('$p') pretty sure thats it I won't be able to check until I get to my laptop. maybe some insite on it before I get home I don't know if this is the cause it just struck me when I was reading through my post.
  11. Ok I commented all the code after the if ($u && $p) upto the mysqli_close and changed the if ($u && $p) { to if ($u && $p) { echo "$u $p" ; } and it did echo the values at the top of the page so its not failing that test...
  12. I'm still at a beginner level of programming with php and mysql but I do have an understanding of how the language works. I keep getting my error message when trying to log in "You have entered and incorrect password or the user name does not exist or has not yet been activated." here is the login.php script <!-- <?php # login.php require_once ('includes/config.php'); if (isset($_POST['submitted'])) { require_once (MYSQL); if (!empty($_POST['username'])) { $u = mysqli_real_escape_string ($dbc, $_POST['username']); } else { $u = FALSE; echo '<p class="error">You did not enter a user name.</p>'; } if (!empty($_POST['password'])) { $p = mysqli_real_escape_string ($dbc, $_POST['password']); } else { $p = FALSE; echo '<p class="error">You did not enter a password.</p>'; } if ($u && $p) { $q = "SELECT userid, username, email FROM users WHERE (username='$u' AND password=SHA1('$p'))"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br/>MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { $_COOKIE = mysqli_fetch_array ($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'index.php'; ob_end_clean(); header("Location: $url"); exit(); } else { echo '<p class="error">You have entered and incorrect password or the user name does not exist or has not yet been activated.</p>'; } } else { echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } $page_title = 'Connect User Name With The Site'; include ('includes/header.php'); ?> <div id="login"> <h1>Login</h1> <fieldset> <form action="login.php" method="post"> <p><b>User Name:</b> <input type="text" name="username" size="20" maxlength="40"/></p> <p><b>Password:</b> <input type="password" name="password" size="20" maxlength="32"/></p> <input type="submit" name="submit" value="Go!"/> <input type="hidden" name="submitted" value="TRUE"/> </form> </fieldset> <?php include ('includes/footer.html'); ?> --> the config file is the same as in the chapter. I have checked the users table in the correct database the username is correct and so is the password by calling a select to match to the password and it returns the user. this is my header file <!-- <?php # header.php ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $page_title; ?></title> <link rel="stylesheet" href="includes/style.css" type="text/css" media="screen"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <div id="header"> <h1>Welcome To Site</h1> <h2>Simple Logo.</h2> </div> <div id="navigation1"> <ul> <li><a href="login.php">Login</a></li> <li><a href="index.php">Home</a></li> <li><a href="browse.php">Browse</a></li> <li><a href="signup.php">Sign Up</a></li> </ul> </div> <div id="adblock"> <ul> <li>Advertise Here</li> <li>Advertise Here</li> <li>Advertise Here</li> </ul> </div> <div id="content"> --> footer file closes remaining tags and includes the ob_end_flush() function I've re-written the script multiple times and even tried using the scripts from chapter 11 and still get a similar error, its as if its ignoring the input fields from the forms. If anybody has some insight to my problem any help is very much appreciated if it is any help this is my table setup for users ( userid int(10) unsigned not null auto_increment, email varchar(90) not null, password char(32) not null, username varchar(40) not null, active char(32), registrationdate datetime not null, primary key (userid), unique key (email), unique key (username), ) would using char instead of varchar for the password column cause a problem with the validation process, I know char will fill in the rest of the assigned characters with blank spaces but should be removed when it is called. also I took out the and if active=null part of the query thinking that could of been a problem still didn't help.
×
×
  • Create New...