raghu_tak Posted June 11, 2013 Share Posted June 11, 2013 friends,this is a code of head first php bookit is used to edit a profile of user who has logged in but when i edit a profile the page displayed again with no feedback please help me friends!! <html> <head><title> Edit Profile </title></head> <body> <h1 style="color:brown;"><center>Please Edit your profile to find new mismatch.</center></h1> <form enctype="multipart/form-data" method="post" action="<?php echo$_SERVER['PHP_SELF']; ?>"> <p><i><center>This information would be seen by others and easily get connected to you.</center></i></p> <hr/> <img src="images1\mismatch.jpg" width="400" height="400" alt="mismatch image." align="right"> <fieldset style="width:250"> <legend>Edit your profile</legend> <table><tr> <td><label for="fname">Firstname:</label></td> <td><input type="text" id="fname" name="fname"><br/></td> </tr><tr> <td><label for="lname">Lastname:</label></td> <td><input type="text" id="lname" name="lname"><br/></td> </tr><tr> <td><label for="bday">Birthday:</label></td> <td><input type="text" id="bday" name="bday"><br/></td> </tr><tr> <td><label for="sex">Gender:</label></td> <td><input type="text" id="sex" name="sex"><br/></td> </tr><tr> <td><label for="nation">Country:</label></td> <td><input type="text" id="nation" name="nation"><br/></td> </tr><tr> <td><label for="screenshot">Picture:</label></td> <td><input type="file" name="screenshot" value="Choose image"><br/></td> </tr></table> </fieldset> <input type="submit" name="submit" value="Save"> <?php define('upath','mismatch/images1/'); define('msize',1024*50); if(isset($_SESSION['user_id'])) { $id1=$_SESSION['user_id']; if(isset($_POST['submit'])) { $dbc=mysqli_connect('localhost','root','','mismatch') or die('Error connceting database'); if((!empty($_POST['fname']))&&(!empty($_POST['lname']))&&(!empty($_POST['bday']))&& (!empty($_POST['sex']))&&(!empty($_POST['nation']))) { $fname=$_POST['fname']; $lname=$_POST['lname']; $bday=$_POST['bday']; $sex=$_POST['sex']; $nation=$_POST['nation']; if(!empty($_FILES['screenshot']['name'])) { $screenshot=$_FILES['screenshot']['name']; if(($_FILES['screenshot']['size']>0)&&($_FILES['screenshot']['size']<msize)) { $target=upath.$screesnhot; if(move_uploaded_file($_FILES['screenshot']['tmp_name'],$target)) { $query="SELECT * FROM mismatch_user WHERE user_id=$id1"; $result=mysqli_query($dbc,$query) or die('Error getting data'); if(mysqli_num_rows($result)==1) { $query1="UPDATE mismatch_user SET firstname='$fname', lastname='$lname', birthday='$bday',". "gender='$sex', country='$nation', picture='$screenshot' WHERE user_id='$id1'"; $result1=mysqli_query($dbc,$query1) or die('Error quering database'); echo'<br/><b>Profile Edited successfully</b>'; } } else { echo'<br/><b/>File cannot be uploaded'; } } else { echo'<br/><b/>Check size of Image.'; } } else { $query1="UPDATE mismatch_user SET firstname='$fname', lastname='$lname', birthday='$bday',". "gender='$sex', country='$nation' WHERE user_id='$id1'"; $result2=mysqli_query($dbc,$query2) or die('Error quering database'); echo'<br/><b>Profile Edited successfully</b>'; } } else { echo'<br/><b/>Please Enter all the information.'; } } } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/ Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 (edited) - Firstly, display your code in code tags, identified by the "<>" icon on the top - Second, make you have all your logic ABOVE the HTML. - Trim your code to the stuff that is relevant - Ask a question and tell us what is not working. - It would be wise to indent your code :/ this is so hard to read. Seriously, you arent even asking a question. Edited June 11, 2013 by DaveyK Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435353 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 friend i have did all this stuffbut its not helping me Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435354 Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 I dont see your code in code blocks. So thats one thing you havent done. None of the things I said will actually solve anything. But it MAY help us understand your problem and give guidance (we wont solve your problem for you. Well sometimes we will.). REGARDLESS, I am completely missing your problem. What is the issue?! Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435356 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 this is a file please see it once this code is get refreshed everytime when i click a submit button. edit.php Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435359 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 the data is not updated in database Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435360 Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 HERE, this is what we need. Not a file, but code in code blocks: <?php define('upath','mismatch/images1/'); define('msize',1024*50); if(isset($_SESSION['user_id'])) { $id1=$_SESSION['user_id']; if(isset($_POST['submit'])) { $dbc=mysqli_connect('localhost','root','','mismatch') or die('Error connceting database'); if((!empty($_POST['fname']))&&(!empty($_POST['lname']))&&(!empty($_POST['bday']))&& (!empty($_POST['sex']))&&(!empty($_POST['nation']))) { $fname=$_POST['fname']; $lname=$_POST['lname']; $bday=$_POST['bday']; $sex=$_POST['sex']; $nation=$_POST['nation']; if(!empty($_FILES['screenshot']['name'])) { $screenshot=$_FILES['screenshot']['name']; if(($_FILES['screenshot']['size']>0)&&($_FILES['screenshot']['size']<msize)) { $target=upath.$screesnhot; if(move_uploaded_file($_FILES['screenshot']['tmp_name'],$target)) { $query="SELECT * FROM mismatch_user WHERE user_id=$id1"; $result=mysqli_query($dbc,$query) or die('Error getting data'); if(mysqli_num_rows($result)==1) { $query1="UPDATE mismatch_user SET firstname='$fname', lastname='$lname', birthday='$bday',". "gender='$sex', country='$nation', picture='$screenshot' WHERE user_id='$id1'"; $result1=mysqli_query($dbc,$query1) or die('Error quering database'); echo'<br/><b>Profile Edited successfully</b>'; } } else { echo'<br/><b/>File cannot be uploaded'; } } else { echo'<br/><b/>Check size of Image.'; } } else { $query2="UPDATE mismatch_user SET firstname='$fname', lastname='$lname', birthday='$bday',". "gender='$sex', country='$nation' WHERE user_id='$id1'"; $result2=mysqli_query($dbc,$query2) or die('Error quering database'); echo'<br/><b>Profile Edited successfully</b>'; } } else { echo'<br/><b/>Please Enter all the information.'; } } } ?> <html> <head><title> Edit Profile </title></head> <body> <h1 style="color:brown;"><center>Please Edit your profile to find new mismatch.</center></h1> <form enctype="multipart/form-data" method="post" action="<?php echo$_SERVER['PHP_SELF']; ?>"> <p><i><center>This information would be seen by others and easily get connected to you.</center></i></p> <hr/> <img src="images1\mismatch.jpg" width="400" height="400" alt="mismatch image." align="right"> <fieldset style="width:250"> <legend>Edit your profile</legend> <table><tr> <td><label for="fname">Firstname:</label></td> <td><input type="text" id="fname" name="fname"><br/></td> </tr><tr> <td><label for="lname">Lastname:</label></td> <td><input type="text" id="lname" name="lname"><br/></td> </tr><tr> <td><label for="bday">Birthday:</label></td> <td><input type="text" id="bday" name="bday"><br/></td> </tr><tr> <td><label for="sex">Gender:</label></td> <td><input type="text" id="sex" name="sex"><br/></td> </tr><tr> <td><label for="nation">Country:</label></td> <td><input type="text" id="nation" name="nation"><br/></td> </tr><tr> <td><label for="screenshot">Picture:</label></td> <td><input type="file" name="screenshot" value="Choose image"><br/></td> </tr></table> </fieldset> <input type="submit" name="submit" value="Save"> </body></html> Okay so it doesnt update even tho you would expect it to. A good step at debugging would be to add echos or var_dumps to see which IFs are triggering and which arent. Its a really basic process, but you can try something like: if(isset($_SESSION['user_id'])) { echo 'User session is set<br>'; $id1=$_SESSION['user_id']; if(isset($_POST['submit'])) { echo 'Form is submitted<br>'; $dbc=mysqli_connect('localhost','root','','mismatch') (...) Do that on several key IF statements, to see where your code is going. The issue doesnt have to be lay in the PHP. Try it out and see how far your script actually goes. Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435361 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 not worked same happens again... Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435364 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 even this code not executed echo 'Form is submitted<br>'; Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435365 Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 If nothing is echoed then that means your SESSION is not set. Try doing a var_dump on $_SESSION on the top of the page, like so: <?php define('upath','mismatch/images1/'); define('msize',1024*50); var_dump($_SESSION); die(); // kill the rest of the page if(isset($_SESSION['user_id'])) { What does that echo? Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435366 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 Sorry but please explain what will var_dump will do and what it is? Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435367 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 nothing is displayed just NULL is written on top left corner... why? Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435369 Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 That is because you are not creating a session, check out the function session_start() and how you can use it. Also, I PRESUME you are checking for a session because you have some sort of login functionality. Since you built a login system, I presume you also know how to handle sessions. Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435370 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 yes i have built a login system that redirects to edit page means current page but when we edit our information no data is updated in database and i have created a session using session_start(); so i didnt use it again in edit page because session_id is set now. i am attaching login script too please have a look on it too. loginx.php Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435371 Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 The session on a page will only exist if you call session_start() on that page, and as the var_dump shows the issue you are facing has nothing to do with your update. The issue lies in the fact that you dont have a session active on that page. Make sure you have a session and go from there. Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435372 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 i wrote this this session_start() in my script but nothing happened same output nothing. but when i write if(!isset($_SESSION['user_id'])) at place of if(isset($_SESSION['user_id'])) i got feedback 'profile updated successfully'. but when i saw my database nothing was updated. Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435374 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 hey thanks a lot it now updated i retried again and now this worked but i don't know what happened to it first time..lol Thanks a lot genius. Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435375 Share on other sites More sharing options...
raghu_tak Posted June 11, 2013 Author Share Posted June 11, 2013 But following script causing another problem you see i get following errors Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\raghu\mismatch\edit.php on line 26Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php121B.tmp' to 'images1/' in C:\xampp\htdocs\raghu\mismatch\edit.php on line 26 if(move_uploaded_file($_FILES['screenshot']['tmp_name'],$target)) { $query="SELECT * FROM mismatch_user WHERE user_id=$id1"; $result=mysqli_query($dbc,$query) or die('Error getting data'); if(mysqli_num_rows($result)==1) { $query1="UPDATE mismatch_user SET firstname='$fname', lastname='$lname', birthday='$bday',". "gender='$sex', country='$nation', picture='$screenshot' WHERE user_id='$id1'"; $result1=mysqli_query($dbc,$query1) or die('Error quering database'); echo'<br/><b>Profile Edited successfully</b>'; Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435377 Share on other sites More sharing options...
DaveyK Posted June 12, 2013 Share Posted June 12, 2013 (edited) i wrote this this session_start() in my script but nothing happened same output nothing. but when i write if(!isset($_SESSION['user_id'])) at place of if(isset($_SESSION['user_id'])) i got feedback 'profile updated successfully'. but when i saw my database nothing was updated. ofc this works, but thats exactly what you DONT want. Please put your code in code blocks. What you need to think about is: how can I solve this issue on my own without making someone else do it for me. You have two error messages, so copy the first and google it. http://bit.ly/11GeVRp The first link is a stackoverflow question. The answer is on that page. Do some research and dont expect us to do it for you. Edited June 12, 2013 by DaveyK Quote Link to comment https://forums.phpfreaks.com/topic/279036-hello-friends-please-help-me-in-this-too/#findComment-1435500 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.