Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Forms

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Forms

Postby kirkham99 » Wed May 21, 2003 1:52 am

All seems fine "apart" from I want to REFRESH the form by calling itself after it has deleted som of the rows etc ...

One form with a submit bttn of "search" will browse the database and list entries.

So I thought I could just set this ON and use the location function to re-drive the script but it does n't work saying Headers already output!

Whats the best way to redisplay/reprocess the form to display the NEW results minus the ones I have just delete??

Heres the latest script

<?php
header("Cache-Control:no-cache");
?>
<html>
<head>
</head>
<body>

<?php
#WINdows
$sqlhost = 'localhost:3306';
$sqluser = '??';
$sqlpass = '??';
$sqldb = 'test';

$utable = 'lm_users';




?>

<?php

if ($search)
{
$wher = "email like '%$searchemail%'";
include("dump_vars.php");
?>
<FORM name = "searchform2" method="post" action="<?php echo $PHP_SELF?>">
<br>
Search Email : <input type="text" name="searchemail" value="<?php echo $searchemail?>" size="37">
<input type="submit" name="search" value="search" >
</FORM>

<FORM name = "listdets" method="post" action="infodets.php">
<div align="left" style="width: 613; height: 68">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#00FFFF" width="710">
<tr>
<td width="58">Id</td>
<td width="148">First Name</td>
<td width="95">Last Name</td>
<td width="115">Email</td>
<td width="55">List</td>
<td width="71">Dateadd</td>
<td width="31">Edit </td>
<td width="26">Del </td>
<td width="46">Unsub</td>
</tr>
<?php
#connect to Mysql
$conn=mysql_connect($sqlhost,$sqluser,$sqlpass) or die("Could not connect to database");
$rs=mysql_select_db($sqldb, $conn) or die("Could not select the database");

$ucmd = "select * from $utable where $wher";
$urow = mysql_query($ucmd) or die("Could not execute the query " . mysql_errno().": ".mysql_error());
#$row2 = mysql_fetch_array($urow);
$cnt = mysql_num_rows($urow);

echo "Number of rows : $cnt <Br>";
$i=0;
while ($row = mysql_fetch_array($urow))
{

$fname = $row["fname"];
$lname = $row["lname"];
$list = $row["list"];
$email = $row["email"];
$dateadd = $row["dateadd"];
$id = $row["id"];
$uid = $row["uid"];

echo " <tr>";
echo " <td> <input type=text name=id[] size=5 value='$id'> </td>";
echo " <td width='148'> <input type=text name=fname[] size=20 value='$fname'> </td>";
echo " <td width='95'> <input type=text name=lname[] size=20 value='$lname'> </td>";
echo " <td width='115'> <input type=text name=email[] size=20 value='$email'> </td>";
echo " <td width='55'> <input type=text name=list[] size=5 value='$list'> </td>";
echo " <td width='71'> <input type=text name=dateadd[] size=15 value='$dateadd'> </td>";
echo " <td width='53'> <input type=checkbox name=opt[$i] value='Edit'> </td>";
echo " <td width='24'> <input type=checkbox name=opt[$i] value='Del'> </td>";
echo " <td width='46'> <input type=checkbox name=opt[$i] value='Unsub'> </td>";
echo " </tr>";
$i++;//incr cnt
}
?>

</table>
<p align="center">
<br>
<input type="submit" name="submit" value="Process the Form" >
</div>
</form>

<?php
exit();
}

if ($submit)
{
function quote( $var )
{
$var = '$var';
echo $var;
}
unset($submit);
include("dump_vars.php");
//process del, edit etc... and re-display
$i=0;
$ii=count($fname);
echo "count = $ii";

for($i=0;$i<$ii;$i++)
{
if ( !empty($opt[$i]) )
{
switch ($opt[$i])
{
case "Edit":
print "$i equals edit";
break;
case "Del":
print "$i equals del";
break;
case "Unsub":
print "$i equals unsub";
#connect to Mysql
$wher = "id = $id[$i] and email = '$email[$i]'";
$conn=mysql_connect($sqlhost,$sqluser,$sqlpass) or die("Could not connect to database");
$rs=mysql_select_db($sqldb, $conn) or die("Could not select the database");
$ucmd = "delete from $utable where $wher";
$urow = mysql_query($ucmd) or die("Could not execute the Delete query " . mysql_errno().": ".mysql_error());
echo "Number of rows Deleted: $cnt <Br>";
break;
}//end case
}//endif
} //endfor

$search = TRUE;
header("Location:infodets.php");
exit ();
} //endif
else
{
include("dump_vars.php");
?>
<p>
<FORM name = "searchform" method="post" action="<?php echo $PHP_SELF?>">
<input type=hidden name=dosearch value='yes'>
<br>
Search Email : <input type="text" name="searchemail" size="37">
<input type="submit" name="search" value="search" > <br>
</FORM>
<?php
}
?>

</body>
</html>
kirkham99
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Mar 11, 2003 8:25 am

Postby Redcircle » Wed May 21, 2003 11:49 pm

try putting the code that processes the form at the very top of the page before anything is output to the browser
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby kirkham99 » Thu May 22, 2003 4:06 am

I used a OP_START() on line 1 and it worked, do you know if this is good practise???
kirkham99
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Mar 11, 2003 8:25 am

Postby Redcircle » Thu May 22, 2003 4:58 am

I wouldn't use it cause the coding error is still there.. it's like when you get a noise on your car.. the solution.. turn the radio up louder.... but the problem still remains.

ob_start is an output buffer not an error catcher.


what is happening is something is outputting data to the browser.. this could even be a " ". If you then attempt to do a header call it will error out.. like I mentioned earlier. put your form processing code at the top.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron