Dysan Posted January 18, 2008 Share Posted January 18, 2008 Hi, Can the following HTML (Form) and PHP code be merged into one file? HTML <!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> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <form name="form1" id="form1" method="post" action="login.php"> <label>ID:</label> <input name="id" type="text" id="id" /> <br /> <br /> <input name="save" type="submit" id="save" value="Save" /> </form> </body> </html> PHP [code=php:0]<?php session_start(); $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die(mysql_error()); } mysql_select_db("db", $con); $id = mysql_real_escape_string($_POST['id']); $data = mysql_query("SELECT * FROM users WHERE id='$id'"); $row = mysql_fetch_array($data); if(!mysql_num_rows($data)==0) { $_SESSION['token'] = 1; $_SESSION['user'] = $row['name']; $_SESSION['account'] = $row['account']; header("location: userpage.php"); exit(); } else { echo "Login Unsuccessful!"; } mysql_close($con); ?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/86707-merge-two-files/ Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 Yes Quote Link to comment https://forums.phpfreaks.com/topic/86707-merge-two-files/#findComment-443101 Share on other sites More sharing options...
Dysan Posted January 19, 2008 Author Share Posted January 19, 2008 How? - I'm stuck! Quote Link to comment https://forums.phpfreaks.com/topic/86707-merge-two-files/#findComment-443174 Share on other sites More sharing options...
trq Posted January 19, 2008 Share Posted January 19, 2008 Wrap all your php in this following... <?php if (isset($_POST['svae'])) { // you code goes here. } ?> Then simply place all the php code in the same file as your form and change the form decleration to read.... <form name="form1" id="form1" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/86707-merge-two-files/#findComment-443178 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 if (isset($_POST['save'])) { Would probably work a little better. Quote Link to comment https://forums.phpfreaks.com/topic/86707-merge-two-files/#findComment-443180 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.