User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,950 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 2,603 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: 372 | Replies: 12 | Solved
Reply
Join Date: Feb 2008
Posts: 43
Reputation: Scottmandoo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Light Poster

Simple Code needs fixing

  #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: SlyGraffix and Loved By Design
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Simple Code needs fixing

  #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  
Join Date: Feb 2008
Posts: 43
Reputation: Scottmandoo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Light Poster

Re: Simple Code needs fixing

  #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 8:24 am.
My Sites: SlyGraffix and Loved By Design
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 7
Solved Threads: 206
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Maven

Re: Simple Code needs fixing

  #4  
Mar 27th, 2008
You can use is_int
Eg.
  1. if(is_int($letter2)){
  2. $letter3="#";
  3. } else {
  4. $letter3=$letter2;
  5. }
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 43
Reputation: Scottmandoo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Light Poster

Re: Simple Code needs fixing

  #5  
Mar 27th, 2008
Thanks that works perfect!!!
My Sites: SlyGraffix and Loved By Design
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 7
Solved Threads: 206
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Maven

Re: Simple Code needs fixing

  #6  
Mar 27th, 2008
You are welcome
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 43
Reputation: Scottmandoo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Light Poster

Re: Simple Code needs fixing

  #7  
Mar 27th, 2008
sorry, just tried testing again and it doesnt make the numbers change to the # symbol
My Sites: SlyGraffix and Loved By Design
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 7
Solved Threads: 206
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Maven

Re: Simple Code needs fixing

  #8  
Mar 27th, 2008
umm.. Can you post your code ?
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 43
Reputation: Scottmandoo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scottmandoo's Avatar
Scottmandoo Scottmandoo is offline Offline
Light Poster

Re: Simple Code needs fixing

  #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: SlyGraffix and Loved By Design
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,866
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 7
Solved Threads: 206
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Maven

Re: Simple Code needs fixing

  #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};
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*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC