tobimichigan Posted August 11, 2009 Share Posted August 11, 2009 This code: <?php include("cn.php"); $pfno=$_GET['id']; $row=mysql_query("SELECT (*) FROM user_table WHERE id=$id"); //$result = mysql_fetch_assoc($select); $num=mysql_fetch_array($row); //mysql_close(); $i=0; while ($i < $num) { $amountd=mysql_result($result,$i,"amountd"); $department=mysql_result($result,$i,"department"); $email=mysql_result($result,$i,"email"); $fname=mysql_result($result,$i,"fname"); $oname=mysql_result($result,$i,"oname"); $lname=mysql_result($result,$i,"lname"); $lga=mysql_result($result,$i,"lga"); $marital=mysql_result($result,$i,"marital"); $Nationalty=mysql_result($result,$i,"Nationalty"); $pfno=mysql_result($result,$i,"pfno"); $residentialadd=mysql_result($result,$i,"residentialadd"); $sex=mysql_result($result,$i,"sex"); $soorigin=mysql_result($result,$i,"soorigin"); $telno=mysql_result($result,$i,"telno"); //Space For Code $query = ("UPDATE user_table SET amountd = '$amountd', department = '$department', email = '$email', fname = '$fname', lga = '$lga', lname = '$lname',marital='$marital', Nationalty='$Nationalty',oname='$oname', residentialadd='$residentialadd', soorigin='$soorigin',telno='$telno', WHERE pfno = '$pfno'"); mysql_query($query); echo //"Record Updated"; mysql_close(); ++$i; } $amountd=$_POST['amountd']; $department=$_POST['department']; $email=$_POST['email']; $fname=$_POST['fname']; $lga=$_POST['lga']; $lname=$_POST['lname']; $marital=$_POST['marital']; $Nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $residentialadd=$_POST['residentialadd']; $soorigin=$_POST['soorigin']; $telno=$_POST['telno']; ?> <form action='Edit_Profile.php' method='post' enctype='multipart/form-data' name='register'> <table width='28%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td colspan='2'><div align='center'> <p><font size="2" face="verdana">Edit your Profile</font></p> </div></td> </tr> <tr> <td width='31%'> </td> <td width='69%'> </td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>PF NO.</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['pfno'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>FIRST NAME</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['fname'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>OTHER NAMES</font><font size='2' face='verdana'></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['oname'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LAST NAME</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['lname'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>STATE OF ORIGIN</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['soorigin'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LOCAL GOVERNMENT</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['lga'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>NATIONALITY</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['Nationalty'] ?>"> </font></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>Email address</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['email'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>RESIDENTIAL ADDRESS</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['residentialadd'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>TELEPHONE NUMBER</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['telno'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>DEPARTMENT</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['department'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>MARITAL STATUS</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['marital'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>SEX</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['sex'] ?>"> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>AMOUNT DEDUCTIBLE</font></td> <td><font size='2' face='verdana'> <input name="username" type="text" value="<?php echo $row['amountd'] ?>"> </font></td> </tr> <tr> <td> </td> <td><font size='2' face='verdana'> <input type='submit' name='Submit' value='Update'> </font></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form><div align='center'><font size='1' face='verdana'><a href='Admin_Login.php'>Back to login page</a></font></div> <td colspan='2'><div align='center'><font size='1' face='verdana'>TM</font></div></td> <td colspan='2'> </td> </body> </html> Is an edit_profile code, which is meant to display existing member information from the database and after editing the info update a table. But its not showing the exisitng data much less updating. Besides, its morelike show at the top of the browser: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in line24="$num=mysql_fetch_array($row);" Please any valid pointers would be appreciated. Thanks... Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted August 11, 2009 Share Posted August 11, 2009 $row=mysql_query("SELECT * FROM user_table WHERE id='$id'"); change $id into '$id' see if it could help Quote Link to comment Share on other sites More sharing options...
mars_rahul Posted August 11, 2009 Share Posted August 11, 2009 Ok do this <?php include("cn.php"); $pfno=$_GET['id']; $row=mysql_query("SELECT * FROM user_table WHERE id='$id'"); while ($num=mysql_fetch_array($row)) { ......... ........ ........ } Continue.... Well this may be other simple alternate and u also need to modify the code inside while loops. such as : $amountd = $num[amountd]; and same for other. Quote Link to comment Share on other sites More sharing options...
Solution PFMaBiSmAd Posted August 11, 2009 Solution Share Posted August 11, 2009 Your query is failing because the $id variable in it does not contain anything. Your code is setting $pfno=$_GET['id'];, not $id=$_GET['id']; You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you. Stop and start your web server to get any change made to php.ini to take effect and confirm that the values were changed using a phpinfo(); statement. You would have gotten an undefined error message about the nonexistent $id variable that would have pointed you in the right directing of finding the error in your code. You should should also be setting a default value for $id to handle those times when the page is requested with a URL that does not contain an ?id= on the end of the URL. You can use something like the following to set $id to either the $_GET variable or a default value - $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; // the (int) will protect against sql injection in an integer field value Quote Link to comment Share on other sites More sharing options...
tobimichigan Posted August 31, 2013 Author Share Posted August 31, 2013 Thanks you all for your contribution. 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.