Jump to content

Multiple lines in SQL DB??


slpctrl

Recommended Posts

Here's my code:

 

index.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>test</title>
<script language="javascript" src="scripts.js">
function makefields(num_clas)
{
document.getElementById('fields').innerHTML=""
var b = num_clas
for (a=1; a<=b; a++)
{
document.getElementById('fields').innerHTML+="<tr><td><input type='text' name='field1' id='field1' width='100' align='left' maxlength='25' /></td><td><input type='text' name='field2' id='field2' width='100' align='left' maxlength='20' /></td> <td><input type='text' name='field3' id='field3' width='100' align='left' maxlength='10' /></td> <td><select name='field4' id='field4'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>5</option> <option value='5'>5</option> </select></td> <td><input type='text' name='field5' id='field5' width='100' align='left' maxlength='10' /></td> <td><input type='text' name='field6' id='field6' width='100' align='left' maxlength='15' /></td></tr>"
}
}
</script>
</head>
<body>
<form id='newuser' name='newuser' method='post' action='create.php'>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="25%"> </td>

<td width="50%" align="center">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr height="30">
<td width="50"> </td>
<td width="250"> </td>
<td width="50"> </td>
</tr>
<tr align="center" height="50">
<td> </td>

<td>
<table width='800' border='0'>
<tr>
<td><strong>header:</strong></td>
<td colspan='5'>Number of fields: <input type='text' name='num_clas' id='num_clas' size='2' maxlength='2' onKeyUp='makefields(this.value)' /></td>
</tr>
<tr>
<td>field 1:</td>
<td>field 2:</td>
<td>field 3:</td>
<td>field 4:</td>
<td>field 5:</td>
<td>field 6:</td>
</tr>
</table>
<table width='800' border='0' id='fields' name='fields'>
</table>
<div align='right'>
<input type='submit' name='create_btn' id='create_btn' value='Create' />
<input type='reset' name='reset_btn' id='reset_btn' value='Reset' />
</div>
</form>
</td>
<td></td>
</tr>
<tr height="30">
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br /></td>
<td width="25%"> </td>
</tr>
</table>

</body>
</html>
</body>
</html>

 

create.php

 

<?php
include("dbcon.php");

$field1 = htmlentities($_REQUEST["field1"]);
if (empty($field1)) {
echo "<script>alert('No value was entered for field1, please enter a value.');</script>";
}

$field2 = htmlentities($_REQUEST["field2"]);
if (empty($field2)) {
echo "<script>alert('No value was entered for field2, please enter a value.');</script>";
}

$field3 = htmlentities($_REQUEST["field3"]);
if (empty($field3)) {
echo "<script>alert('No value was entered for field3, please enter a value.');</script>";
}

$field4 = htmlentities($_REQUEST["field4"]);
if (empty($field4)) {
echo "<script>alert('No value was entered for field4, please enter a value.');</script>";
}

$field5 = htmlentities($_REQUEST["field5"]);
if (empty($credith)) {
echo "<script>alert('No value was entered for field5, please enter a value.');</script>";
}

$field6 = htmlentities($_REQUEST["field6"]);
if (empty($field6)) {
echo "<script>alert('No value was entered for field6, please enter a value.');</script>";
}

$info = mysql_query("INSERT INTO info (field1, field2, field3, field4, field5, field6)
VALUES ('".$field1."', '".$field2."', '".$field3."', '".$field4."', '".$field5."', '".$field6."')");

echo "<script>window.location='index.php'</script>";
}

//close connection
mysql_close($con);
?>

 

Now, the javascript opens up as many lines as the user chooses, but for some reason only the last line is inserted into the DB. Anyone know why this might be acting in such a manner?  ???

Link to comment
https://forums.phpfreaks.com/topic/103671-multiple-lines-in-sql-db/
Share on other sites

It may be the fact that you have all the fields named the same and it can't tell the differences.

 

You have to to set it up where the javascript tosses a row id in front of the field name like 1_field_1 1_field_2, 2_field_1, 2_field_2 etc... and then php to scan the fields and rows and submit them accordingly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.