Jump to content

Weird Problem


supermerc

Recommended Posts

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

Link to comment
Share on other sites

 

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());
  }
}
?>

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.