phatgreenbuds Posted December 16, 2006 Share Posted December 16, 2006 OK well I am now completely confused. Before you go flaming me I fully admit I am a NOOB. In fact I just started learning PHP and MySQL last month. My process is simple...while I go through my book I gradually write something that emulates something I use everyday, helps me focus and apply what I am learning. So I am trying to make a ticketing/request system. The first page collects user information using the forms and posts it to the next page where it gets inserted into the database. Once on the second page I have them upload a file to that ticket entry. (This file upload is required for vendor non-disclosure etc etc). The problem is once they upload the file it acts just like a refresh and creates duplicate tickets in the database. Being so new to this I think I am approaching this wrong but do not know enough to come up with another way. Just for reference I have everything working in this including filtering and emailing and all other funtionality one would expect from a ticketing system. This is the last hurdle. How would you do it? Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/ Share on other sites More sharing options...
Cagecrawler Posted December 16, 2006 Share Posted December 16, 2006 Whats your code? Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142179 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 [code]<?phpsession_start();$con = mysql_connect("localhost","root","ME");if (!$con) { die('Could not connect: ' . mysql_error()); }$currentstatus = Open;$currentowner = Unassigned; $currentrname = $_POST['rname'];$currentrcnumber = $_POST['rcnumber'];$currentrdnumber = $_POST['rdnumber'];$currentremail = $_POST['remail'];$currentesname = $_POST['esname'];$currentesdnumber = $_POST['esdnumber'];$currentescnumber = $_POST['escnumber'];$currentesemail = $_POST['esemail'];$currentrtype = $_POST['rtype'];$currentdescript = $_POST['descript']; mysql_select_db("crddb", $con);$sql="INSERT INTO crdmain (reqname, reqdesk, reqcell, reqmail, exname, exdesk, excell, exmail, reqtype, descript, reqstatus, reqowner)VALUES('$currentrname','$currentrdnumber','$currentrcnumber','$currentremail','$currentesname','$currentesdnumber','$currentescnumber','$currentesemail','$currentrtype','$currentdescript','$currentstatus','$currentowner')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }mysql_close($con);$qcon = mysql_connect("localhost","root","ME");if (!$qcon) { die('Could not connect: ' . mysql_error()); }mysql_select_db("crddb", $qcon);$query = "SELECT CRDNum FROM crdmainWHERE descript = '$currentdescript'";$result=mysql_query($query) or die(mysql_error());while ($rows=mysql_fetch_array($result)) {echo "<br>";echo "Your CRD Number is: ";echo $rows['CRDNum'];$docref = $rows['CRDNum'];}mysql_close($qcon);?>To complete your request please upload the relevant request form below:<form method="post" enctype="multipart/form-data"><table width="350" border="0" cellpadding="1" cellspacing="1" class="box"><tr> <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" id="userfile"> </td><td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload Request Form "></td></tr></table></form><?phpif(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);}$qconup = mysql_connect("localhost","root","ME");if (!$qconup) { die('Could not connect: ' . mysql_error()); }mysql_select_db("crddb", $qconup);$query = "INSERT INTO crdmain (reqfilename, reqfilesize, reqfiletype, reqfile )VALUES ('$fileName', '$fileSize', '$fileType', '$content')WHERE CRDNum = '$docref'";echo "$docref";echo "<br>File $fileName uploaded<br>";} $qconup = mysql_connect("localhost","root","ME");if (!$qconup) { die('Could not connect: ' . mysql_error()); }session_unset();?>[/code] Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142181 Share on other sites More sharing options...
Cagecrawler Posted December 16, 2006 Share Posted December 16, 2006 Use UPDATE instead of INSERT for the upload's MySQL query:Change[code]$query = "INSERT INTO crdmain (reqfilename, reqfilesize, reqfiletype, reqfile )VALUES ('$fileName', '$fileSize', '$fileType', '$content')WHERE CRDNum = '$docref'";[/code]to[code]$query = "UPDATE crdmain SET reqfilename='$fileName, reqfilesize='$fileSize', reqfiletype='$fileType', reqfile='$content' WHERE CRDNum = '$docref'";[/code] Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142182 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 Ok did that and when i hit upload it still creates another entry in the database. Is this the way i really should do this? I am willing to try other methodology if you have any sugestions.I was going to put the upload portion on the first page where they submit all the user info but then got myself confused with how I would pass the upload through to the next page. Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142186 Share on other sites More sharing options...
Cagecrawler Posted December 16, 2006 Share Posted December 16, 2006 What is being inserted into the duplicate line? The file data, the first forms data or both? Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142190 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 The data from the first form is being duplicated into a whole new entry in the database. Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142191 Share on other sites More sharing options...
phatgreenbuds Posted December 16, 2006 Author Share Posted December 16, 2006 WOOO HOOO! I was able to figure out a way around it. I basically stripped the code down on page two so that it just entered the data into the databes then redirected to the third page and passed the ticket number through the url. so basically they jump from the first page to the third page without knowing it. Link to comment https://forums.phpfreaks.com/topic/30828-solved-hurting-my-brain-on-this/#findComment-142201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.