Couls someone help me fix this code, I think I need to put in a function and a return but i'm not quite sure.
All the code does is return the value # for everything even letters

$letter       = ucfirst($_POST['tut_name']);
$letter2      = $letter{0};
 
    if($letter2 = 1) 
        { 
        $letter3 = '#';  
        } 
        else if ($letter2 = 2)   
            { 
            $letter3 = '#'; 
            } 
			else if ($letter2 = 3)   
            	{ 
            	$letter3 = '#'; 
            	}
				else if ($letter2 = 4)   
            		{ 
            		$letter3 = '#'; 
            		}
					else if ($letter2 = 5)   
            			{ 
            			$letter3 = '#'; 
            			}
						else if ($letter2 = 6)   
            				{ 
            				$letter3 = '#'; 
            				}
							else if ($letter2 = 7)   
            					{ 
            					$letter3 = '#'; 
            					}
								else if ($letter2 = 8)   
            						{ 
            						$letter3 = '#'; 
            						}
									else if ($letter2 = 9)   
            							{ 
            							$letter3 = '#'; 
            							}
										else if ($letter2 = 0)   
            								{ 
            								$letter3 = '#'; 
            								}
					else $letter3 = $letter{0};

I'm lost
Are you saying that your code currently returns # signs for all the text entered or are you saying that you would like it to return the # for your letters?

What are you wanting it to do, and what is it doing?

Sage

ok what i want my code to do is

If $letter2 = a number 1, 2, 3 etc. it sets $letter3 to '#'
If $letter2 = a letter it sets $letter3 to $letter2 so it pretty much stays the same

is that what you wanted to know?

And what my code currently does is just set $letter3 to '#' for letters and numbers

You can use is_int
Eg.

if(is_int($letter2)){
$letter3="#";
} else {
 $letter3=$letter2;
}
commented: Thanks +1

Thanks that works perfect!!!

You are welcome :)

sorry, just tried testing again and it doesnt make the numbers change to the # symbol

umm.. Can you post your code ?

<?php

$username="";
$password="";
$database="";

$tut_name     = $_POST['tut_name'];
$tut_image    = $_FILES['tut_image']['name'];
$letter       = ucfirst($_POST['tut_name']);
$letter2      = $letter{0};
 
if(is_int($letter2))
{$letter3='#';} 
else { $letter3=$letter2;}

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

if (empty($tut_image)) {
	$result = '<font color=FFFFFF>Please choose a rom to upload!</font>';
	$error++;
}
else {
		$filename = stripslashes($tut_image);
		$extension = getextension($filename);
		$extension = strtolower($extension);
		if (($extension !== "zip") && ($extension !== "rar")) {
			$result = '<font color=FFFFFF>Unknown file extension, please try again</font>';
			$error++;
		}
		else {
			$tmpFile = $_FILES['tut_image']['tmp_name'];
			$sizekb = filesize($tmpFile);
			if ($sizekb > 8000000) {
				$result = '<font color=FFFFFF>The file has exceeded the size limit, please try again</font>';
				$error++;
			}
			else {
				$imageName = '../files/gba-roms/' . time() . '.' . $extension;
				$copy = copy($tmpFile, $imageName);
				if (!$copy) {
					$result = '<font color=FFFFFF>File upload unsuccessful, please try again</font>';
					$error++;
				}
			}
		}
}
if ($error > 0) {
	echo $result;
}
else {

function ByteSize($bytes)  
    { 
    $size = $bytes / 1024; 
    if($size < 1024) 
        { 
        $size = number_format($size, 2); 
        $size .= ' KB'; 
        }  
    else  
        { 
        if($size / 1024 < 1024)  
            { 
            $size = number_format($size / 1024, 2); 
            $size .= ' MB'; 
            }  
        else if ($size / 1024 / 1024 < 1024)   
            { 
            $size = number_format($size / 1024 / 1024, 2); 
            $size .= ' GB'; 
            }  
        } 
    return $size; 
    } 

$size2 = ByteSize($sizekb);

	$con = mysql_connect('localhost',$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	$sql = "INSERT INTO `gba_roms` VALUES ('','$letter','$imageName','$letter3','$extension','$size2')";
	$query = mysql_query($sql) or die('Error: ' . mysql_error());

mysql_close();
}



?>

What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!

$letter2 = $letter{0};

What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!

Just uploading some files :)

But when I upload a file starting with 3, it inserts $letter3 as 3 not the # symbol

Use is_numeric instead of is_int :) !

Yep that works now, thanks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.