Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting $_post value numeric instead of string

Status
Not open for further replies.

walkerdigest

Programmer
Feb 10, 2009
35
TR
in the form I have the following element:

<select name="sayfa">
<option value="1">Anasayfa</option>
<option value="2">Alt Sayfa</option>
</select>

I get the following $_POST value :

$sayfa = $_POST['sayfa'];
echo $sayfa + $sayfa; <-------- here I get value as 2 when I choose option Anasayfa(with value 1);

so the $_POST value returns numeric value instead of string. shouldn't I have get string value? I need string value here.

I have applied strval and string to $_POST value but it didn't work. what should I do?
 
php uses implicit typing. so this code

Code:
$a = "3";
$b = "4";

echo $a + $b;
will output 7 even though both variables are passed as strings.

so there is something else going wrong with your script. If you can post the WHOLE html form then we can have a better look.
 
when I choose option value 1 for $sayfa= $_POST['sayfa'], I want to upload image with size 150x150 but instead I always end up with 125x75

if ($sayfa == "2")
{
$bresim = imagecopyresampled($imb, $imx, 0, 0, 0, 0, 500, 500, $xxx[0], $xxx[1]);
imagejpeg ($imb,$kopyalanacakYerb);
}

if ($sayfa == "1")
{$kresim = imagecopyresampled($imk, $imx, 0, 0, 0, 0, 150, 150, $xxx[0], $xxx[1]);}
else if ($sayfa == "2")
{$kresim = imagecopyresampled($imk, $imx, 0, 0, 0, 0, 125, 75, $xxx[0], $xxx[1]);}
 
see my post above. you need to help us to help you.
 
the following is the form

<form action="resimekle_kaydet.php" method="post" enctype="multipart/form-data">
<table width="700" border="0" cellspacing="4" cellpadding="0" align="center">
<caption>FOTO?RAF EKLEME</caption>
<tr>
<td>&nbsp;Foto?raf Ba?l???</td>
<td>&nbsp;<input name="baslik" type="text" size="60"></td>
</tr>
<tr>
<td>&nbsp;Resim</td>
<td>&nbsp;<input name="resim" type="file" size="60">(sadece jpg ve gif dosyalar? yükleyiniz)</td>
</tr>
<tr>
<td>&nbsp;Aç?klama</td>
<td>&nbsp;<textarea cols="50" rows="10" name="aciklama"></textarea></td>
</tr>
<tr>
<td>&nbsp;Yay?nda</td>
<td>&nbsp;<select name="yayinda">
<option value="0">Yay?nda De?il</option>
<option value="1">Yay?nda</option>
</select></td>
</tr>
<tr>
<td>&nbsp;Sayfa</td>
<td>&nbsp;<select name="sayfa">
<option value="1">Anasayfa</option>
<option value="2">Alt Sayfa</option>
</select></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="kmt" value="Kaydet"></td>
</tr>
</table>
</form>

The following is the receiving form input:

$baslik = $_POST['baslik'];
$aciklama = $_POST['aciklama'];
$yayinda = $_POST['yayinda'];
$sayfa = $_POST['sayfa'];


if (!isset($_POST['baslik']) or $_POST['baslik']=="")
{
header("Location:panel.php?id=foto&id2=ekle&hata=1"); // baslik girilmedi
}
if (!isset($_POST['aciklama']) or $_POST['aciklama']=="")
{
header("Location:panel.php?id=foto&id2=ekle&hata=2"); // aciklama girilmedi
}


$yeri = $_FILES['resim']['tmp_name'];
$adi = $_FILES['resim']['name'];
$boyut = $_FILES['resim']['size'];
$tipi = $_FILES['resim']['type'];

if ($boyut<2000000 and $boyut>0)

{
if ($tipi=="image/pjpeg" || $tipi="image/gif")
{
$zaman = time();
$dosyaismib = "bresim_".$zaman;
$dosyaismik = "kresim_".$zaman;

if ($tipi=="image/pjpeg")
{
$dosyaismib .=".jpg";
$dosyaismik .=".jpg";
}
else
{
$dosyaismib .=".gif";
$dosyaismik .=".gif";
}

$kopyalanacakYerb = "photos\\".$dosyaismib;
$kopyalanacakYerk = "thumbnails\\".$dosyaismik;


$imb = imagecreatetruecolor (500, 500);
$imk = imagecreatetruecolor (125, 75);
if ($tipi=="image/pjpeg")
$imx = imagecreatefromjpeg($yeri);
else
$imx = imagecreatefromgif($yeri);

$xxx = getimagesize($yeri);


if ($sayfa == "2")
{
$bresim = imagecopyresampled($imb, $imx, 0, 0, 0, 0, 500, 500, $xxx[0], $xxx[1]);
imagejpeg ($imb,$kopyalanacakYerb);
}

if ($sayfa == "1")
{$kresim = imagecopyresampled($imk, $imx, 0, 0, 0, 0, 150, 150, $xxx[0], $xxx[1]);}
else if ($sayfa == "2")
{$kresim = imagecopyresampled($imk, $imx, 0, 0, 0, 0, 125, 75, $xxx[0], $xxx[1]);}

imagejpeg ($imk,$kopyalanacakYerk);
imagedestroy($imb);
imagedestroy($imk);
imagedestroy($imx);

$sql = "insert into resim (baslik,bresim,kresim,aciklama,yayinda,sayfa) values ('" .$baslik . "','" . $dosyaismib . "','" . $dosyaismik . "','" . $aciklama . "','" . $yayinda . "','" . $sayfa . "')";

mysql_query($sql,$baglantim);
header("Location:panel.php?id=foto&id2=ekle&kayit=ok"); // resim eklenmi?tir

} else
header("Location:panel.php?id=foto&id2=ekle&hata=3");// dosyan?n tipi jpg veya gif de?il..
}else
header("Location:panel.php?id=foto&id2=ekle&hata=4");// dosyan?n boyutu büyük.
 
I got it

I have also added if statement below
$imk = imagecreatetruecolor (125, 75);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top