Page 1 of 1

help needed

Posted: Wed Dec 31, 2003 1:15 am
by dakkonz
I want to do a form which makes the user click "i agree" before the submit button can be clicked... I got this code from the net and tried but there seems to be something wrong... It does not goes to my If($_POST['submit'])... Please help to see what is wrong with it... Thanks

This is the code :

Code: Select all

<?php
  	 if (isset($_POST['submit']))
       {
	   require_once ('../mysql_connect.php'); // Connect to the database.

	  $query = "UPDATE song SET status='Being Published', datecontract='$today' WHERE refnum={$row['refnum']}";
      $result = mysql_query ($query);
	  if($result) {
	  header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "index.php");
	  exit();
       } 
	   else {
	   header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "admin.html");
	    }
	mysql_close();
	}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="agreeform" >

/* text */
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br>
<input type="submit" name="submit" value="Submit!" disabled>
</form>

<script>
//change two names below to your form's names
document.forms.agreeform.agreecheck.checked=false
</script>

<script>

//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}

</script>
[Edit: Added PHP tags --JAM]

Posted: Wed Dec 31, 2003 8:25 am
by Saethyr

Code: Select all

<?php
require_once ('../mysql_connect.php'); // Connect to the database. 
?>
Do you have this file? with require_once if you do not have it, it will halt the script. What exactly is happening when you submit the form?


Saethyr

Posted: Thu Jan 01, 2004 12:00 am
by dakkonz
yah i have the file.... once submitted it juz refresh the page with nothing done... and my database variables all gone

Posted: Thu Jan 01, 2004 12:46 am
by JAM
You have error levels to low, or you would have spotted the error:

Code: Select all

$query = "UPDATE song SET status='Being Published', datecontract='$today' WHERE refnum={$row['refnum']}";
You need to use $_POST['today'] etc etc when using data passed on from a form.

Posted: Sat Jan 03, 2004 6:29 am
by dakkonz
thanks man settled already