Jump to content

form problem - seek troubleshooting advice


LoriB

Recommended Posts

Hello - I have a PHP form on a web site with text and images that is tied to a database.  The form is on an admin page.  When the user updates the text and clicks submit, the image deletes (the text updates successfully).  I am unable to identify and correct the problem.  Is anyone willing to take a look at the code and help troubleshoot?  Thanks so much!

Link to comment
https://forums.phpfreaks.com/topic/48675-form-problem-seek-troubleshooting-advice/
Share on other sites

Yes - here it is - thanks.

 

 

<?

 

$dir="../";

 

include "../includes/common.inc";

 

 

 

if ($_GET['agentID'])

 

{

 

$agentID=$_GET['agentID'];

 

}

 

 

 

if ($_POST['show'])

 

{

 

$show=$_POST['show'];

 

}

 

 

 

if ($_GET['confirmdelete'])

 

{

 

$confirmdelete=$_GET['confirmdelete'];

 

}

 

 

 

if($confirmdelete){

 

file_delete($globalvars[agentimagedir],"agentlist","agentID","photo",$confirmdelete);

 

 

 

$delQry=$globalvars[dblink]->mysql_query("delete FROM agentlist WHERE agentID = ".$confirmdelete);

 

header("location: agent_editor.php?updated=true");

 

exit;

 

}

 

elseif($_POST){

 

if($show[vtour]!=""){

 

$formvars[]=array("vtour","Virtual Tour","url");

 

}

 

$formvars[]=array("lastname","Last Name","text");

 

$formvars[]=array("firstname","First Name","text");

 

$formvars[]=array("phone","Phone","text");

 

if($show!=""){

 

$formvars[]=array("email","Email","email");

 

}

 

valid_form($formvars);

 

if(intval($show[agentID])<=0){

 

if(!$_FILES['photo']['tmp_name']){

 

$errorcount++;

 

$errors[]="Please select a photo";

 

}

 

}

 

 

 

if(!$errors){

 

if($_FILES['photo']['tmp_name']){

 

file_upload("photo",$globalvars[agentimagedir],$oldimage,"image1");

 

$show[photo]=$image1;

 

}

 

else{

 

$show[photo]=$oldimage;

 

}

 

 

 

$fields="agentID,lastname,firstname,location,content,phone,pager,photo,email";

 

$values=qry_use_magic(intval($show[agentID]),"n").qry_use_magic($show[lastname],"t").qry_use_magic($show[firstname],"t").

 

qry_use_magic($show[location],"t").qry_use_magic($show[content],"t").qry_use_magic($show[phone],"t").

 

qry_use_magic($show[pager],"t").qry_use_magic($show[photo],"t").qry_use_magic($show,"t",1);

 

$useqry="replace into agentlist (".$fields.") values(".$values.")";

 

$updQry=$globalvars[dblink]->mysql_query($useqry);

 

header("location: agent_editor.php?updated=true");

 

exit;

 

}

 

}

 

else{

 

if($agentID){

 

$getnewQry=$globalvars[dblink]->mysql_query("SELECT * FROM agentlist WHERE agentID = ".$agentID);

 

$show=mysql_fetch_assoc($getnewQry);

 

$oldimage=$show[photo];

 

}

 

else{

 

$show[location]="E";

 

}

 

}

 

 

 

show_cheader("agentlist Property Editor");

 

?>

 

 

 

<table>

 

<tr>

 

<td><img src="<?=$globalvars[imageurl]?>/admin_logo.gif" align="left" border="0">

 

</td>

 

</tr>

 

<tr>

 

<td> 

 

</td>

 

</tr>

 

</table>                                                                                                                                 

 

<cfoutput>

 

<script language="Javascript">

 

function confirmdelete(){

 

if (confirm("Are you sure you want to permanently delete this Agent?")) {

 

window.location="<?=$PHP_SELF?>?confirmdelete=<?=$show[agentID]?>"

 

}

 

}

 

function countchars(){

 

var usecount=document.update_agent_form['show[content]'].value;

 

if(usecount.length > 100){

 

alert('You have exceeded 100 characters');

 

}

 

}

 

</script>

 

</cfoutput>

 

<FONT size="+1">Agent Update Form</FONT> <BR>

 

 

 

<? dsp_errors($errorcount,$errors); ?>

 

 

 

