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
https://forums.phpfreaks.com/topic/61740-weird-problem/
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
https://forums.phpfreaks.com/topic/61740-weird-problem/#findComment-307373
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
https://forums.phpfreaks.com/topic/61740-weird-problem/#findComment-307521
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.