Hi all,
I have a two-part form intended to replicate the output from a toolbar, with the aim of sending data to a database.

So the data is generated by the following code (sim1.php):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Start</title>
<link href="toolbar_popup.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post" action="toolbar_process.php">
            <input type="text" name="tbar_site"/>
            <br />
            <select name="tbar_type" size="2">
              <option value="h">housing</option>
              <option value="o">other</option>
            </select>
        <br />
        <input type="hidden" name="origin" value="tbar">
        <input type="submit" value="Enter details!"/>
        </form>
</body>
</html>

this is then sent to toolbar_process.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">

<!-- Begin
function popUp(URL) {
eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=200,height=300');");
}
// End -->
</script>
<title>Toolbar Process</title>
<link href="toolbar_popup.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
	<div id="text">
    <?php
		if (!isset($origin))	{
			require_once('connect.php');
			if ($_SERVER['REQUEST_METHOD'] == "POST")  
					{ 
						#set variables, stripslashes
						$type = addslashes($_POST["tbar_type"]); 
						$site = addslashes($_POST["tbar_site"]);
												
						# setup SQL statement
						$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site','$type','$origin')"; 
				
						#execute SQL statement 
						#$result = mysql_query($sql); 
				
						# check for error 
						if (mysql_error()) 
							{ 
								print "Database ERROR1: " . mysql_error(); 
							} 
						
						//message for user
						echo "<h1>Thanks!</h1>Your toolbar entry: ".$site.", was submitted.";	
					}
					$origin = NULL;
		}
?>
    	<h2>
        Got more?</h2>
        <form method="post" action="toolbar_process.php">
            <input type="text" name="site"/>
            <br />
            <select name="type" size="2">
              <option value="h">housing</option>
              <option value="o">other</option>
            </select>
        <br />
        <input type="submit" value="Enter details!"/>
        </form>
    </div>
<?php
require_once('connect.php');
if ($_SERVER['REQUEST_METHOD'] == "POST")  
    { 
#set variables, stripslashes
$type1 = addslashes($_POST["type"]); 
$site1 = addslashes($_POST["site"]);
$origin1 = "page";

# setup SQL statement
$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site1','$type1','$origin1')"; 

        #execute SQL statement 
        #$result = mysql_query($sql); 

        # check for error 
        if (mysql_error()) { print "Database ERROR1: " . mysql_error(); } 
		
		//message for user
		echo "<h1>Thanks!</h1>Your entry was submitted.";
	}
?>
	 </div>
</div>
</body>
</html>

The aim is that the data should either come from sim1.php, or if the user has landed on the second page without going to sim1, the data is sent via similar form.
Both times the origin is added to the row.
Sadly, the entries are not being recorded on mysql.

I'm sure it's almost there... Can anyone help?

Try uncommenting line 33 where you have commented the function mysql_query(). Also try replacing the $_SERVER with the following:

if (isset($_POST) && !empty($_POST)) {

Thanks cwarn.
I've altered the code as you suggested:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Toolbar Process</title>
<link href="toolbar_popup.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
	<div id="text">
    <?php
		if (!isset($origin))	{
			require_once('connect.php');
			if (isset($_POST) && !empty($_POST))  
					{ 
						#set variables, stripslashes
						$type = addslashes($_POST["tbar_type"]); 
						$site = addslashes($_POST["tbar_site"]);
						$origin1 = "tbar";
												
						# setup SQL statement
						$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site','$type','$origin')"; 
				
						#execute SQL statement 
						$result = mysql_query($sql); 
				
						# check for error 
						if (mysql_error()) 
							{ 
								print "Database ERROR1: " . mysql_error(); 
							} 
						
						//message for user
						echo "<h1>Thanks!</h1>Your toolbar entry: ".$site.", was submitted.";	
					}
					$origin = NULL;
		}
?>
    	<h2>
        Got more?</h2>
        <form method="post" action="toolbar_process.php">
            <input type="text" name="site"/>
            <br />
            <select name="type" size="2">
              <option value="h">housing</option>
              <option value="o">other</option>
            </select>
        <br />
        <input type="submit" value="Enter details!"/>
        </form>
    </div>
<?php
require_once('connect.php');
if ($_SERVER['REQUEST_METHOD'] == "POST")  
    { 
#set variables, stripslashes
$type1 = addslashes($_POST["type"]); 
$site1 = addslashes($_POST["site"]);
$origin1 = "page";

# setup SQL statement
$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site1','$type1','$origin1')"; 

        #execute SQL statement 
        $result = mysql_query($sql); 

        # check for error 
        if (mysql_error()) { print "Database ERROR1: " . mysql_error(); } 
		
		//message for user
		echo "<h1>Thanks!</h1>Your entry: ".$site1.", was submitted.";
	}
?>
	 </div>
     <h2>What now?</h2>
     Would you like to visit the <a href="index.php">wkho.me.uk homepage</a>?
     <br /> Or add to the <a href="directory_entry.php">Directory</a>?
</div>
</body>
</html>

The problem now is that I have two entries when submit is pressed (see attachment).
So, how do I enter just one new row/fire the sql once? And only show the relevant message...sheesh, I know that's a lot to ask!

Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Toolbar Process</title>
<link href="toolbar_popup.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
	<div id="text">
    <?php
		if (!isset($origin))	{
			require_once('connect.php');
			if (isset($_POST) && !empty($_POST))  
					{ 
						#set variables, stripslashes
						$type = mysql_real_escape_string($_POST["tbar_type"]); 
						$site = mysql_real_escape_string($_POST["tbar_site"]);
						$origin1 = "tbar";
												
						# setup SQL statement
						$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site','$type','$origin')"; 
				
						#execute SQL statement 
						$result = mysql_query($sql); 
				
						# check for error 
						if (mysql_error()) 
							{ 
								print "Database ERROR1: " . mysql_error(); 
							} 
						
						//message for user
						echo "<h1>Thanks!</h1>Your toolbar entry: ".$site.", was submitted.";	
					}
					$origin = NULL;
		}
?>
    	<h2>
        Got more?</h2>
        <form method="post" action="toolbar_process.php">
            <input type="text" name="site"/>
            <br />
            <select name="type" size="2">
              <option value="h">housing</option>
              <option value="o">other</option>
            </select>
        <br />
        <input type="submit" value="Enter details!"/>
        </form>
    </div>
<?php
require_once('connect.php');
if (isset($_POST) && !empty($_POST))  
    { 
#set variables, stripslashes
$type1 = mysql_real_escape_string($_POST["type"]); 
$site1 = mysql_real_escape_string($_POST["site"]);
$origin1 = "page";

# setup SQL statement
$sql  = "INSERT INTO `wkho_users`.`web_dir` (`site`, `type`,`origin`) VALUES ('$site1','$type1','$origin1')"; 

        #execute SQL statement 
        $result = mysql_query($sql); 

        # check for error 
        if (mysql_error()) { print "Database ERROR1: " . mysql_error(); } 
		
		//message for user
		echo "<h1>Thanks!</h1>Your entry: ".$site1.", was submitted.";
	}
?>
	 </div>
     <h2>What now?</h2>
     Would you like to visit the <a href="index.php">wkho.me.uk homepage</a>?
     <br /> Or add to the <a href="directory_entry.php">Directory</a>?
</div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.