<!--- Entry form --->

 

 

 

<FORM action="<?=$PHP_SELF?>" method="post" name="update_agent_form" enctype="multipart/form-data">

 

 

 

<input type="hidden" name="show[agentID]" value="<?=$show[agentID]?>">

 

<input type="hidden" name="oldimage" value="<?=$oldimage?>">

 

 

 

<TABLE border="0" width="400" bgcolor="eeeeee">

 

 

 

 

 

    <!--- Field: agents.lastname --->

 

    <TR>

 

    <TD valign="top"> Last Name </TD>

 

    <TD>

 

 

 

<INPUT type="text" name="show[lastname]" value="<?=$show[lastname]?>" maxLength="30">

 

 

 

</TD>

 

<td rowspan="4" width="100">

 

<?

 

$useimage=$show[photo]!=""&&!$errors?$globalvars[agentimageurl]."/".$show[photo]:$globalvars[imageurl]."/noimage.gif";

 

?>

 

<img src="<?=$useimage?>" name="photo" border="0" height="100" width="75">

 

</td>

 

</TR>

 

 

 

 

 

    <!--- Field: agents.firstname --->

 

    <TR>

 

    <TD valign="top"> First Name </TD>

 

    <TD>

 

 

 

<INPUT type="text" name="show[firstname]" value="<?=$show[firstname]?>" maxLength="50" required="yes" message="Please enter a first name.">

 

 

 

</TD>

 

</TR>

 

 

 

 

 

    <!--- Field: agents.location --->

 

    <TR>

 

    <TD valign="top"> Location</TD>

 

    <TD>

 

<INPUT type="radio" name="show[location]" value="E"<? if($show[location]=="E"){ echo " checked"; } ?>> East

 

<INPUT type="radio" name="show[location]" value="W"<? if($show[location]=="W"){ echo " checked"; } ?>> West

 

</TD>

 

</TR>

 

 

 

<tr>

 

<td colspan="2"> </td>

 

</tr>

 

 

 

    <!--- Field: agents.text --->

 

<tr>

 

    <TD colspan="3">

 

Agent blurb 115 characters max<br>

 

<textarea name="show[content]" cols="40" rows="4" wrap="virtual" onkeypress="countchars();"><?=$show[content]?></textarea>

 

 

 

</TD>

 

</TR>

 

<tr>

 

<td colspan="3"> </td>

 

</tr>

 

 

 

    <!--- Field: agents.phone --->

 

    <TR>

 

    <TD valign="top"> Phone </TD>

 

    <TD colspan="2">

 

 

 

<INPUT type="text" name="show[phone]" value="<?=$show[phone]?>" maxLength="50">

 

 

 

</TD>

 

</TR>

 

 

 

 

 

    <!--- Field: agents.pager --->

 

    <TR>

 

    <TD valign="top"> Pager </TD>

 

    <TD colspan="2">

 

 

 

<INPUT type="text" name="show[pager]" value="<?=$show[pager]?>" maxLength="50">

 

 

 

</TD>

 

</TR>

 

 

 

 

 

    <!--- Field: agents.email --->

 

    <TR>

 

    <TD valign="top"> Email </TD>

 

    <TD colspan="2">

 

 

 

<INPUT type="text" name="show" value="<?=$show?>" maxLength="50">

 

 

 

</TD>

 

</TR>

 

 

 

<!--- Field: agents.photo --->

 

    <TR>

 

    <TD valign="top">Photo:</TD>

 

    <TD colspan="2">

 

<INPUT type="file" name="photo" size="25" onchange="document.photo.src=document.update_agent_form.photo.value;">

 

 

 

 

 

</TD>

 

</TR>

 

</TABLE>

 

<br>

 

<?

 

$frmtxt=$show[agentID]>0?"Update":"Add";

 

?>

 

<INPUT type="submit" value="<?=$frmtxt?> Agent">

 

 

 

</FORM>

 

 

 

<?

 

if($show[agentID]>0){

 

?>

 

<FORM><INPUT type="button" value=" Delete Agent " onClick="confirmdelete()"></FORM>

 

<?

 

}

 

?>

 

 

 

<br>

 

Back to [ <a href="agent_editor.php">Agent Editor</a> ]

 

 

 

<? show_cfooter(); ?>

 

 

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.