Jump to content

hugeness

Members
  • Posts

    33
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

hugeness's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hello i have a frightening mash up of a database for users.. due to my inability and due to having to run on a Joomla CMS (makes simple php tricky) because of this, i have one form that inserts new records rather than updating existing ones.. the only way i can see to work around this is to run a regular housekeeping cron job on the table to delete any record where a user has more than one record, by whichever is oldest (the table is timestamped) so far i have something like DELETE * FROM tablename ORDER BY timestamp ASC LIMIT 5; this will delete the previous 5 records.. but thats not neat enough for the table, how do i do a count then delete all but the newest one? thank you
  2. ahhh... i did the $last2ID = mysql_insert_id(); echo $last2ID; on the previous page, where the bulk of the form was inserted into the database, then passed the id as a variable in the session, fixing it for that user.. the main page where the graphic is uploaded as an update, then displayed..... <?php $_SESSION['last2ID']= $_POST['last2ID']; $_SESSION['othf']= $_POST['othf']; ****lots of variables passed in the session....**** $_SESSION['ts15']= $_POST['ts15']; $_SESSION['ts16']= $_POST['ts16']; $_SESSION['ts17']= $_POST['ts17']; $ts7=serialize($_POST['ts7']); //takes the data from a post operation... $ts8 = $_POST['ts8']; $last2ID = $_POST['last2ID']; $ts9 = $_POST['ts9']; $ts10 = $_POST['ts10']; $ts11 = $_POST['ts11']; $ts12 = $_POST['ts12']; $ts13 = $_POST['ts13']; *****etc etc variables carried from last page...***** $off_yn = $_POST['off_yn']; $off_more = $_POST['off_more']; $ts5 = $_POST['ts5']; *****the script to update the row where all the stuff above has just been added to the database... this is updating in the right place..***** //upload file/logo if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } // connect to db include '..database include.php'; $query = ("update $table1 SET name = '$fileName', size = '$fileSize', type = '$fileType', content ='$content' where id = $last2ID"); mysql_query($query) or die('Error, query failed'); } $tc4 = $tc1.'<br/> '.$tc2.'<br/> '.' '.$tc3; ?> <html><head><title>Upload Logo</title> <style type="text/css"> *****style sheet************</style></head> <body><div id="main"> <p>The following information was successfully added to our database ... please take a few moments to review and update as necessary:</p> <h3>Registration information created:<?php echo $cre; ?> <?php echo $last2ID; ?></h3> ********echo $last2ID correctly pulling out the id number of the row for this dataset*********** <p>File<?php echo $fileName ; ?> uploaded</p> <p>Your Username is <?php echo $un; ?> and your password is <?php echo $pw; ?>.</p> <p>You are: <?php echo $fn; ?><?php echo $ln;?>, <?php echo $ttl; ?></p> <p>Username: <?php echo $un; ?>, password: <?php echo $pw; ?></p> <p>Phone number: <?php echo $tel; ?></p> <p>Your email: <?php echo $conteml; ?></p> ***************details*********** <h3>Geographics</h3> <p>Do you focus Nationwide?:<?php echo $nw; ?></p> *************where the logo is displayed as they uploaded it to check*************** <p>Your logo:</p> *************pulling the graphic from the database********************** <p><img src="showimage.php?image_id=<?php echo $row['content']; ?>" /></p> bunch of hidden variables to pass to next page <input type="hidden" name="tst1" value=" $tst1"> <input type="hidden" name="tst2" value=" $tst2"> <input type="hidden" name="tst3" value=" $tst3"> <input type="hidden" name="tst4" value=" $tst4"> <input type="hidden" name="tst5" value=" $tst5"> <input type="hidden" name="tst6" value=" $tst6"> <input type="hidden" name="nw" value=" $nw"> <input type="hidden" name="pr" value=" $pr"> <input type="hidden" name="ps1" value=" $ps1"> <input type="hidden" name="ps6" value=" $ps6"> <input type="hidden" name="ps16" value=" $ps16"> <input type="hidden" name="ps26" value=" $ps26"> <input type="hidden" name="ps46" value=" $ps46"> <input type="hidden" name="ps100" value=" $ps100"> <input type="hidden" name="cent1" value=" $cent1"> <input type="hidden" name="cent6" value=" $cent6"> <input type="hidden" name="cent16" value=" $cent16"> <input type="hidden" name="cent26" value=" $cent26"> <input type="hidden" name="cent46" value=" $cent46"> <input type="hidden" name="cent100" value=" $cent100"> </form> </body> </html> the showimage.php page... <?php // connect to db include '..database include.php'; //$row = mysql_fetch_array(mysql_query("SELECT * FROM duplicate where id='24';")); when the row is set to id 24, the script works.. $row = mysql_fetch_array(mysql_query("SELECT * FROM duplicate where id='$last2ID';")); //this doesnt appear to be finding the variable header("Content-type: image/jpg"); ?>
  3. OK.. so now i have grabbed the row ID using $rowID=mysql_insert_id(); so i have the auto increment id for the row, this means no mixup when adding graphics, and i'm now using the same table, just simpler for me, shouldnt be too much overhead.. only going to have a few hundred users total.. passing all the form data on to the page where the graphic gets uploaded in a session.. so, i should now be able to upload the graphic to the same row, using the same table... as an update, and i can, this works.. however, when i try to select the row using "SELECT * FROM table where id='$rowID'; in the include page showimage.php the query doesnt work.. if i put the row number in, 24, then the query works. and if i lift the query out of the include page (leaving the header info) and put it on the main page i get the hex code... so it seems the include page cannot get a handle on the variable $rowID. how can i resolve this?
  4. Ahh, thanks for that.. so just to clear it for me, LAST_INSERT_ID() will select the last primary id for the existing session, so even if others are updating the database at the same time, that user will be editing the same record set? will have another go modifying the code...
  5. ok.. so this is what i did, i built the include page... cutting the code from the main page... showimage.php $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('minisite',$conn) or trigger_error("SQL", E_USER_ERROR); $row = mysql_fetch_array(mysql_query("SELECT * FROM upload ORDER BY id DESC LIMIT 1;")); header("Content-type: image/jpg"); print $row['content']; and inserted the code suggested with a little edit.. as suggested.. in the main page.. <p><img src="showimage.php?image_id=<?php echo $row['content']; ?>" /></p> worked like a dream.. thanks a million! le goodstuff.
  6. yep, only i'm not outputting the image with a reference, i am downloading it from the database.. the graphic is in the database as hex code.. not referenced as a URL. thanks though, i always love that site!
  7. Thanks for that... got the image to display after upload.. this is a form review page, where the user checks the details that they have put in, including the graphic and text.. at the moment i can only get either the text, OR the graphic to display, but not both.. again i assume this is a header issue.. i have looked around a lot, but so far can only glean that there is a way to get both to work using an include file, but not seen enough detail to work out what is going on.. here is my somewhat messy but basically functional code.. <?php $_SESSION['othf']= $_POST['othf']; $_SESSION['newRight']= $_POST['newRight']; $_SESSION['un']= $_POST['un'];............................ passing the variables from the previous page.. all works ok ..............$off_yn = $_POST['off_yn']; $off_more = $_POST['off_more']; $ts5 = $_POST['ts5']; //upload file/logo if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('minisite',$conn) or trigger_error("SQL", E_USER_ERROR); $query = "INSERT INTO upload (name, size, type, content,pw,un ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content','$pw','$un')"; mysql_query($query) or die('Error, query failed'); //include '../library/closedb.php'; } $row = mysql_fetch_array(mysql_query("SELECT content FROM upload WHERE id = LAST_INSERT_ID() ")); header("Content-type: image/jpg"); print $row['content']; <!-- NOTHING SHOWS BELOW THIS POINT --> $tc4 = $tc1.'<br/> '.$tc2.'<br/> '.' '.$tc3; ?> have tried this next part echoed out as a php string, no success.. <html><head><title>Upload Logo</title> <style type="text/css"> a { color: #e16500; } STYLE SHEET BITS HERE </style></head> <body><div id="main"><p>The following information was successfully added to our database ... please take a few moments to review and update as necessary:</p> <h3>Registration information created: $cre </h3> <p>File $fileName uploaded</p> <p>Your Username is $un and your password is $pw.</p> <p>You are: $fn $ln, $ttl</p> LOTS OF MIXED HTML AND VARIABLES ...... ype="hidden" name="ts7" value=" $ts7"> <input type="hidden" name="ts5" value=" $ts5"> <input type="submit" input id="update" value="Click here to update your details" > </form> </body> </html> anyone know of any good examples for this setup? also.. have seen an example which again i dont quite understand, but could work for me.. instead uploading the graphic converted to base64.. does anyone know if this method works around the conflict displaying a blob and text appears to have? heres an example of converting to base64.. http://www.tutcity.com/view/image-databasing.9514.html thank you!
  8. Hi I am using the following code... $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('minisite',$conn) or trigger_error("SQL", E_USER_ERROR); $id = 1; $type = $row['type']; header('Content-type: $type'); $query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'"); //line 21 -> while($row = mysql_fetch_array($query)){ $content = $row['content']; echo $content; } adapted, just to try and experiment and get started with showing an image stored as a blob in my database.. Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\ggg\My Documents\php\xampp\htdocs\minisite\graphic_test1.php:1) in C:\Documents and Settings\ggg\My Documents\php\xampp\htdocs\minisite\graphic_test1.php on line 17 GIF89a–÷ÿ‰Œ”©­¹¡¥´’•¢jkrøùú+()ƒŒ•™¤ÁÅÓ¡«ÑÕᚊ™424¥©µïðóðòõ¹½Ê etc etc if anyone can move me on a bit, would be great! thank you.
  9. you could try this one... http://forum.codecall.net/php-tutorials/7663-tutorial-storing-images-mysql-php-part-ii-display-your-images.html
  10. It has a value of 'truncate' now.. but yes, the result is outputted in my last post.
  11. Thanks for that, interesting stuff... so adding the session_start() to my test page kicked off a warning, does this mean globals are set to 'on' and i need to turn them off? so lets presume i tackle the error message... (using xampp latest so not sure why globals should be on). page 1 would be session_start() form submit = post page2 would be session_start() $_SESSION['variable_n']= $_POST['variablen']; $'variable_n = $_POST[''variable_n']; utilize variables etc.. page 3 session_start() would i need to copy all the $_SESSION['variable_n']= $_POST['variablen']; $'variable_n = $_POST[''variable_n']; again? is that kind of the whole end result of disabling globals? that this stuff doesnt get passed automatically? thank you, just trying to understand whats going on. lastly, is this format still valid? if (!$id) { header("Location: http://site.com/book/pick_modcontact.php"); exit; } else { session_start(); } if ($valid != "yes") { header("Location: http://site.com/resource/admin/admin_menu.php"); exit; } else { session_register('valid');
  12. Hello I have been out of the loop with PHP for about 6 years, even then my knowledge was basic.. i have been looking for the correct way to pass variables over pages using sessions, but the tutorials out there appear really mixed up on the use of session_start() and gobals and stuff like that.. could anyone recommend a definitive tutorial for 2009 that i can make a start on applying to my pages? i have about 40 variables i need to share over pages.. I've just added session_start() to a page to test it, and am now getting the following message Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 thanks!
  13. That actually works, it selects the one row in the table... Showing rows 0 - 0 (1 total, Query took 0.0003 sec) d name type size content pw un Edit Delete 1 ellie2.gif image/gif 10615 [bLOB - 10.4 KiB] truncate truncate
  14. SELECT * FROM `duplicate` WHERE un = 'jjokoja' LIMIT 0 , 30 Showing rows 0 - 0 (1 total, Query took 0.0005 sec) so that worked fine. but the second table, upload, wont work! very strange! why would a table with the same setup for the same two columns fail a simple select? SELECT * FROM `upload` WHERE un = 'jjokoja' MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec )
×
×
  • 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.