INSERTING VALUES FROM JAVASCRIPT TO DATABASE USING PHP
Posted: Mon Mar 09, 2009 4:07 am
Can you please help me with my codes? The javascript part has no problem, but still,
this code cannot insert any values to database...
Please, please, please try it and help me. I will truly appreciate your help from the bottom of my heart.
p.s. I'm using phpmyadmin for database
this code cannot insert any values to database...
Please, please, please try it and help me. I will truly appreciate your help from the bottom of my heart.
p.s. I'm using phpmyadmin for database
Code: Select all
<html>
<head>
<script type="text/javascript">
function createForm(number) {
data = "";
inter = "'";
if (number < 51 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 50) spaces=" ";
else spaces=" ";
data = data + "<input type='text' id='" + inter + i + inter + "' name='tester[]' value='<?php echo"$test";?>'><select id='" + inter + i + inter + "' name='tester2[]'><option>'<?php echo"$test2";?>'</option><option value='" + inter + i + inter + "' >Positive</option><option value='" + inter + i + inter + "'>Negative</option> </select> <br>";
}
document.getElementById('cust').innerHTML = data;
}
else
{ alert('Maximum of 50 only!');}}
</script>
</head>
Code: Select all
<body>
[color=#000040]<!--The form; a textbox and a dropdown-->[/color]
<form name="counter">
<input type="text" name="number" size="5" />
<input name="button" type="button" onclick="createForm(document.counter.number.value);" value="Add item(s)" /><br>
<span id=cust style="position:relative;"></span>
<input type="submit" name="sub"/>
</form>
Code: Select all
<?php
[color=#000040] //script part[/color]
include("connect.php");
if(isset($_POST["sub"])){
$test=$_POST['tester[]']; $test2=$_POST['tester2[]'];
mysql_query("insert into `testing` (`tester`,`tester2`) values('$test','$test2')");}
?>
</body>
</html>
//sql part
CREATE DATABASE `testing` ;
CREATE TABLE `testing`.`tester` (
`test` varchar( 12 ) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET = latin1;
CREATE TABLE `testing`.`tester2` (
`test2` varchar( 1 ) NOT NULL
);