supermerc Posted July 25, 2007 Share Posted July 25, 2007 Hey I have a page where people are supposed to go and be able to update something into database but when they submit the form it works but it returns as my form (where i had my inputs and everything) gets posted like 100 times on the page and i cant figure out why this is my code <?php $query=mysql_query("select * from users where owname = '$_SESSION[s_username]' LIMIT 1") or die ("Error:".mysql_error()); while($row=mysql_fetch_array($query)){ ?> <form method="post"><table align="center"> <tr> <td>Outwar Name: </td> <td>Password:</td> </tr> <tr> <td><input name="textfield" type="text" readonly="true" value="<?=$row['owname']?>" /></td> <td><input type="text" name="password" value="<?=$row1['password']?>" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="passset" value="Submit" /></td> </tr> </table> </form> <?php if (isset($_POST['passset'])) { $_SESSION[formsubmited]=true; $now = date("F jS Y"); $password = mysql_escape_string($_POST['password']); $query = mysql_query("select * from pass where owname='".$_SESSION['s_username']."' LIMIT 1"); if (mysql_num_rows($query) != 1) { $query = mysql_query("INSERT INTO pass (owname, password, updated) VALUES ('$row[owname]','$password','$now')") or die(mysql_error()); }else { $sql = ("UPDATE pass SET password = '$password', updated = '$now' WHERE owname = '$_SESSION[s_username]'"); $qry = mysql_query($sql) or die("MySQL Error: <br /> {$sql} <br />". mysql_error()); } } } ?> thx Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 try now and see i think it the loop. <?php $query=mysql_query("select * from users where owname = '$_SESSION[s_username]' LIMIT 1") or die ("Error:".mysql_error()); while($row=mysql_fetch_array($query)){ ?> <form method="post"><table align="center"> <tr> <td>Outwar Name: </td> <td>Password:</td> </tr> <tr> <td><input name="textfield" type="text" readonly="true" value="<?=$row['owname']?>" /></td> <td><input type="text" name="password" value="<?=$row1['password']?>" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="passset" value="Submit" /></td> </tr> </table> </form> <?php } if (isset($_POST['passset'])) { $_SESSION[formsubmited]=true; $now = date("F jS Y"); $password = mysql_escape_string($_POST['password']); $query = mysql_query("select * from pass where owname='".$_SESSION['s_username']."' LIMIT 1"); if (mysql_num_rows($query) != 1) { $query = mysql_query("INSERT INTO pass (owname, password, updated) VALUES ('$row[owname]','$password','$now')") or die(mysql_error()); }else { $sql = ("UPDATE pass SET password = '$password', updated = '$now' WHERE owname = '$_SESSION[s_username]'"); $qry = mysql_query($sql) or die("MySQL Error: <br /> {$sql} <br />". mysql_error()); } } ?> Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 25, 2007 Author Share Posted July 25, 2007 But not it wont let me view the page if the people dont have anything in that table Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 25, 2007 Share Posted July 25, 2007 what? pls explain more Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 26, 2007 Author Share Posted July 26, 2007 like if i log on to an account that has something in the pass table its fine, but if its empy then it doesnt show the form Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 26, 2007 Share Posted July 26, 2007 because your form is inside that while which will only execute if the sql statement is not empty seee this while of yours while($row=mysql_fetch_array($query)){ ?> obviously if the while wont turn around then the data inside the while wont be process so what ? 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.