•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,371 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,826 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 399 | Replies: 12 | Solved
![]() |
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
All the code does is return the value # for everything even letters
php Syntax (Toggle Plain Text)
$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};
My Sites: SlyGraffix and Loved By Design
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
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
Last edited by Scottmandoo : Mar 27th, 2008 at 8:24 am.
My Sites: SlyGraffix and Loved By Design
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
You can use is_int
Eg.
Eg.
php Syntax (Toggle Plain Text)
if(is_int($letter2)){ $letter3="#"; } else { $letter3=$letter2; }
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
sorry, just tried testing again and it doesnt make the numbers change to the # symbol
My Sites: SlyGraffix and Loved By Design
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
php Syntax (Toggle Plain Text)
<?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(); } ?>
My Sites: SlyGraffix and Loved By Design
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!
•
•
•
•
$letter2 = $letter{0};
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- fstream Tutorial (C++)
- The quick 'n' dirty ultra simple vBulletin SEO hack (Existing Scripts)
- Quicksorting linked list - simple algorithm (C)
- How to install slackware (Not as easy as MEPIS) (Getting Started and Choosing a Distro)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- Browser problem's (HTML and CSS)
- Easy drop down menu? (JavaScript / DHTML / AJAX)
- expected error on homepage (HTML and CSS)
- please help! (C++)
- Amature Program- Lacking (C++)
Other Threads in the PHP Forum
- Previous Thread: How to give the variable value to textfield on same page?
- Next Thread: How can i use php to create a members profile???



Linear Mode