Minimeallolla Posted November 11, 2010 Share Posted November 11, 2010 I'm trying to: when the submit button is hit, store data in a file (already created upon registration) and then show the files content. I have a few problems. The file im showing the content of cannot be found \= even though it was created using the same line as this.. if (isset($_POST['submit'])) { $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); include ("cookieusername.php"); $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) $filename = "***/$username.info.php" or exit("Unable to open file!"); $handle = @fopen($filename, 'x+')or die(mysql_error()); $content = "lololo"; @fwrite($handle, $content)or die(mysql_error()); @fclose($filename); } include ("***/$username.info.php")or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 what is *** ? Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted November 11, 2010 Author Share Posted November 11, 2010 its a hashed version of my directory for safety Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 So the file path is one folder below your script path? Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted November 11, 2010 Author Share Posted November 11, 2010 ("***/$username.info.php") for example is my filepath/directory.. im pretty sure the filepath is correct. Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted November 11, 2010 Author Share Posted November 11, 2010 ok ill just copy and paste the whole file but change the names of the directory for safety lol im paranoid >< ok well you only really need the part i first posted but this is all incase it makes a difference.. i posted my goal in the first post.. and for the content, i wanted to make it eg. $firstname. but that didnt work so i changed it to lolo and that dindt work so ergh >< <?php include ("database.php"); include ("cookieusername.php"); ?> <title> MySite - Profile - <?php echo $username ?> </title> <style type="text/css"> <!-- A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal } A:visited { COLOR: black; TEXT-DECORATION: none; font-weight: normal } A:active { COLOR: green; TEXT-DECORATION: none } A:hover { COLOR: blue; TEXT-DECORATION: none; font-weight: none } --> </style> <?php include ("nav.php"); include ("database.php"); // include ("echousername.php"); include ("background.php"); // include ("cookieusername.php"); // if ($_COOKIE['ID_my_site']) ?> <br><p> <div id="mydiv"> <style type="text/css"> DIV { display: none; } </style> <Center><b>Additional Details</b> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"><center> <Br><p><center><b>Bithrdate Day:<name="day" /> <select> <?php for($iii = 1; $iii <= 31; $iii++) { echo "<option>$iii</option>"; } ?> </select> Month:<name="month" /> <select> <option>January</option> <option>Febuary</option <option>March</option <option>April</option <option>May</option <option>June</option <option>July</option <option>August</option <option>September</option <option>October</option <option>November</option <option>December</option </select> Year:<name="year" /> <select> <?php for($iii = 1900; $iii <= 2010; $iii++) { echo "<option>$iii</option>"; } ?> </select><br /> First name: <input type="text" name="firstname" /><br /> Last name: <input type="text" name="lastname" /><br /> <b>Location</b><br /> Location: (eg, country, state, city)<input type="text" name="location" /><br /> <b>Gender</b><br /> <input type="radio" name="gender" value="male" />Male<br /> <input type="radio" name="gender" value="female" />Female<br /> <input type="submit" name="submit" value="submit" /> </form></table> </div> <?php //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = mysql_real_escape_string( $_COOKIE['ID_my_site'] ); $pass = mysql_real_escape_string( $_COOKIE['Key_my_site'] ); $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($username == $info['username']) echo "$username"; } } if (isset($_POST['submit'])) { $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); include ("cookieusername.php"); $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) $filename = "/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php" or exit("Unable to open file!"); $handle = @fopen($filename, 'x+')or die(mysql_error()); $content = "lololo"; @fwrite($handle, $content)or die(mysql_error()); @fclose($filename); } $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) include ("/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php")or die(mysql_error()); ?> <br> <center> <a href="javascript:;" onmousedown="if(document.getElementById('mydiv').style.display == 'none') { document.getElementById('mydiv').style.display = 'block'; } else{ document.getElementById('mydiv').style.display = 'none'; }">Edit Information.</a> </center> <br> <br> <br> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 Not sure why you are using mysql_error after fopen and fwrite. But remove the error suppression @ before fopen and fwrite so you can actually get an error report. Also, you have a mysql_error after a include? Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted November 11, 2010 Author Share Posted November 11, 2010 if i get rid of the @ infront of Fwrite or so, it comes up with function error.>< Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 That is a good sign.. post the error? Did you remove the mysql_errors after them? Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted November 11, 2010 Author Share Posted November 11, 2010 Warning: fopen(/home/bob/public_html/mysite/profiles/profileinfo/moo.info.php) [function.fopen]: failed to open stream: File exists in /home/bob/public_html/mysite/profiles/write.php on line 117 ok i changed it to this: if (isset($_POST['submit'])) { $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); include ("cookieusername.php"); $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) $filename = "/home/giacjrdi/public_html/mysite/profiles/profileinfo/$username.info.php" or exit("Unable to open file!"); $handle = fopen($filename, 'x+')or die(mysql_error()); $content = "lololo"; fwrite($handle, $content)or die(mysql_error()); fclose($filename); } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 'x+' Create and open for reading and writing; otherwise it has the same behavior as 'x'. You can't create what already exists. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 So that is all fixed up, repost your new code and ask your new question. Quote Link to comment 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.