Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 11-20-2010, 10:29 PM repeat insert form
Average Talker

Posts: 17
Name: charlie
Trades: 0
I have this program that inserts data into a database and would like to be able to repeat the form for further data inserts upon submission but don't know how. Below is code for the form & the testinsert.php:
HTML Code:
<html>
<head>
<style type="text/css">
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function getResults() {
   var search_val = $("#apt").val();
   $.post("prerentget.php", { search_term: search_val }, function(data) {
      if (data.length > 0) {
         $("#name")[0].value = data;
         }
      })
   }
</script>
<script type="text/javascript">
window.google_analytics_uacct = "UA-256751-2";
</script>
</head>
<body onload="document.form.apt.focus()">
<form name="form" action="testinsert.php" method="post">
<!--code for the form-->
<INPUT type="submit" value="submit data" />
</p>
</form></body></html>
PHP Code:
<?php
$apt
=$_POST['apt'];
$name=$_POST['name'];
$datereceived=$_POST['datereceived'];
$time=$_POST['time'];
$symptom=$_POST['symptom'];
$action=$_POST['action'];
$compmo=$_POST['compmo'];
$compday=$_POST['compday'];
$compyear=$_POST['compyear'];
$ordno=$_POST['ordno'];
$stat mysql_connect("localhost","root","") or die('Unable to connect to database: ' mysql_error());
$stat mysql_select_db("maintdb") or die('Unable to select database: ' mysql_error());
$query "INSERT INTO maintdata 
(apt,name,datereceived,time,symptom,action,compmo,compday,compyear,ordno) 
VALUES('
$apt','$name','$datereceived','$time','$symptom','$action','$compmo','$compday','$compyear','$or
dno')"
;
$stat mysql_query($query) or die('Query failed: ' mysql_error());
mysql_close();
?>
ckdoublenecks is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-22-2010, 04:21 AM Re: repeat insert form
Banned

Posts: 408
Name: mushget
Trades: 0
Optionally you could add at the end of your php file:

PHP Code:header("Location: file_that_holds_the_form.[COLOR=blue! important][COLOR=blue! important]html"[/COLOR]);
die();
[/COLOR]

This would work because your phpfile is not generating any output to the browse
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
Old 11-22-2010, 11:53 AM Re: repeat insert form
Average Talker

Posts: 17
Name: charlie
Trades: 0
I used the below but the echo doesn't work ?<?php
$apt=$_POST['apt'];
$name=$_POST['name'];
$datereceived=$_POST['datereceived'];
$time=$_POST['time'];
$symptom=$_POST['symptom'];
$action=$_POST['action'];
$compmo=$_POST['compmo'];
$compday=$_POST['compday'];
$compyear=$_POST['compyear'];
$ordno=$_POST['ordno'];
$stat = mysql_connect("localhost","root","") or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db("maintdb") or die('Unable to select database: ' . mysql_error());
$query = "INSERT INTO maintdata
(apt,name,datereceived,time,symptom,action,compmo, compday,compyear,ordno)
VALUES('$apt','$name','$datereceived','$time','$sy mptom','$action','$compmo','$compday','$compyear', '$or
dno')";
// ****************************************
echo "apt $apt data inserted<br /><br />";
// ***************************************
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close();
?>
<html>
<script type="text/javascript">
location.href = "http://localhost/files/form.html";
</script>
</html>
<?php?>
ckdoublenecks is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to repeat insert form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37204 seconds with 12 queries