<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
//The below lines are executed when the user has completed the specified areas.
//My problem is that I need the application to store the values it receives from the user into this file in order to get the $app_id.
//But I also need to print something on this page or redirect it to another page like with a header.
//I also need to include this file, plus some other parts that are not important, in four other files and I do not want to redirect or print messages on those pages.
//So, what I need to know is how can I possibly make $app_id a variable that I can include in other files without the other stuff.
//Or, is there a way to manipulate the messages or header whichever I decide to use to only work the first time and not when it is included?
$info = mysql_connect("localhost","*******", "*******")
or die("Could not connect:" . mysql_error());
mysql_select_db("apps");
mysql_query("INSERT INTO PERSONAL_DATA VALUES ('','$first_name','$last_name', CURRENT_DATE,
'$address', '$city', '$state', '$zip', '$phone_num', '$alt_phone', '$dob', '$ssnum')");
$app_id = mysql_query("SELECT PD_ID FROM PERSONAL_DATA WHERE FIRST_NAME = '$first_name' AND LAST_NAME='$last_name'
AND ADDRESS = '$address' AND ZIP = '$zip' AND PHONE = '$phone_num' AND DOB = '$dob'")
or die("Invalid query: " . mysql_error()); //this is where I am getting the id that I need and storing it into a variable.
mysql_close($info);
print "You have completed the application click here."
?>
</body>
</html>
If you include that code elsewhere, you're going to have a mess on your hands because you'll be inserting a new record each time 🙁
I see two separate problems here:
- As your code exists, you have not successfully retrieved $app_id. you need to fetch the row.
- This really doesn't stand on its own. just make it an include-- you don't need any output with it (no html). That way you just include it in whatever script you're going to. But I don't think you'll need it more than once. When you get the user's id, put it in a session variable , then its available to every script.