grozanc Posted March 8, 2008 Share Posted March 8, 2008 Hello All, I have a script that lets people go back and edit an upload to my site. The path of the file isn't getting dumped into the database. There are three php files that do the work. It works fine for the original upload, but the variable ($id primary id that points to the record in the database) gets lost in the version where they do the edit. I've manually entered the variable and it puts the path to the file into the database. I'm including the script for all three pages. The variable isn't getting passed properly to the third script. If anyone can point me in the right direction, I'd appreciate it! Code for Form: <form action="edit_videoscript.php " method="post" enctype="multipart/form-data" name="uploadform"> <font class="forms">First Name:<br> <input type="text" value="<?=$row['first_name']?>" name="first_name" id="first_name" class="story"/> <br><br> E-Mail:<br> <input value="<?=$row['email']?>" type="text" name="email" id="email" class="story"/> <br><br> <a href="javascript:openCityStatePhotoWindow();" class="linkpopup">City & State:<br></a> <input value="<?=$row['city']?>" type="text" name="city" id="city" class="storycity"/> <? include 'library/state1edit.php'; ?> <br><br> <a href="javascript:openLinksWindow();" class="linkpopup">Web Link:<br></a> <input value="<?=$row['link']?>" type="text" name="link" id="link" class="story"/> <br><br> <a href="javascript:openVideoWindow();" class="linkpopup">Video:<br></a> <input name="userfile" type="file" id="userfile" class="storyphoto"> <br><br> <a href="javascript:openCaptionVideoWindow();" class="linkpopup">Video Caption:<br></a> </font> <textarea name="caption" id="caption" wrap="hard" class="storycaption"><?=$row['caption']?></textarea><br> <br><br> <input type="hidden" name="thanks" value="7"> <input type="hidden" name="id" value="<?=$row['id']?>"> <input name="upload" type="submit" id="upload" value="Upload" class="storybtn" onClick="YAHOO.example.container.wait.show();"> </form> Code for the script that starts the upload and puts all but the path into the database <?php $host = 'localhost'; $user = 'xxxxxx'; $pass = 'xxxxxx'; $db = 'xxxxxx'; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); // Set variables $hasPortrait = false; if ($_FILES['userfile']['name'] != "") { $hasPortrait = true; } if (!$hasPortrait) { // Set variables $id=$_POST['id']; $first_name = $_POST['first_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $link = $_POST['link']; $caption = $_POST['caption']; $thanks = $_POST['thanks']; // Insert into database $query = "UPDATE uploads_content SET first_name = '$first_name', email = '$email', city = '$city', state = '$state', link = '$link', caption = '$caption', approved = '0' WHERE id = '$id' "; mysql_query($query) or die('Error, query failed : ' . mysql_error()); if($query) {header( "Location: http://www.pavementmemories.com/thanks.php?first_name=$first_name&thanks=$thanks" );} else {header( "Location: http://www.pavementmemories.com/oops_contact.php" );} } else { $temp_video = '/home/grozanc/public_html/pavementmemories.com/videos/temp/'; $video_processor = '/home/grozanc/public_html/pavementmemories.com/process_video2.php'; if(isset($_POST['upload'])) { $first_name = $_POST['first_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $link = $_POST['link']; $caption = $_POST['caption']; $thanks =$_POST['thanks']; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // generate the random file name $randName = md5(rand() * time()); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } if( is_uploaded_file($_FILES['userfile']['tmp_name']) ) { $newfile = $randName . '.' . $ext; move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_video . $newfile); } $cmd = '/usr/bin/php ' . $video_processor . ' "' . $temp_video . $newfile .'" ' . $randName . ' ' . $insert_id; proc_close( proc_open( $cmd . " >> /home/grozanc/public_html/logs/videoprocess.log &", array(), $foo ) ); //exec('/usr/bin/php ' . $video_processor . ' "' . $temp_video . $newfile .'" ' . $randName . ' ' . $insert_id .' &', $out,$rval); file_put_contents('/home/grozanc/public_html/logs/videocommands.log',"\n" . $cmd,FILE_APPEND); //header("Location: http://www.pavementmemories.com/thanks.php"); //exit; $first_name = str_replace("'","’",$first_name); $city = str_replace("'","’",$city); $caption = str_replace("'","’",$caption); $query = "UPDATE uploads_content SET first_name = '$first_name', email = '$email', city = '$city', state = '$state', link = '$link', caption = '$caption', name = '$fileName', approved = 0, featured = 0 WHERE `id` = '{$id}' "; mysql_query($query) or die('Error, query failed : ' . mysql_error()); $insert_id = mysql_insert_id(); include ( "thanks.php" ); exit; } } ?> This last script gets called from the previous one to process the upload and isn't getting the $id variable in the query. If I enter an id of an existing record instead of the $id, it runs the update. <?php require_once('xxxxxx'); $id=$_GET['id']; $base_dir = '/home/grozanc/public_html/'; $web_dir = $base_dir . 'pavementmemories.com/'; $log_dir = $base_dir . 'logs/'; $videos_dir = 'videos/'; $sample_rates = array(44100, 22050, 1102); $ffmpeg_binary = "/usr/bin/ffmpeg"; $flvtool2 = "/usr/bin/flvtool2"; $width = '320'; $height = '240'; $srcfile = $argv[1]; $destfile = $videos_dir . $argv[2] . '.flv'; $fulldest = $web_dir . $destfile; $ffmpegObj = new ffmpeg_movie($srcfile); $srcFPS = $ffmpegObj->getFrameRate(); $srcAB = intval($ffmpegObj->getAudioBitRate()/1000); $srcAR = $ffmpegObj->getAudioSampleRate(); if( !in_array($srcAR,$sample_rates) ) $srcAR = 44100; //exec($ffmpeg_binary . ' -i ' . $srcfile . ' ' . $destfile . " | " . $flvtool2 . " -U stdin " . $destfile,$output,$retval); $vid_command = $ffmpeg_binary . " -i " . $srcfile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $width . "x" . $height . " " . $fulldest; file_put_contents($log_dir . 'ffmpegcmd.log', "\n" . $vid_command, FILE_APPEND); exec($vid_command,$output,$retval); /* echo "Ret Val: $retval<br>"; echo "<pre>"; print_r($output); echo "</pre>"; */ $logdata = date("m-d-Y") . "\n" . var_export($output,true) . "\n\n"; file_put_contents($log_dir . 'videooutput.log', $logdata,FILE_APPEND); $destfile = $_POST['path']; mysql_query(" UPDATE uploads_content SET video_processed = 1, path = '$destfile' WHERE `id` = '$id' "); echo mysql_error(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/ Share on other sites More sharing options...
deansatch Posted March 9, 2008 Share Posted March 9, 2008 assuming your third page is thanks.php, add a bit to this line in script 2 include ( "thanks.php" ); to: include ( "thanks.php?id=$id" ); Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487342 Share on other sites More sharing options...
grozanc Posted March 9, 2008 Author Share Posted March 9, 2008 I tried passing the variable through the link, but since it is an include and not a redirect it wouldn't work. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487359 Share on other sites More sharing options...
darkfreaks Posted March 9, 2008 Share Posted March 9, 2008 you should use header instead of include Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487370 Share on other sites More sharing options...
grozanc Posted March 9, 2008 Author Share Posted March 9, 2008 I tried to use the header instead of include, but since this is several parts of different code and I'm a newbie, I couldn't get this upload code to work if I used a header instead of the include. Anyone else have any ideas! Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487400 Share on other sites More sharing options...
uniflare Posted March 9, 2008 Share Posted March 9, 2008 i have not read through your entire code but guessing from the responses already could you not just get rid of "$id=$_GET['id'];" line entirely? Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487407 Share on other sites More sharing options...
grozanc Posted March 9, 2008 Author Share Posted March 9, 2008 I tried removing the $id=$_GET['id']; as well. It didn't work and I have no idea why?! Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487414 Share on other sites More sharing options...
uniflare Posted March 9, 2008 Share Posted March 9, 2008 hmmm, strange, what file are you including at the top? instead of removing the line try replacing it with: $id=$_POST['id']; hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487428 Share on other sites More sharing options...
grozanc Posted March 9, 2008 Author Share Posted March 9, 2008 I'm trying to include the last of the three pieces of code into the second. I also tried posting the id and that didn't work either. It's frustrating, that it works when you simply upload a new file but it doesn't when you edit and old upload unless I use the actual primary id instead of having the variable pass. Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487435 Share on other sites More sharing options...
grozanc Posted March 9, 2008 Author Share Posted March 9, 2008 Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487783 Share on other sites More sharing options...
uniflare Posted March 9, 2008 Share Posted March 9, 2008 try echoing/printing the id at various parts in your code and see where it goes missing. Quote Link to comment https://forums.phpfreaks.com/topic/95124-variable-wont-pass/#findComment-487925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.