emery Posted January 22, 2012 Share Posted January 22, 2012 I have this code it is supposed to make a file with the random number and name inside it, but instead it makes a file with just the random number and the extention isn't there ".num" <?php $loca = $_POST['loca']; $name = $_POST['name']; if ( $loca == "" ) { echo "Error - Contact emery.cairns@gmail.com or STOP HACKING"; die; } else { if ( $name == "" ) { echo "Error - Contact emery.cairns@gmail.com or STOP HACKING"; die; } else { } } $rand = rand(100000, 999999); $myFile = $rand + ".num"; $fh = fopen($myFile, 'w') or die("Error with regerstration - please contact emery.cairns@gmail.com or try again"); $stringData = $rand + "\n"; fwrite($fh, $stringData); $stringData = $name + "\n"; fwrite($fh, $stringData); fclose($fh); echo "Hello "; echo $name ; echo " ... Your account number is "; echo $rand; $string = "\n\r Please write this number down, \n\r you may only get 1 from the webpage"; echo nl2br($string); setcookie("dsc", $rand, time()+9999999999999999999); ?> Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/ Share on other sites More sharing options...
litebearer Posted January 22, 2012 Share Posted January 22, 2012 this??? $myFile = $rand . ".num"; Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310084 Share on other sites More sharing options...
emery Posted January 22, 2012 Author Share Posted January 22, 2012 yea, that is the fle Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310093 Share on other sites More sharing options...
Labradoodle-360 Posted January 22, 2012 Share Posted January 22, 2012 Is there a reason that you're using the file functions rather than just using file_put_contents? Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310096 Share on other sites More sharing options...
emery Posted January 22, 2012 Author Share Posted January 22, 2012 Nope , just the way I learned, you can teach me the other way if you wish Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310105 Share on other sites More sharing options...
emery Posted January 23, 2012 Author Share Posted January 23, 2012 this??? $myFile = $rand . ".num"; Ok, that worked, but now when it creates the file it puts an extra 0 at the end of the RAND number and it doesn't print $NAME on it Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310162 Share on other sites More sharing options...
litebearer Posted January 23, 2012 Share Posted January 23, 2012 the plus sign + is used for MATH. the period . is used to join text together. You are trying to use plus to join text $stringData = $name + "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310168 Share on other sites More sharing options...
emery Posted January 23, 2012 Author Share Posted January 23, 2012 ok, but why does it add another "0" to the end of my RaND number when its in the file, ECHO $RAND doesn't print the extra 0 Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310184 Share on other sites More sharing options...
AyKay47 Posted January 23, 2012 Share Posted January 23, 2012 ok, but why does it add another "0" to the end of my RaND number when its in the file, ECHO $RAND doesn't print the extra 0 where exactly in the text file? you use rand() several times to add data into the file. can you post the file contents. Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310188 Share on other sites More sharing options...
emery Posted January 23, 2012 Author Share Posted January 23, 2012 If the $RAND ='s 287685 the file ='s 2876850 When it is supposed to look something like this 287685 "Name" Quote Link to comment https://forums.phpfreaks.com/topic/255535-file-help/#findComment-1310189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.