geotri314 Posted July 27, 2010 Share Posted July 27, 2010 hi guys. i have a question. so, i have created a php script that handles a form, in a self referenced .php file. part of the php code is the below : <?php $name = $_POST['name']; $url = $_POST['url']; $username = $_POST['username']; $password = $_POST['password']; if($name) { echo <<<END <tt>You have just entered the following data:<br /> <table> <tr><td><tt>Name:</td><td><tt>$name</td></tr> <tr><td><tt>Link:</td><td><tt>$url</td></tr> <tr><td><tt>Username:</td><td><tt>$username</td></tr> <tr><td><tt>Password:</td><td><tt>$password</td></tr> </table> <br /> END; $dbc = mysqli_connect('localhost', '49713', '59725972', '49713') or die('skata... '); $query = "INSERT INTO forums (url, name, username, password) VALUES ('$url', '$name', '$username', '$password')"; $result = mysqli_query($dbc, $query) or die ('pali skata... '); mysqli_close($dbc); } echo <<<END <hr /><br />\n <table width="95%" rules="all">\n <tr><td><tt><b>Name</td><td><tt><b>URL</td><td><tt><b>Username</td><td><tt><b>Password</td></tr>\n END; $dbc = mysqli_connect('localhost', '49713', '59725972', '49713') or die ('Could connect to the sql db'); $query = "SELECT * FROM forums"; $result = mysqli_query($dbc, $query) or die('something went wrong with the query'); while($row = mysqli_fetch_array($result)) { echo "<tr>\n<td><tt><a href=\"" . $row['url'] . "\" target=\"_blank\"><tt>" . $row['name'] . "</tt></td>\n<td><tt><a href=\"" . $row['url'] . "\" target=\"_blank\"><tt>" . $row['url'] . "</tt></td>\n<td><tt>" . $row['username'] . "</tt></td>\n<td><tt>" . $row['password'] . "</tt></td>\n</tr>\n"; } ?> i wonder if there is a way, to keep the <?php ... ?> code on a different file and i call it whenever i want with the exact the same results. i dont know if i am making clear what i want, but i d like somehow, to have a way, to call this code and attach it to the page, whereas the code is stores on another file of its own, but without loading a different .php page so as to keep being self referenced. sorry for bothering you. can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/208986-call-a-script-from-outside-a-page/ Share on other sites More sharing options...
Adam Posted July 27, 2010 Share Posted July 27, 2010 You should wrap it in a function. Quote Link to comment https://forums.phpfreaks.com/topic/208986-call-a-script-from-outside-a-page/#findComment-1091630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.