Hi All,
I am having a problem with Inserting Data from a generated form.
To explain this clearly the code is listed below. There are three pages and
a
table in the db.
When the sql statement is run, it ends at the INSERT clause.
Any help would be appreciated ...
-------------------------------
TABLE
-------------------------------
# phpMyAdmin MySQL-Dump
# version 2.2.0rc3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: ww2
# Generation Time: July 31, 2001, 9:39 am
# Server version: 3.23.25
# PHP Version: 4.0.2
# Database : test
# --------------------------------------------------------
#
# Table structure for table 'server'
#
CREATE TABLE server (
server_type varchar(4) NOT NULL default '0',
server_name varchar(10) NOT NULL default '0',
server_intip varchar(15) NOT NULL default '0',
server_intport int(5) NOT NULL default '0',
server_protocol char(3) NOT NULL default ' '
) TYPE=MyISAM;
-------------------------------
Page One
-------------------------------
<HTML><HEAD><TITLE>Select the Number of Onsite Servers you need: Step
1</TITLE></HEAD>
<BODY>
<FORM method="POST" action="create.servers.php3">
<P>Please Enter the Number of Onsite Servers your school needs.</P>
<P>Number of Servers: <INPUT type="text" name="num_servers" size=5></p>
<INPUT type="submit" value="Display Servers">
</FORM></BODY></HTML>
-------------------------------
Page Two
-------------------------------
<HTML>
<HEAD><TITLE>Create a Database Table: Step 2</TITLE></HEAD>
<BODY>
<FORM method="POST" action="create.servers.process.php">
<table cellspacing=5 cellpadding=5>
<tr>
<th>Server Type</th>
<th>Server Name</th>
<th>Internal Server IP</th>
<th>Internal Server Port</th>
<th>UDP/TCP</th>
</tr>
<?
for ($i = 0 ; $i <$num_servers; $i++) {
echo "
<tr>
<td align=center>
<select name=\"server_type[]\">
<option value=\"float\">web</option>
<option value=\"float\">mail</option>
<option value=\"float\">other</option>
</select>
</td>
<td align=center>
<input type=\"text\" name=\"server_name[]\" size=\"20\">
</td>
<td align=center>
<input type=\"text\" name=\"iserver_intip[]\" size=\"20\">
</td>
<td align=center>
<input type=\"text\" name=\"server_intport[]\" size=\"5\">
</td>
<td align=center>
<select name=\"server_protocol[]\">
<option value=\"float\">TCP</option>
<option value=\"float\">UDP</option>
</select>
</td>
</tr>";
}
?>
<tr><td align=center colspan=3><INPUT type="submit" value="Create
Table"></td></tr>
</table>
</FORM>
</BODY>
</HTML>
-------------------------------
Page Three
-------------------------------
<HTML>
<HEAD>
<TITLE>Inserting Data</TITLE></HEAD>
<BODY>
<h1>Inserting Data</h1>
<?
$sql = "INSERT INTO SERVER VALUES ("; for ($i = 0; $i <
count($server_type); $i++) {
$sql .= "$server_type[$i] $server_name[$i] $server_intip[$i]
$server_intport[$i]";
if ($server_protocol[$i] != "") {
$sql .= " ($server_protocol[$i]),";
} else {
$sql .= ",";
}
}
$sql = substr($sql, 0, -1);
$sql .= ")";
$connection = mysql_connect("localhost","username","password")
or die("Couldn't connect to server.");
$db = mysql_select_db("test", $connection)
or die("Couldn't select database.");
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't insert data!";
} else {
echo "<P>data inserted!";
}
?>
</BODY>
</HTML>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]