how do I insert verified, redisplayed form data into DB?

:o ... Greetings!

Am having a devil of a time inserting data into database. No, this is not the straight forward use of form data as input to an INSERT statement. Here’s the set-up:

  1. user provides data to be checked against a master database:

     		<TABLE CLASS="inputMatchTableBorder" WIDTH=275 ALIGN=CENTER>
     		<form action="index.php" method="post">
     				<td width=30% align=right>First&nbsp; Name </td>
     				<td width=70%><input type="text" name="firstName" size="25"></td>
     				<td width=30% align=right>Last&nbsp; Name </td>
     				<td width=70%><input type="text" name="lastName" size="25"></td>
     				<td width=30% align=right>Email </td>
     				<td width=70%><input type="text" name="eMail" size="25"></td>
     			<tr><td colspan=2 align=center><input type="submit" name="submit" value="Confirm"></td></tr>
  2. form data (user input) is used as input to a QUERY of the database to determine if user has an account:

     				$query_Membership = "SELECT * FROM Membership WHERE (firstName) = ('$lowercase_firstName') AND (lastName) = ('$lowercase_lastName')";
     				$result = @mysql_query($query_Membership);
     				$details = mysql_fetch_array($result);
  3. This is the problem area! How do I take the information retrieved from the database, display it for the user (to see and manually verify the accuracy of the first & last names and/or email address) and use the DISPLAYED DATA as INPUT for an INSERT into a different database?

<? if ($details['firstName'] <> ''){?> <?} else {?> <?}?> <? if ($details['lastName'] <> ''){?> <?} else {?> <?}?> <? if ($details['eMail'] <> ''){?> <?} else {?> <?}?>
Create "Members Only" access?
First Name  <?echo (" " . $details['firstName'] . "");?>
Last Name  <?echo (" " . $details['lastName'] . "");?>
Email  <?echo (" " . $details['eMail'] . "");?>
Username  <? $user = substr(($details['firstName']), 0, 1); $name = substr(($details['lastName']), 0); $username = $user . $name; echo (" " . $username . "");?>

not_a_bozo sez: Much thanks for your help with this!

(I hope this qualifies for a PHP-related question. I have a hard time determining when I am using PHP and MySQL statements. I guess this qualifies me as a Beginner and thus the use of this “Beginners” forum.)

If the data is inputed into the form elements all u need to do is add a standard insert query.

mysql_query(“insert into table set (field, field1, field2) values (’$var’, ‘$var1’, ‘$var2’)”);

If you are on about the previous form data then u should make hidden element with = the value of the previous variable or sessions to store the data till you need it.

Thank you, Pablo, for your time and your reply.

Your suggestion: (If the data is inputed into the form elements all u need to do is add a standard insert query) and my use of the user input: “SELECT * FROM 2004Membership WHERE (firstName) = (’$firstName’)” may be a sticking point.

That is, in another part of the displayed page I show the retrieved data within a form with a submit button labelled “Create.”

When the “Create” button is clicked I pass no data, just go to that same displayed page (again) and, within the code for that page is a test for the value of the “Create” button: if ($submit == “Create”)

… at this point the coding is supposed to INSERT the retrieved data:
$query = “INSERT INTO 2004MembersAccess (username, password, fname, lname, securitylevel, email, logincount) VALUES (’$username’, ‘$password’, ‘$firstName’, ‘$lastName’, 0, ‘$eMail’, 0)”;

BUT, when verifying the value of the data retrieved by the SELECT statement: echo ($details[‘lastName’] . " is the last name of the member

the output/site’s page shows ONLY the quoted part of the echo statement (“is the last name of the member”) … the retrieved data value is missing.

Where did the retrieved data go? (does this make sense?)

thanks again!


$query_Membership = “SELECT * FROM Membership WHERE firstName = “$lowercase_firstName” AND lastName = “$lowercase_lastName”)”;

Echo out your SQL command and echo out mine. Which is the one that you expect?


it was hard for me to understand your statement:
Echo out your SQL command and echo out mine. Which is the one that you expect?

“Echo out” … a bit cryptic, but I suspect you meant that I should put your query line and mine in two separate echo commands and see what happens (which I imagine will answer your question).

I did do as above, but found no difference in the output (that that is echoed onto the page) except for the parantheses show up on my echoed line.

How does this address my original problem/question: Once I have queried a database and presented the results on a web page, how do I then have someone click on a submit button on the presented results page and insert into another database, those values displayed on the page?



Your SQL:

$query_Membership = "SELECT * FROM Membership WHERE (firstName) = ('$lowercase_firstName') AND (lastName) = ('$lowercase_lastName')";

echo "My SQL = " . $query_Membership . “


$query_Membership1 = "SELECT * FROM Membership WHERE firstName = "$lowercase_firstName" AND lastName = "$lowercase_lastName")";

echo "lig’s SQL = " . $query_Membership1 . “

There is a slight difference in them. I honestly think it is the SQL that is the problem but your script is not designed to tell you that. So please remove the @ from infront of the mysql_query. We need to see the errors if they are generated - not suppress them. You also need to check $result to see if it is valid. You are making the assumption that it is when there will be times that it is not so you should handle it. A simple if (!$result) can throw an error message up. So it should look something like

$sql = "something";
Echo $sql; // show me the SQL query being sent to the DB
$result = mysql_query($sql);
if (!$result) // if the query has a problem
    // tell me there is a problem
    echo "There is an error in the query.  The error is ";
    // and what the problem is
    echo mysql_error();
Sponsor our Newsletter | Privacy Policy | Terms of Service