943,651 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1296
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 27th, 2008
0

Simple Code needs fixing

Expand Post »
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

php Syntax (Toggle Plain Text)
  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};
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Scottmandoo is offline Offline
61 posts
since Feb 2008
Mar 27th, 2008
0

Re: Simple Code needs fixing

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
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007
Mar 27th, 2008
0

Re: Simple Code needs fixing

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Scottmandoo is offline Offline
61 posts
since Feb 2008
Mar 27th, 2008
1

Re: Simple Code needs fixing

You can use is_int
Eg.
php Syntax (Toggle Plain Text)
  1. if(is_int($letter2)){
  2. $letter3="#";
  3. } else {
  4. $letter3=$letter2;
  5. }
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 27th, 2008
0

Re: Simple Code needs fixing

Thanks that works perfect!!!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Scottmandoo is offline Offline
61 posts
since Feb 2008
Mar 27th, 2008
0

Re: Simple Code needs fixing

You are welcome
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 27th, 2008
0

Re: Simple Code needs fixing

sorry, just tried testing again and it doesnt make the numbers change to the # symbol
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Scottmandoo is offline Offline
61 posts
since Feb 2008
Mar 27th, 2008
0

Re: Simple Code needs fixing

umm.. Can you post your code ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 27th, 2008
0

Re: Simple Code needs fixing

php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Scottmandoo is offline Offline
61 posts
since Feb 2008
Mar 27th, 2008
0

Re: Simple Code needs fixing

What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!
Quote ...
$letter2 = $letter{0};
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to give the variable value to textfield on same page?
Next Thread in PHP Forum Timeline: How can i use php to create a members profile???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC