PHP Programming > Beginners - Learning PHP

Inserting extra quotes when submitting form

(1/3) > >>

mdahlke:
I have a form that if I were to type "don't" (w/o quotes), it comes out as don''''t. What could be causing this?

p.s. It doesn't do this on my localhost, only when its uploaded to the web server


--- PHP Code: ---$limitedtextarea = mysql_real_escape_string(urldecode($_POST['limitedtextarea'])); //The actual judgment
$url = mysql_real_escape_string($_POST['url']); //URL (Actually now set to get IP Address of user uploading)
$figcaption = mysql_real_escape_string(urldecode($_POST['figcaption'])); //Caption for the image
$imageURL = mysql_real_escape_string($_POST['imageURL']); //URL for and image
$link = mysql_real_escape_string($_POST['link']);

--- End code ---

Noodles:
What does the form look like  ?
what is inserted in to the database ?

Where does it come out ?

--- Quote ---it comes out as don''''t

--- End quote ---

mdahlke:
The form...

--- PHP Code: ---<form method="post" action="" enctype="multipart/form-data" name="form1">
<fieldset id="judgment">
      <label for="file"><span class="steps">Step 1.</span> Choose a picture:&nbsp;
          <small>Image maximum size <b>5 </b>MB</small>&nbsp;<small>jpeg, gif, or png</small></label>
          <br />
          <input id="upload-image" size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/>
<div id="thumbnail"></div>
           <br /> or enter image url:
            <input name="imageURL" type="url" size="50" placeholder="Paste image link here" title="To copy image link - right click on any image and select &quot;Copy image URL&quot;">
            <br>
            <br>
          <label for="figcaption"><span class="steps">Step 2.</span> Enter a caption for the image:</label>
           <input name="figcaption" id="figcaption" type="text" required="Enter a caption"/>
            <br>
            <br>
          <label for="description"><span class="steps">Step 3.</span> Judg whatever/whoever is in that picture:</label>
          <br>
         <textarea id="description" style="width:500px;height:100px" name="limitedtextarea" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,350);" 
onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,350);" required="Oops! You seemed to forget the most importatnt part!"></textarea>
            <br>
            <font size="1">(Maximum characters: 350)<br>
You have <input readonly type="text" name="countdown" size="3" value="350"> characters left.</font>
            <br>
            <br />
            <label for="link">Have a link?</label>
            <input type="url" name="link" placeholder="Enter it here!" size="40"/>
<br />
<br />
            
            <input type="hidden" name="url" value='<?php echo "Date:".date('Y-m-d H:i:s')."<br />Ip:".$_SERVER['REMOTE_ADDR'].""?>'/>
          
          <label for="submit"><span class="steps">Step 4.</span> Submit it:</label> 
          <input type="submit" id="mybut" value="       Judg It!        " name="Submit"/>
 </fieldset>         
</form>
--- End code ---


the insertion into db...

--- PHP Code: ---<?php 
require 'db.php';
error_reporting(0);

$limitedtextarea = mysql_real_escape_string(urldecode($_POST['limitedtextarea'])); //The actual judgment
$url = mysql_real_escape_string($_POST['url']); //URL (Actually now set to get IP Address of user uploading)
$figcaption = mysql_real_escape_string(urldecode($_POST['figcaption'])); //Caption for the image
$imageURL = mysql_real_escape_string($_POST['imageURL']); //URL for and image
$link = mysql_real_escape_string($_POST['link']);

if($imageURL==null && $_FILES['file']['name']==null)
{
echo"";
}
else{
$change= "http://www.judgd.com";
$abc="";


 define ("MAX_SIZE","3000");
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

 $errors=0;
  
 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
  $image =$_FILES["file"]["name"];
$uploadedfile = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
   
  if ($image) 
  {
 
  $filename = stripslashes($_FILES['file']['name']);
 
   $extension = getExtension($filename);
  $extension = strtolower($extension);


 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
  {

  $change='<div class="msgdiv">Unknown Image extension </div> ';
  $errors=1;
  }
  else
  {

 $size=filesize($_FILES['file']['tmp_name']);


if ($size > MAX_SIZE*5000)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
die;
$errors=1;
}


if($extension=="jpg" || $extension=="jpeg" || $extension=="pjpeg")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);

}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);

}
else 
{
$src = imagecreatefromgif($uploadedfile);
}

echo $scr;


$percent = 0.5;

list($width,$height)=getimagesize($uploadedfile);


$newwidth=$width;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);


$newwidth1=$width*$percent;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

$newwidth2=$width*$percent*$percent;
$newheight2=($height/$width)*$newwidth2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,$width,$height);

$filePath = "images/";
$filePathSmall = "images/small/";
$filePathThumb = "images/thumbnail/";

$filename = $_FILES['file']['name'];

$filenamesmall = $newheight1."x".$newheight1."_".$_FILES['file']['name'];

$filenamethumb = $newheight2."x".$newheight2."_".$_FILES['file']['name'];

imagejpeg($tmp,$filePath.$filename,100);

imagejpeg($tmp1,$filePathSmall.$filenamesmall,100);

imagejpeg($tmp2,$filePathThumb.$filenamethumb,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
imagedestroy($tmp2);
}}

}

$fileName = $filename;

if($fileName==null){
$fileName=$imageURL;
}
//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors) 
 {
 
   // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
   $query = "INSERT INTO judgment (limitedtextarea, name, namesmall, namethumb, size, type, path, url, figcaption, link ) 
VALUES ('$limitedtextarea','$fileName','$filenamesmall','$filenamethumb', '$fileSize', '$fileType', '$filePath', '$url', '$figcaption','$link')";

$result = mysql_query($query) or die('Error, query failed : ' . mysql_error());

if(!$result){
   print '<script type="text/javascript">';
   print 'alert("Please follow posting guidelines")';
   print '</script>';

    }
else {
   echo "<div style='position:absolute; top:140; left:250'>Post Successful!</div>";
    }
 }
}
--- End code ---


calling it from db...


--- PHP Code: ---echo ("<!--[if !IE]> -->");
$ipadd = $_SERVER['REMOTE_ADDR'];
if($row['path']==null) // IF PATH IS NULL; THEN IMAGE IS URL; DO THIS...
{
echo ("

<table itemscope itemtype='http://schema.org/Review' class='showing'>
<tr>
<td rowspan='1' colspan='1'>
<figure>
<a itemprop='contentUrl' href='".$row['name']."' rel='lightbox' title=\"".$row['figcaption']." - ".$row['limitedtextarea']."\">
<img class='figImg' itemprop='thumbnailUrl' src='". $row['name']."' alt='".$row['name']."' title='".$row['name']."'/></a></figure>
</td>
</tr>
<tr>
<td class='figcap'><a href='judgment_search.php?figcaption=".$row['figcaption']."' title='".$row['figcaption']."'>".$row['figcaption']."</td>
</tr>
<tr>
<td rowspan='1' colspan='1'><span itemprop='comment'>".$row['limitedtextarea']."</span></td>
</tr>

<tr>");
if ($row['link']==!null){
echo "<td><a href='".$row['link']."' title='".$row['link']."' target='_blank'>Link</a></td>";
}
echo ("<td></td>
</tr>

<tr>
<td>

<div class='fb-like' data-href=\"http://www.judgd.com/judgment_search?figcaption=".$row['figcaption']."\" data-send='true' data-layout='button_count' data-width='250' data-show-faces='false'></div>
<a href='http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.judgd.com%2F&media=".$row['name']."&description=".urlencode($row['limitedtextarea'])."' class='pin-it-button' count-layout='horizontal'><img border='0' src='//assets.pinterest.com/images/PinExt.png' title='Pin It' /></a>

</td>
</tr>

</table>
<!-- <![endif]-->

");
}

--- End code ---


when "don't" or "it's" or anyting with an apostrophe it triples it when inserting it into the db

Noodles:
Which form input does this happen the textarea ?            

mdahlke:
Textarea ("description") and input[type="text"] ("figcaption")

Navigation

[0] Message Index

[#] Next page

Go to full version