PHP - Changing Content-type Header Causes Two Database Updates Instead Of One.
<?php require_once('init.php'); $results = $db->prepare('SELECT file_location, file_type, file_size, id as media_id WHERE id = ? LIMIT 1;'); $results->execute(array($_GET['id'])); while ($row = $results->fetch()) { header('Content-Type: ' . $row['file_type']); header('Content-Length: ' . $row['file_size']); $media_ins = $db->prepare('UPDATE media SET total_clicks = total_clicks + 1 WHERE id = ?'); $media_ins->execute(array($row['id'])); readfile($row['file_location']); }For some reason, putting the header('Content-Type....') causes the UPDATE statement to trigger twice increasing the total_clicks by 2. Commenting out the content-type line causes a single update to occur. init.php contains nothing more than session_start and the database connection. When i comment-out the content-type line the page is blank with no errors or messages. I'm not sure why this is occurring. Similar TutorialsOr should the Twig class be used to generate the content type header?
require_once '../../../vendor/autoload.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('templates'); $twig = new Twig_Environment($loader, array('debug' => true,)); $twig->addExtension(new Twig_Extension_Debug()); header('Content-type: text/html; charset=utf-8'); echo $twig->render('myTemplate.html', array()); hi evry bdy i m new to php here is my big problem im trying to display images and resize but header tag in php not working here is my code <?php header('Content-type: image/jpeg'); $new_width = 200; $new_height = 200; $files = glob("images/*.*"); //print_r($files); //for ($i=0; $i<count($files); $i++) { $filename= $files[0]; print $filename."<br />"; list($width, $height) = getimagesize($filename); echo "width is".$width." and height is ".$height; echo '<img src="'.$filename.'" alt="random image" />'."<br /><br />"; $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_p, null, 100); //} ?> if i m commenting header in line 3 then it is displaying garbage value if i m not commenting then it is displaying filename as string ... i wanna resize image please help me..... Weird question. I am using a captcha class which creates the code/image simply by doing this: Code: [Select] <img src="captcha.php"> The captcha.php file has lots of code of course, but this being key to my question: Code: [Select] header("Content-Type: image/jpeg"); ImageJpeg($image); Can I do it so I can create the image in the PHP of the actual script executing, so I don't have to call captcha.php in the image? - So it would look like this: (well no, but I think this explains what I want) Code: [Select] <img src="<?php echo $captchaCreated; ?>"> I am using a MVC design and don't see why the captcha should try and change this. I changed the imput type on a registration form from type="submit" to type="image" and the warning messages don't show here is the code Code: [Select] [<?php include "includes/config.php"; include "includes/functions.php"; session_start(); ob_start(); $name=trim($_REQUEST['name']); $company=trim($_REQUEST['company']); $phone=trim($_REQUEST['phone']); $email=trim($_REQUEST['email']); $address=trim($_REQUEST['address']); $city=trim($_REQUEST['city']); $state=trim($_REQUEST['state']); $zipcode=trim($_REQUEST['zipcode']); $loginid=trim($_REQUEST['loginid']); $password=trim($_REQUEST['pw1']); $confirmpassword=trim($_REQUEST['pw2']); if(isset($_REQUEST['Submit'])) { if($password==$confirmpassword) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { if(mysql_num_rows(mysql_query("SELECT * FROM `tbl_registration` WHERE `loginid` = '".$loginid."'")) == 0) { $sqlregister = "INSERT INTO `tbl_registration`(`name`,`company`,`phone`,`email`,`address`,`city`,`state`,`zip`,`loginid`,`password`) VALUES ('".$name."','".$company."','".$phone."','".$email."','".$address."','".$city."','".$state."','".$zipcode."','".$loginid."','".$password."') "; $rsregister= mysql_query($sqlregister); //$num=mysql_num_rows($rssearch); /*$rowArr=array(); $rowResult=array(); */ $Msg=message("You Have Registered Successfully..",2); if(is_dir("upload/".$loginid)) $msg1 = message("Problem With Creating Account.!",2); else { mkdir("upload/".$loginid); mkdir("upload/".$loginid."/web"); mkdir("upload/".$loginid."/email"); mkdir("upload/".$loginid."/emaildata"); } } else $msg = message("Login Id already exists..try another.!",2); } else { $msg =message("Sorry, you have provided an invalid security code.!",2); } } else $msg = message("confirm password does not match.!",2); } ?>/code] the form [code]<form name="form1" action="your_info.php" method="post" onSubmit="return validate(form1);"> <table width='360' cellpadding='1' cellspacing='2' bordercolor='#CACEDA' class="borders" align="center"> <tr> <td></td> <td colspan="3" class="txt3"><span style="padding-left:35px;"> <?=$Msg;?><br><?=$msg;?><br><?=$msg1;?> </span></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">Name:</div></td> <td width="200"><input name="name" type="text" size="40" class="ordertextin" value="<?=$name;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">Company:</div></td> <td width="200"><input name="company" type="text" size="40" class="ordertextin" value="<?=$company;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">Phone:</div></td> <td width="200"><input name="phone" type="text" size="40" class="ordertextin" value="<?=$phone;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td class="txt3" width="100"><div align="right">Email:</div></td> <td><input name="email" type="text" size="40" class="ordertextin" value="<?=$email;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">Address:</div></td> <td width="200"><input name="address" type="text" size="40" class="ordertextin" value="<?=$address;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">City:</div></td> <td width="200"><input name="city" type="text" size="30" class="ordertextin" value="<?=$city;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100"> <div align="right"><span class="txt3">State:</span></div></td> <td width="200" align="left"> <select name="state" class="ordertextin"> <option selected>Choose one </option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> <option value="AZ">Arizona</option> <option value="AR">Arkansas</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DE">Delaware</option> <option value="FL">Florida</option> <option value="GA">Georgia</option> <option value="GU">Guam</option> <option value="HI">Hawaii</option> <option value="ID">Idaho</option> <option value="IL">Illinois</option> <option value="IN">Indiana</option> <option value="IA">Iowa</option> <option value="KS">Kansas</option> <option value="KY">Kentucky</option> <option value="LA">Lousiana</option> <option value="ME">Maine</option> <option value="MD">Maryland</option> <option value="MA">Massachusetts</option> <option value="MI">Michigan</option> <option value="MN">Minnesota</option> <option value="MS">Mississippi</option> <option value="MO">Missouri</option> <option value="MT">Montana</option> <option value="NE">Nebrasca</option> <option value="NV">Nevada</option> <option value="NB">New Brunswick</option> <option value="NH">New Hamshire</option> <option value="NJ">New Jersey</option> <option value="NM">New Mexico</option> <option value="NY">New York</option> <option value="NC">North Carolina</option> <option value="ND">North Dakota</option> <option value="OH">Ohio</option> <option value="OK">Oklahoma</option> <option value="OR">Oregon</option> <option value="OTHER">Other</option> <option value="PA">Pennsylvania</option> <option value="PR">Puerto Rico</option> <option value="RI">Rhode Island</option> <option value="SC">South Carolina</option> <option value="SD">South Dakota</option> <option value="TN">Tennessee</option> <option value="TX">Texas</option> <option value="UT">Utah</option> <option value="VT">Vermont</option> <option value="VI">Virgin Islands</option> <option value="VA">Virginia</option> <option value="WA">Washington</option> <option value="DC">Washington DC</option> <option value="WI">Wisconsin</option> <option value="WY">Wyoming</option> <option value="YK">Yukon</option> </select> </td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td width="100" class="txt3"><div align="right">Zip:</div></td> <td width="200"><input name="zipcode" type="text" size="30" class="ordertextin" value="<?=$zipcode;?>"></td> <td width="20"></td> </tr> <tr> <td></td> <td class="txt3" width="100"><div align="right">Login Id: </div></td> <td><input name="loginid" type="text" size="30" class="ordertextin" value="<?=$loginid;?>"></td> <td></td> </tr> <tr> <td width="16"></td> <td class="txt3" width="100"><div align="right">Password:</div></td> <td><input name="pw1" type="password" size="40" class="ordertextin" value="<?=$password;?>"></td> <td width="20"></td> </tr> <tr> <td width="16"></td> <td class="txt3"><div align="right">Confirm Password: </div></td> <td><input name="pw2" type="password" size="40" class="ordertextin" value="<?=$confirmpassword;?>"></td> <td width="20"></td> </tr> <tr> <td height="10"></td> <td><div align="right">Security Code: </div></td> <td><img src="CaptchaSecurityImages.php?width=150&height=28&characters=7"/><br/><input id="security_code" name="security_code" type="text" class="inputType Inputsize150"/></td> </tr> <tr> <td width="16"></td> <td></td> <td> </td> <td width="20"></td> </tr> <tr><td height="20"></td> <td></td> <td><DIV class=satisfaction-quarantee-image-alignment ><INPUT type="image" name="Submit" height=54 alt="submit" width=208 src="images/submit_butom.gif"></DIV></td> </tr> </table> </form> Thanks. I am using the dragdrop functionality on a page which also updates the database.Drag and drop is working fine But i am having difficulty to determine which events to use to update the database. Here is my code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Sortable - Portlets</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--<link rel="stylesheet" href="/resources/demos/style.css">--> <style> body { min-width: 520px; } .interview-questions-column { width: 400px; float: left; padding-bottom: 100px; } .question-bank { width: 500px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; padding: 0.3em; } .portlet-header { padding: 0.2em 0.3em; margin-bottom: 0.5em; position: relative; } .portlet-toggle { position: absolute; top: 50%; right: 0; margin-top: -8px; } .portlet-content { padding: 0.4em; } .portlet-placeholder { border: 1px dotted black; margin: 0 1em 1em 0; height: 50px; } .sortable { border: 1px solid #eee; width: 95%; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } .bank-quertion-sotrable { border: 1px solid #eee; width: 150px; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .bank-quertion-sotrable li{ margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 200px; } .ui-state-default { height: 1.5em; line-height: 1.2em; } </style> <script> $(function() { $( ".interview-questions-column" ).sortable({ connectWith: ".interview-questions-column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all" }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).click(function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); $(function() { $( ".sortable" ).sortable({ placeholder: "ui-state-default", connectWith: ".connectedSortable", /*receive: function(event, ui) { // only perform for sub drop downs if($(this).hasClass('question_bank')) { // if the item doesn't have the matching sub class if (!$(this).hasClass($(ui.item).attr('class'))) { // cancel the sortable $(ui.sender).sortable('cancel'); } } alert('receive'); alert(ui.sender.attr("dataid")); alert(ui.sender.toSource()); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); },*/ update: function (event, ui) { //serial = $('#sortableF').sortable('serialize'); var data = $(this).sortable('serialize'); alert(data); //alert('update sortable'); //alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); // POST to server using $.post or $.ajax /*$.ajax({ data: 'test', type: 'POST', url: '/your/url/here' });*/ } }).disableSelection(); }); $(function() { $( ".draggable" ).draggable({ connectToSortable: ".sortable", helper: "clone", /*revert: function(valid) { if(valid) { alert("drop is valid"); //Dropped in a valid location } else { alert("drop is invalid"); //Dropped in an invalid location } // return !valid; return false; }*/ stop: function( event, ui ) { // alert(ui); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); } }); }); $( "ul, li" ).disableSelection(); </script> </head> <body> <div class="interview-questions-column"> <div class="portlet"> <div class="portlet-header">Feeds</div> <div class="portlet-content"> <ul id="sortableF" class="connectedSortable sortable"> <li class="ui-state-default" id="item-1">Item 1</li> <li class="ui-state-default" id="item-2">Item 2</li> <li class="ui-state-default" id="item-3">Item 3</li> <li class="ui-state-default" id="item-4">Item 4</li> <li class="ui-state-default" id="item-5">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">News</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-6">Item 1</li> <li class="ui-state-default" id="item-7">Item 2</li> <li class="ui-state-default" id="item-8">Item 3</li> <li class="ui-state-default" id="item-9">Item 4</li> <li class="ui-state-default" id="item-10">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Shopping</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-11">Item 1</li> <li class="ui-state-default" id="item-12">Item 2</li> <li class="ui-state-default" id="item-13">Item 3</li> <li class="ui-state-default" id="item-14">Item 4</li> <li class="ui-state-default" id="item-15">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Links</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-16">Item 1</li> <li class="ui-state-default" id="item-17">Item 2</li> <li class="ui-state-default" id="item-18">Item 3</li> <li class="ui-state-default" id="item-19">Item 4</li> <li class="ui-state-default" id="item-20">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Images</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-21">Item 1</li> <li class="ui-state-default" id="item-22">Item 2</li> <li class="ui-state-default" id="item-23">Item 3</li> <li class="ui-state-default" id="item-24">Item 4</li> <li class="ui-state-default" id="item-25">Item 5</li> </ul> </div> </div> </div> <div class="question-bank"> <div class="portlet"> <div class="portlet-header">Question bank</div> <div class="portlet-content"> <ul id="question_back" class="connectedSortable bank-quertion-sotrable"> <li class="ui-state-default draggable" id="item-26">Item 1</li> <li class="ui-state-default draggable" id="item-27">Item 2</li> <li class="ui-state-default draggable" id="item-28">Item 3</li> <li class="ui-state-default draggable" id="item-29">Item 4</li> <li class="ui-state-default draggable" id="item-30">Item 5</li> </ul> </div> </div> </div> </body> </html>Basically above code will form few boxes with items(which are actually questions) in it. There is one box on the right side with heading "Question Bank". From the "Question Bank" we can drag the questions to other boxes but can't do the reverse(this is also working). Also we can sort the questions within the box or drag the questions from one box to another. Box heading are the categories and items are questions associated to that categories. What i need is : Event that updates the database when we drag the questions from "Question Bank" to any box on the left side. Please note Questions in the "Question Bank" are pre created coming from database. Event that updates the database when we sort the questions within the box. Event that updates the database when we drag the question from one box to another box. it should also do the sorting for that two boxes. Event that updates the database when we sort the boxes. Here is the JS Fiddle link jsfiddle.net/6o30rrzx Question Bank is comming on the bottom of the page instead of on the right side any advice and suggestions will be greatly appreciated Thank you for reading this post. For SEO purposes I am told that either 301/302 redirects are better. I use header("Location: $url everywhere, is this 301 or 302 ? Also, I see somewhere that this is the proper way to do it. Code: [Select] header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.$location); .. what if I didn't use the first line (I have sites all over the place littered with header Location, but have only used the 2nd line)? Would it make a difference - it works that's for sure. Hi, I am trying to get google docs viewer integrated into my website. It is working for ppt files but not pptx files. I have read up and I understand I need to alter the header to: header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); However when I do this I click on the link and it just downloads index.php. Any idea what I am doing wrong here? Hi All, I'm trying to upload a gif file via php/curl, and the browser keeps interpreting the content-type as application/xml. I've tried explicitly setting the content type, see below, but it has no effect. Any thoughts? I've seen conflicting posts on the ability to specify the content-type with curl/php. Code: [Select] curl_setopt($session, CURLOPT_HTTPHEADER, array( "Content-Type: image/gif", 'Content-length: ' . strlen($post) )); Hey guys, I know nothing of PHP so please bare with me as I try to explain my problem. My company collects sales leads that are emailed through to a CRM system (GoldMine). We are currently in the process of moving our website from a shared windows server to a dedicated linux server and it seems to be causing a problem with the form, or at least PHP behind it. The guy who handed the initial set up has mysteriously disapeared so we're in a bit of a fix. I'm not specifically looking for a solution, more of an idea of where to go from here. I'm not sure wether the problem lies in the PHP itself or something else.. like the server for example. I was hoping someone here might be able to point me in the right direction somewhat. Anyway, the problem is that while testing the form on the new server the email is sent and our CRM picks it up but cannot read because a newly appeared line has been inserted at the top of the body. This does not appear when filling in the form currently live on our site (windows server). the line is: Code: [Select] Content-Type: text/x-gm-impdata As far as I'm aware this content-type is necessary for our CMR to recognize and read the email, but it shouldn't be showing up in the body of the mail. The full on send PHP is: Code: [Select] <?php $redirectURL = "http://www.website.co.uk/confirmation_page.htm"; function Decode($strValueIn) { //Do not modify this function! $intX = 0; $intY = 0; $Temp = ""; $Mod = ""; $intMod =0; $intTemp = 0; $ValueOut = ""; $intY = 1; $strValueOut=""; for ($intX=1; $intX<=((strlen($strValueIn)/2)/2); $intX=$intX+1) { $strTemp=""; $strMod=""; if (($intX % 2)==0) { $strMod=substr(substr($strValueIn,$intY-1,4),0,2); $strTemp=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2)); } else { $strMod=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2)); $strTemp=substr(substr($strValueIn,$intY-1,4),0,2); } $intMod=hexdec($strMod); $intTemp=hexdec($strTemp); $intTemp=$intTemp-$intMod; $strValueOut=$strValueOut.chr($intTemp); $intY=$intY+4; } return $strValueOut; } if ($_POST["GMsubmit"]!="") { $Body = ""; $Notes = ""; $SendToEmail = Decode($_POST["SendToEmail"]); //$SMTP = Decode($_POST["SMTP"]); //Your SMTP data may have to be set set on the Apache Server, and this variable is not used. $OnNewSendGMEmail = $_POST["OnNewSendGMEmail"]; if ($OnNewSendGMEmail!="") {$OnNewSendGMEmail = Decode($OnNewSendGMEmail);} else {$OnNewSendGMEmail = "";} if ($_POST["OnDUPSendGMEmail"]!="") {$OnDUPSendGMEmail = Decode($_POST["OnDUPSendGMEmail"]);} else {$OnDUPSendGMEmail = "";} if ($_POST["OnNewAttachTrack"]!="") {$OnNewAttachTrack = Decode($_POST["OnNewAttachTrack"]);} else {$OnNewAttachTrack = "";} if ($_POST["OnDupAttachTrack"]!="") {$OnDupAttachTrack = Decode($_POST["OnDupAttachTrack"]);} else {$OnDupAttachTrack = "";} if ($_POST["Word"]!="") {$Password = Decode($_POST["Word"]);} else {$Password = "";} if ($_POST["DupLogic"]!="") {$DupLogic = Decode($_POST["DupLogic"]);} else {$DupLogic = "";} $OutputAs = $_POST["OutPutAs"]; $DuplicateCount=0; $XML = "<gmdata>"; if ($_POST["DuplicateCount"]!="") { $DuplicateCount =intval($_POST["DuplicateCount"]); } if ($DuplicateCount >0 || $OnNewSendGMEmail!="" || $OnDUPSendGMEmail!="" || $OnNewAttachTrack!="" || $OnDupAttachTrack!="") { $Body = $Body."[Instructions]\r\n"; $XML = $XML."<Instructions>"; if ($DuplicateCount > 0) { for($counter=0; $counter < $DuplicateCount; $counter++) { $RealCount=$counter+1; $str = "DuplicateChecking$RealCount"; eval("\$str = \"$str\";"); $Body = $Body."DupCheck".$RealCount."=".$_POST[$str]."\r\n"; //print($str.":".$_POST[$str].";"); $tempVal = $_POST[$str]; if ($tempVal==="EMAIL") { $XML = $XML."<DupCheck>EA1</DupCheck>"; } else { if ($tempVal==="WEBSITE") { $XML = $XML."<DupCheck>WS1</DupCheck>"; } else { $XML = $XML."<DupCheck>".htmlspecialchars($_POST[$str])."</DupCheck>"; } } } if ($DupLogic !="") {$Body = $Body."DupLogic=OR\r\n";} } if ($OnNewSendGMEmail!="") { $Body = $Body."OnNewSendGMEmail=".$OnNewSendGMEmail."\r\n"; $XML = $XML."<OnNewSendGMEmail>".htmlspecialchars($OnNewSendGMEmail)."</OnNewSendGMEmail>"; } if ($OnDUPSendGMEmail!="") { $Body = $Body."OnDUPSendGMEmail=".$OnDUPSendGMEmail."\r\n"; $XML = $XML."<OnDupSendGMEmail>".htmlspecialchars($OnDUPSendGMEmail)."</OnDupSendGMEmail>"; } if ($OnNewAttachTrack!="") { $comma =strpos($OnNewAttachTrack, ","); $Body = $Body."OnNewAttachTrack=".$OnNewAttachTrack."\r\n"; if ($comma =="") { $XML = $XML."<OnNewAttachTrack>".htmlspecialchars($OnNewAttachTrack)."</OnNewAttachTrack>"; } else { list($track, $user) = split(',', $OnNewAttachTrack,2); $XML = $XML."<OnNewAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnNewAttachTrack>"; } } if ($OnDupAttachTrack!="") { $comma =strpos($OnDupAttachTrack, ","); $Body = $Body."OnDupAttachTrack=".$OnDupAttachTrack."\r\n"; if ($comma =="") { $XML = $XML."<OnDupAttachTrack>".htmlspecialchars($OnDupAttachTrack)."</OnDupAttachTrack>"; } else { list($track, $user) = split(',', $OnDupAttachTrack,2); $XML = $XML."<OnDupAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnDupAttachTrack>"; } } if ($Password!="") { $Body = $Body."Password=".$Password."\r\n"; $XML = $XML."<Password>".htmlspecialchars($Password)."</Password>"; } if ($DupLogic!="") { $XML = $XML."<DupLogic>OR</DupLogic>"; } else { $XML = $XML."<DupLogic>AND</DupLogic>"; } $XML = $XML."</Instructions>"; } $Body = $Body."[Data]\r\n"; $XML = $XML."<accounts><account>"; $Phone = ""; $EA = ""; $WS = ""; $PR = ""; while(list($key,$value)= each($_POST)) { eval("$\$key = \"$value\";"); { if ($key!="GMsubmit" && $key!="SMTP" && $key!="OnNewSendGMEmail" && $key!="OnDUPSendGMEmail" && $key!="OnNewAttachTrack" && $key!="OnDupAttachTrack" && $key!="SendToEmail" && $key!="DuplicateCount" && $key!="Word" && strpos($key, "DuplicateChecking") === false && $key!="OutPutAs" && $key!="DupLogic" && strpos($key, "pretty_") === false) { if($value!="") { if ($key=="UHCUSTDESC" || $key=="UHDESCGOOD" || $key=="UHPI") { $value = str_replace("\r\n","<br/>",$value); $NoteHeader = ""; if ($key=="UHCUSTDESC") { $NoteHeader = "<strong>Customer Description</strong><br/><br/>"; } if ($key=="UHDESCGOOD") { $NoteHeader = "<strong>Descriptions of Goods</strong><br/><br/>"; } if ($key=="UHPI") { $NoteHeader = "<strong>Packing Information</strong><br/><br/>"; } $Notes = $Notes.$NoteHeader.$value."<br/><br/>"; } $Body = $Body.$key."=".$value."\r\n"; if (substr($key,0,5)!="PHONE" && substr($key,0,3)!="FAX" && substr($key, 0, 5)!="EMAIL" && substr($key,0, 7)!="WEBSITE") { $PR = $PR."<property name=".chr(34).$key.chr(34)." db_name=".chr(34).$key.chr(34).">"; $PR = $PR."<property_string>".htmlspecialchars($value)."</property_string>"; $PR = $PR."</property>"; } else { if(substr($key,0,5)=="PHONE") { $Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">"; $Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>"; $Phone = $Phone."</phone>"; } elseif(substr($key,0,3)=="FAX") { $Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">"; $Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>"; $Phone = $Phone."</phone>"; } elseif(substr($key,0,7)=="WEBSITE") { $WS = $WS."<website primary=".chr(34)."1".chr(34)." id=".chr(34)."WS1".chr(34).">"; $WS = $WS."<properties><property name=".chr(34)."web_site".chr(34)."><property_string>".$value."</property_string></property></properties>"; $WS = $WS."</website>"; } elseif(substr($key,0,5)=="EMAIL") { $EA = $EA."<email primary=".chr(34)."1".chr(34)." id=".chr(34)."EA1".chr(34).">"; $EA = $EA."<properties><property name=".chr(34)."email_address".chr(34)."><property_string>".$value."</property_string></property></properties>"; $EA = $EA."</email>"; } } } } } } if ($PR !="") {$XML = $XML."<properties>".$PR."</properties>";} if($Phone!="") { $XML = $XML."<phone_numbers>".$Phone."</phone_numbers>"; } if($EA!="") { $XML = $XML."<emails>".$EA."</emails>"; } if($WS!="") { $XML = $XML."<websites>".$WS."</websites>"; } $XML = $XML."</account></accounts></gmdata>"; $ToSubject="Web Import"; //The PHP built in function mail() will not raise or cause errors if it fails - so be sure that your PHP server is setup correctly! if( $OutputAs!="INI") { $Body = $XML; } //ini_set("SMTP", Decode($SMTP)); $Body = $Body."UHSUBDATE=".date("d/m/Y")."\r\n"; $Body = $Body."NOTES=".$Notes; if(mail(Decode($SendToEmail), $ToSubject, $Body, "From: GoldMine WebImport <no-reply@frontrange.com>\r\n\r\nContent-Type: text/x-gm-impdata\r\n\r\n" )) { //print "Your data has been recorded successfully!\r\n\r\n<!--\r\n".Decode($SendToEmail)."\r\n".$ToSubject."\r\n".$Body."\r\n\r\n".$OutputAs."\r\n\r\n-->"; header("location: ".$redirectURL); } else { print("There was a mailer failure.\r\n\r\n<!--\r\n".$Body."\r\n\r\n-->");} } else { echo "There was no form data passed."; } ?> Line 294 contains the text that's appearing in the email. Any ideas would be very, very much appreciated. I have piping set up, where when I send an e-mail to a certain address, a script executes. This script will parse the e-mail and will post the body of the e-mails (along with a picture, if attached) to a blog. This all works okay, except the problem I keep running into is when I send from different devices (desktop, Android phone, BlackBerry), the e-mails have different character sets or encoding. So one e-mail will show up just fine, and then the body of another will look something like this: Quote --90e6ba6e83a0846c8504926b9478 Content-Type: text/html; charset=ISO-8859-1 This is the content of the e-mail. --90e6ba6e83a0846c8504926b9478-- So what I'm wondering is if there is any way to detect the charset/encoding and automatically decode it properly? The only solution I have so far -- and I'm not very good with PHP, I'll admit -- is to just "hack" my way through, by using stristr() to see if the body contains certain characters (like "ISO-8859-1"), and then extracting the text that is in between, say, "ISO-8859-1" and "--". Of course, this is very crude, and has many problems on its own. So what I am looking for is if there is some sort of way to automatically get the body of an e-mail in plain text, regardless of whether the e-mail has an attachment, how it's encoded, or what mail client was used. Thanks for your time! Hi guys, I was just wondering if anyone could help me. I've got a My_SQL database containing articles, a summary for the article and a date. I have a basic CMS system set-up, but I want to create a script that when users sign up to a mail list it forwards the summary and dates of the articles database. If that makes sense? But I only want it to forward the most recent 5 rows. I'm pretty new to PHP and I've been mostly following tutorials thus far, but this is quite specific. Thanks in advance! Hello all. Here is my script... Code: [Select] if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); echo "<br>"; echo $headers; } $handle = fopen($_FILES['filename']['tmp_name'], "r"); $header = fgetcsv($handle); while(! feof($handle)){ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into CSVtest($header[0],$header[1],$header[2],$header[3],$header[4]) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($import) or die(mysql_error()); } } fclose($handle); echo "Done"; } This is the way how I insert data into database according to header even it's not arranged same as the table column. If the csv has only "cell,firstname,lastname,," (and my table has only these 3 columns as well) then it still working...but if there are "cell,address,company,firstname,lastname" then it will show me unknown column error. Actually I wish to have a function that even there are many columns in csv that not exist in the table it still can just pick the right column and insert into table. Can anyone give me hints on how to change my script?I know there are many errors...it's really embarrassed to show my low standard script... Thanks in advance. I have created an input field on a website for people to subscribe by their email address. The email address is stored in a database. I am using PHPMyAdmin. The email address is successfully working, but I want to prevent duplicate email address to be stored, however, I am having an error. Here are my codes: HTML codes: Code: [Select] <form action="index.php" method="post"> <input type="text" size="25" placeholder="Your email address..." name="enter"/> <input class="submit" type="submit" value="Subscribe" name="subscribe"/> <br/> PHP with Query codes: Code: [Select] <?php if ( $_SERVER['REQUEST_METHOD'] == "POST" ) { $ee = htmlentities($_POST['enter']); if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$ee) || empty($ee)){ echo '<p class="fail">Failed...Try again!</p>'; } else { @mysql_connect ('localhost', 'root', '') or die ('A problem has occurred, refresh the page and try again!'); @mysql_select_db ('links') or die ('A problem has occurred, refresh the page and try again!'); $duplicate = "SELECT * FROM `email` WHERE `emailaadress` = '{$ee}'"; $query = "INSERT INTO email (id, emailaddress) VALUES('NULL', '.$ee')"; $result = mysql_query($duplicate); if ( mysql_num_rows ( $result ) > 1) { /* Username already exists */ echo 'Username already exists'; } else { mysql_query($query); echo '<p class="success">Successfully subscribed!</p>'; } } } ?> Error I am having: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\softwareportfolio\index.php on line 68 Can someone help me? Thank Lets say you have a database which is packed with content. How can this be used for SEO purposes? Does Google follow all the links on your site and read the echo and indexing that information. Or does the content in a database need to converted into HTML for Google to be able to read it? I tried using Google Custom Search however it did not display anything in my database. If Google crawled my site and ranked it and then carried out the search using Google Custom Search would it then display using Google Custom Search? so ik you cna get a search box to search items or text in a database, but what i want to know is how to manually insert text and images into it example image (imagine its an image) text name - text price how would i do this? Hi Guys, I have the following code that I'm getting from my database. This is how it appears in the DB. Code: [Select] <div id="reply_flash"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="font-family: Arial; font-size: 14px; line-height: 19px; text-align: left; color: rgb(102, 102, 102);"> <br> <div style="font-family: Georgia; font-size: 19px; line-height: 20px; color: rgb(88, 43, 0); font-weight: normal; text-align: left;">This is a heading</div> <p>This is some text in this area.</p> <a href="#"><strong>Read more</strong></a> </td> </tr> </table> </div> When the user goes to edit the page, I'm retrieving the above from the database: http://www.mysite.com/newsletter/edit/56 Code: [Select] // Controller to handle the request public function edit() { $id = $this->uri->segment(3); $data['get_newsletter'] = $this->Newsletter_model->get_newsletter($id); $this->load->view('header'); $this->load->view('newsletter/edit', $data); $this->load->view('footer'); } // View to display the request foreach($get_newsletter as $row) { $code = $row->code; $newsletter_id = $row->id; } echo $code; Now, when I echo the code below. It appears in the html as Code: [Select] <div id="reply_flash"> </div> // CLOSING THE DIV AND PUTTING THE TABLE OUTSIDE <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="font-family: Arial; font-size: 14px; line-height: 19px; text-align: left; color: rgb(102, 102, 102);"> <br> <div style="font-family: Georgia; font-size: 19px; line-height: 20px; color: rgb(88, 43, 0); font-weight: normal; text-align: left;">This is a heading</div> <p>This is some text in this area.</p> <a href="#"><strong>Read more</strong></a> </td> </tr> </table> </div> As you can see, when it's being retrieved and being displayed on the webpage, the div is being closed and the table appears outside it. Have no isdea what is going on. Hi, I am hoping I have posted my current problem in the right part of this forum. As it relates to the php code, I presume this is the right place, although it also relates to a mysql database I have too. Ok, here is my problem.... I have two websites, one is a non members site and one is a paid members area site. I had a directory style script made for the non members site and want to use the same script within the members site. I paid for the script to be made and set up, which cost me quite a bit, hence the reason I am copying it all over to my other site too. The script displays thumbnials from the database, 4 across and 3 down (total of 12 thumbs per page), each linking to a URL and each thumb has a title. On the left of the webpage is categories, which when clicked, shows thumbs relating to that specific category, or all etc. The CMS forms allow us to add categories etc. Ok, now my problem is this.. I backed up the original database and created a new database on the members site where I also want this functionality. I copied all the scripts over then chenged the content of the database. On the members site I only want it to display three categories, All, Photos and Videos. So this is quite simple compared to the first site. All seemed to display fine, until I moved all the scripts into the members folder (which is accessed via ccbill). The page displays ok, but it just states "No updates found" as in, no content in the database is found. The base url in the configuration script is set to the top domain, but I have renamed the folders where the thumbs are saved to members/thumbs, but still it isnt working. I also want to change the folder name from its original name of www.domain.com/sites to the new domain.com/updates but nothing works when I try to change it. If anyone can help me out with this, I would be extremely grateful, as the workings of this script are all there, and it seems pointless having to spend hundreds on a new script to be made when the functionality is already there, but just not working right. Thanks so much! hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! I am having a big problem in MySQL and a part in my PHP coding as well. I created a registration form, where the user will have to fill his names, email address, choose a username and so on. I do not want duplicate email address and username in my database, thus, if a user choose either an email address or a username which has already taken, he will be notified. To prevent this duplication, I have set both the email address and username fields as UNIQUE KEY in MySQL. My problems a Even by setting both the username and email address fields as UNIQUE KEY, it is not working as I can register using the same email address or username. How to solve this? I have coded also to prevent this problem of duplicate so that the user will be notified to choose another email or username, but I am having a warning. My PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string($_POST['fname']); $lastname = mysql_real_escape_string($_POST['lname']); $email = mysql_real_escape_string($_POST['emailr']); $uname = mysql_real_escape_string($_POST['user']); $pwd = mysql_real_escape_string($_POST['pass']); $pmd= md5($pwd); //Database $connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); if (mysql_num_rows(mysql_query("SELECT * FROM login WHERE emailaddress = '$email' username = '$uname'"))) { echo '<p class="fail">This email or username is already taken!</p>'; } } } } ?> The warning message I am getting: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\miniimagehosting\register.php on line 44 |