Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/86707-merge-two-files/
Share on other sites

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">

Link to comment
https://forums.phpfreaks.com/topic/86707-merge-two-files/#findComment-443178
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.