Why does the Info typed on form fields stay?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bbnj23
Forum Newbie
Posts: 6
Joined: Thu Mar 13, 2008 5:53 pm
Location: newark, california usa

Why does the Info typed on form fields stay?

Post by bbnj23 »

Hi. I am currently taking up Advanced Dreamweaver and I encountered a problem re: sending forms that even my professor can't come up with an answer yet.

I created a basic form with a php extension but whatever information the first user typed in the fields won't get erased for the next user.
you may check:

http://www.wvcweb.com/avelina23b/lesson_6/exercise.php
to see the actual form issue.


Anyone with a brilliant idea on how to get this fixed? Perhaps someone has encountered the same thing before?


Thanks in advanced. :crazy:
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: Why does the Info typed on form fields stay?

Post by Inkyskin »

Could you post your PHP? We can't really do much without it...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Why does the Info typed on form fields stay?

Post by Christopher »

A place to start might be determine from whence those values are coming.
(#10850)
bbnj23
Forum Newbie
Posts: 6
Joined: Thu Mar 13, 2008 5:53 pm
Location: newark, california usa

Re: Why does the Info typed on form fields stay?

Post by bbnj23 »

Thank you for your interest to help. I'm not sure how members post files here other than the feature below that allows me to attach a file but when I tried, a php extension is not permissible so I am pasting it here instead.

I'm not sure what you meant by "it could have started with values???? But I'm sure you guys might trace it somehow with my codes.

Thanks again :D
+++++++++++++++++++++++++++++++++++++++++++++++

<?php require_once('../Connections/exercise_member.php'); ?>
<?php require_once('../Connections/exercise_signup.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "exercise_member")) {
$insertSQL = sprintf("INSERT INTO exercise_member (member_name1, member_name2, member_street, member_city, member_state, member_zip, member_phone) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['member_name1'], "text"),
GetSQLValueString($_POST['member_name2'], "text"),
GetSQLValueString($_POST['member_street'], "text"),
GetSQLValueString($_POST['member_city'], "text"),
GetSQLValueString($_POST['member_state'], "text"),
GetSQLValueString($_POST['member_zip'], "int"),
GetSQLValueString($_POST['member_phone'], "text"));

mysql_select_db($database_exercise_member, $exercise_member);
$Result1 = mysql_query($insertSQL, $exercise_member) or die(mysql_error());

$insertGoTo = "exercise_result.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "exercise_signup")) {
$insertSQL = sprintf("INSERT INTO exercise_signup (exercise_kind, exercise_bro, exercise_payment) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['exercise_kind'], "text"),
GetSQLValueString($_POST['exercise_bro'], "text"),
GetSQLValueString($_POST['exercise_payment'], "text"));

mysql_select_db($database_exercise_signup, $exercise_signup);
$Result1 = mysql_query($insertSQL, $exercise_signup) or die(mysql_error());

$insertGoTo = "exercise_result.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_exercise_member, $exercise_member);
$query_rsexercise_member = "SELECT member_name1, member_name2, member_street, member_city, member_state, member_zip, member_phone FROM exercise_member";
$rsexercise_member = mysql_query($query_rsexercise_member, $exercise_member) or die(mysql_error());
$row_rsexercise_member = mysql_fetch_assoc($rsexercise_member);
$totalRows_rsexercise_member = mysql_num_rows($rsexercise_member);

mysql_select_db($database_exercise_signup, $exercise_signup);
$query_rsexercise_signup = "SELECT exercise_kind, exercise_bro, exercise_payment FROM exercise_signup";
$rsexercise_signup = mysql_query($query_rsexercise_signup, $exercise_signup) or die(mysql_error());
$row_rsexercise_signup = mysql_fetch_assoc($rsexercise_signup);
$totalRows_rsexercise_signup = mysql_num_rows($rsexercise_signup);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Exercise Sign_Up</title>
<style type="text/css">
<!--
body {
background-color: #C9CDBD;
margin-left: 50px;
margin-top: 50px;
}
-->
</style></head>

<body>
<form name="exercise_member" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" target="_blank" id="exercise_member">
<table width="700" border="0" cellspacing="5">
<tr>
<td width="76"><div align="right">First Name:</div></td>
<td width="605"><input name="member_name1" type="text" id="member_name1" value="<?php echo $row_rsexercise_member['member_name1']; ?>" size="40" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">Last Name:</div></td>
<td><input name="member_name2" type="text" id="member_name2" value="<?php echo $row_rsexercise_member['member_name2']; ?>" size="40" maxlength="40" /></td>
</tr>
<tr>
<td><div align="right">Address 1:</div></td>
<td><input name="member_street" type="text" id="member_street" value="<?php echo $row_rsexercise_member['member_street']; ?>" size="40" maxlength="60" /></td>
</tr>
<tr>
<td><div align="right">Address 2:</div></td>
<td><input name="member_city" type="text" id="member_city" value="<?php echo $row_rsexercise_member['member_city']; ?>" size="40" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">State:</div></td>
<td><input name="member_state" type="text" id="member_state" value="<?php echo $row_rsexercise_member['member_zip']; ?>" size="40" maxlength="2" /></td>
</tr>
<tr>
<td><div align="right">Zip:</div></td>
<td><input name="member_zip" type="text" id="member_zip" value="<?php echo $row_rsexercise_member['member_zip']; ?>" size="40" maxlength="5" /></td>
</tr>
<tr>
<td><div align="right">Phone:</div></td>
<td><input name="member_phone" type="text" id="member_phone" value="<?php echo $row_rsexercise_member['member_phone']; ?>" size="40" maxlength="14" /></td>
</tr>
</table>
<p>&nbsp; </p>
<p>
<label for="label">What kind of exercise are you looking for?</label>
<br />
<input name="exercise_kind2" type="text" id="label" value="<?php echo $row_rsexercise_signup['exercise_kind']; ?>" size="40" maxlength="40" />
</p>
<p>
<label for="label2">Would you like to receive a brochure for complete info?</label>
<br />
<input name="exercise_bro2" type="text" id="label2" value="<?php echo $row_rsexercise_signup['exercise_bro']; ?>" size="10" maxlength="10" />
</p>
<p>
<label for="label3">Would you like to pay online or at the store?</label>
<br />
<input name="exercise_payment2" type="text" id="label3" value="<?php echo $row_rsexercise_signup['exercise_payment']; ?>" size="30" maxlength="30" />
</p>
<p>
<label for="label4"></label>
<input type="submit" name="sign_up2" id="label4" value="Sign Up!" />
</p>
<p></p>
<p>
<input type="hidden" name="MM_insert" value="exercise_member" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsexercise_member);

mysql_free_result($rsexercise_signup);
?>
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Why does the Info typed on form fields stay?

Post by Zoxive »

All of your Selects to get the current data have no WHERE condition.

So every time the page is loaded the 1st row is being selected.

Code: Select all

$query_rsexercise_member = "SELECT member_name1, member_name2, member_street, member_city, member_state, member_zip, member_phone FROM exercise_member";
//
$query_rsexercise_signup = "SELECT exercise_kind, exercise_bro, exercise_payment FROM exercise_signup";
->

Code: Select all

$query_rsexercise_member = "SELECT member_name1, member_name2, member_street, member_city, member_state, member_zip, member_phone FROM exercise_member WHERE id=$curid";
//
$query_rsexercise_signup = "SELECT exercise_kind, exercise_bro, exercise_payment FROM exercise_signup WHERE id=$signupid";
Now where you get these ID's is up to you, the easiest way would be to set sessions when the insert takes place, to save the ID it inserted.
bbnj23
Forum Newbie
Posts: 6
Joined: Thu Mar 13, 2008 5:53 pm
Location: newark, california usa

Re: Why does the Info typed on form fields stay?

Post by bbnj23 »

Looking at your code suggestion is promising but please be patient with me as you are dealing with an absolute neophyte in this field. 8O

When you say-
{"the easiest way would be to set sessions when the insert takes place, "}

Did you mean when I do the "insert record" inside the "Server Behaviour" in "Applications" window?

How do I change this codes other than doing it manually in "code" view. I do this in Dreamweaver by the way.


thanks.
bbnj23
Forum Newbie
Posts: 6
Joined: Thu Mar 13, 2008 5:53 pm
Location: newark, california usa

Re: Why does the Info typed on form fields stay?

Post by bbnj23 »

hi there,

I just want to say thanks for the clue Zoxive! I managed to find an id for my WHERE clause. I used the primary key of my field and set it to "0" so that when the form is viewed it shows record "0" which has no data in it.

Thanks again :D
Post Reply