Simple Code needs fixing

Thread Solved

Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Simple Code needs fixing

 
0
  #1
Mar 27th, 2008
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

  1. $letter = ucfirst($_POST['tut_name']);
  2. $letter2 = $letter{0};
  3.  
  4. if($letter2 = 1)
  5. {
  6. $letter3 = '#';
  7. }
  8. else if ($letter2 = 2)
  9. {
  10. $letter3 = '#';
  11. }
  12. else if ($letter2 = 3)
  13. {
  14. $letter3 = '#';
  15. }
  16. else if ($letter2 = 4)
  17. {
  18. $letter3 = '#';
  19. }
  20. else if ($letter2 = 5)
  21. {
  22. $letter3 = '#';
  23. }
  24. else if ($letter2 = 6)
  25. {
  26. $letter3 = '#';
  27. }
  28. else if ($letter2 = 7)
  29. {
  30. $letter3 = '#';
  31. }
  32. else if ($letter2 = 8)
  33. {
  34. $letter3 = '#';
  35. }
  36. else if ($letter2 = 9)
  37. {
  38. $letter3 = '#';
  39. }
  40. else if ($letter2 = 0)
  41. {
  42. $letter3 = '#';
  43. }
  44. else $letter3 = $letter{0};
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

 
0
  #2
Mar 27th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

 
0
  #3
Mar 27th, 2008
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
Last edited by Scottmandoo; Mar 27th, 2008 at 9:24 am.
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Simple Code needs fixing

 
1
  #4
Mar 27th, 2008
You can use is_int
Eg.
  1. if(is_int($letter2)){
  2. $letter3="#";
  3. } else {
  4. $letter3=$letter2;
  5. }
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

 
0
  #5
Mar 27th, 2008
Thanks that works perfect!!!
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Simple Code needs fixing

 
0
  #6
Mar 27th, 2008
You are welcome
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

 
0
  #7
Mar 27th, 2008
sorry, just tried testing again and it doesnt make the numbers change to the # symbol
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Simple Code needs fixing

 
0
  #8
Mar 27th, 2008
umm.. Can you post your code ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 52
Reputation: Scottmandoo is an unknown quantity at this point 
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

 
0
  #9
Mar 27th, 2008
  1. <?php
  2.  
  3. $username="";
  4. $password="";
  5. $database="";
  6.  
  7. $tut_name = $_POST['tut_name'];
  8. $tut_image = $_FILES['tut_image']['name'];
  9. $letter = ucfirst($_POST['tut_name']);
  10. $letter2 = $letter{0};
  11.  
  12. if(is_int($letter2))
  13. {$letter3='#';}
  14. else { $letter3=$letter2;}
  15.  
  16. function getExtension($str) {
  17. $i = strrpos($str,".");
  18. if (!$i) { return ""; }
  19. $l = strlen($str) - $i;
  20. $ext = substr($str,$i+1,$l);
  21. return $ext;
  22. }
  23.  
  24. if (empty($tut_image)) {
  25. $result = '<font color=FFFFFF>Please choose a rom to upload!</font>';
  26. $error++;
  27. }
  28. else {
  29. $filename = stripslashes($tut_image);
  30. $extension = getextension($filename);
  31. $extension = strtolower($extension);
  32. if (($extension !== "zip") && ($extension !== "rar")) {
  33. $result = '<font color=FFFFFF>Unknown file extension, please try again</font>';
  34. $error++;
  35. }
  36. else {
  37. $tmpFile = $_FILES['tut_image']['tmp_name'];
  38. $sizekb = filesize($tmpFile);
  39. if ($sizekb > 8000000) {
  40. $result = '<font color=FFFFFF>The file has exceeded the size limit, please try again</font>';
  41. $error++;
  42. }
  43. else {
  44. $imageName = '../files/gba-roms/' . time() . '.' . $extension;
  45. $copy = copy($tmpFile, $imageName);
  46. if (!$copy) {
  47. $result = '<font color=FFFFFF>File upload unsuccessful, please try again</font>';
  48. $error++;
  49. }
  50. }
  51. }
  52. }
  53. if ($error > 0) {
  54. echo $result;
  55. }
  56. else {
  57.  
  58. function ByteSize($bytes)
  59. {
  60. $size = $bytes / 1024;
  61. if($size < 1024)
  62. {
  63. $size = number_format($size, 2);
  64. $size .= ' KB';
  65. }
  66. else
  67. {
  68. if($size / 1024 < 1024)
  69. {
  70. $size = number_format($size / 1024, 2);
  71. $size .= ' MB';
  72. }
  73. else if ($size / 1024 / 1024 < 1024)
  74. {
  75. $size = number_format($size / 1024 / 1024, 2);
  76. $size .= ' GB';
  77. }
  78. }
  79. return $size;
  80. }
  81.  
  82. $size2 = ByteSize($sizekb);
  83.  
  84. $con = mysql_connect('localhost',$username,$password);
  85. @mysql_select_db($database) or die( "Unable to select database");
  86. $sql = "INSERT INTO `gba_roms` VALUES ('','$letter','$imageName','$letter3','$extension','$size2')";
  87. $query = mysql_query($sql) or die('Error: ' . mysql_error());
  88.  
  89. mysql_close();
  90. }
  91.  
  92.  
  93.  
  94. ?>
My Sites: SlickTunes and Loved By Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,748
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Simple Code needs fixing

 
0
  #10
Mar 27th, 2008
What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!
$letter2 = $letter{0};
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC