Originally posted by phplearner
Hi again, drew010:
First, thank you for your kind assistance and the references.
FYI, I signed up (for Exhibit pass only) to the 1st MySQL Convention here in the San Jose area next week. I'm hoping there will be some new books, etc. there.
I'm near San Jose, I wanted to check out that convention in San Francisco but its 4 days long and I dont think it would work π
Unfortunately, my ISP is still at MySQL 3.23something, but think I can tweak all this up so that I actually will only have to "Update" 1 table (but with a $variable reference to table2 in one of the fields).
I should have been more specific with this, 3.23 is actually the distribution but your actual version is probably 11.xx. If you run mysql --version from the command line it will return your version.
On my server it returns: mysql Ver 11.18 Distrib 3.23.56, for pc-linux (i686)
Here is the new dilemna...perhaps you can help?
I already have a page which works fine...will pull in data from table2 and fields to INSERT a new record into table1 and will have a relational ID link field.
But what I'm stuck on now is a preliminary page for the user to enter their e-mail address, check the DB, and if already existing, to yield the table1 ID and Name.
If successful, to then have them click on a link to the details.php page for entering the data for table1. To do this, it appears I have to use a "hidden field" for the ID and in the details.php page a $_GET['ID'] to start with??? But right now I've got $ID so dunno about this.
It would be better if the user exists bypass the need to click on a link and just be whisked directly to the details.php page. I tried an action="details.php" in the <form> tag but that didn't work.
[/B]
I would have it check for the email address in the table, then use mysql_num_rows to tell you if there are any result rows, if not it means the dont exist, but if there is, issue a select query for the id and any other info you want, then send it to the details page using header("Location: details.php?include&any&query&string&here"); .
i hope im clear with that. if you use header, it must be printed before any html or text is output to the browser so all that must happen at the very top of the script.
5. The <form action="<?=$SERVER['PHP_SELF']?>" method="post"> tag is causing a parsing error which I don't understand, 'cuz I'm using the same thing in the details.php page with no problem whatsoever!!!
dont forget to include the terminating semicolon at the end.
<form action="<?=$SERVER['PHP_SELF'] --> ; <-- ?>"
Thank you again for your kind assistance through this nightmare.
<?
?>
<html>
<head>
<title> Edit Author </title>
</head>
<body>
<?
if (isset($POST['submit'])) {
$Email = $POST['Email'];
$dbcnx = @mysql_connect('localhost', 'me', '');
mysql_select_db('mydb');
// DB fields: ID, Name, Email
$author=@("SELECT ID, Name
FROM Authors
WHERE Email='$Email'");
$ID=$POST['ID'];
$Name=$POST['Name'];
if (@($author)) {
echo "<input type=\"hidden\" name=\"id\" value=\"$ID\">;
echo('<p>Hello, $Name! You are on file. Click <a href=\"details.php\">Here</a> To Continue...</p>');
} else {
echo('<p>The e-mail address you supplied is not recognized. Please Try Again.' .
mysql_error() . '</p>');
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Enter your e-mail address:<br>
Email: <input type="text" name="Email" size="20" maxlength="50"><br>
<input type="submit" name="submit" value="SUBMIT"></p>
</form>
</body>
</html>
<?
}
?>
I think that that sql above will not work because
$author=@("SELECT ID, Name
FROM Authors
WHERE Email='$Email'");
$ID=$POST['ID'];
$Name=$POST['Name'];
if (@($author)) {...
the first query will just return a value if the query is executed successfully, but no data is actually retrieved, because you must use mysql_fetch_row, or a similar function within a loop to get that, the second call to if(@($author)) shouldnt work at all because i dont think $author will contain a valid query. Look at the php manual on mysql_fetch_row. You must issue a query, then retrieve the data...and then do what you need depending on what data was returned. Below is what I would change your code to...
<?
if (isset($POST['submit'])) {
$Email = $POST['Email'];
$dbcnx = @mysql_connect('localhost', 'me', '');
mysql_select_db('mydb');
// DB fields: ID, Name, Email
$author=@("SELECT ID, Name
FROM Authors
WHERE Email='$Email'");
if(!mysql_num_rows($author) {
// If there are no results, they are not in the database.
echo('<p>The e-mail address you supplied is not recognized. Please Try Again.';
} // end if
else {
// If a row was returned, that means they were in the DB
$author_data = mysql_fetch_row($author);
// Return the data you requested from the SELECT query to an array.
$ID = $author_data[0]; // Since you selected id first, it becomes result 0 in the array.
$Name = $autor_data[1]; // name second, so its array element 1.
echo "<input type=\"hidden\" name=\"id\" value=\"$ID\">;
echo('<p>Hello, $Name! You are on file. Click <a href=\"details.php\">Here</a> To Continue...</p>');
} // end else
} // end isset POST[submit]
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Enter your e-mail address:<br>
Email: <input type="text" name="Email" size="20" maxlength="50"><br>
<input type="submit" name="submit" value="SUBMIT"></p>
</form>
</body>
</html>
hopefully that can solve some of the problems you encountered.