2 Replies - 1284 Views - Last Post: 04 March 2013 - 07:16 AM Rate Topic: -----

#1 xuany   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 03-March 10

how to pass the variable into database after clicking submit button

Posted 04 March 2013 - 06:32 AM

Dear all, when i click submit for the registration form, it will pop up the membership number, how do i insert this membership number into the sql db.
<?php include "layout.php" ?>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/Javascript">
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('*****  Invalid:  *****\n'+errors);
  document.MM_returnValue = (errors == '');


<div class="container">
  <div class="content">
   <table width="100%" border="1">
      <td align="left" valign="middle"><table width="100%" border="0">
         <td width="25" align="left" valign="middle">&nbsp;</td>
          <td width="666" align="left" valign="middle"><strong><font color="#990000" size="3">Registration Status</font></strong></td>
          <td width="407" align="right"><span class="style7"><strong>User :</strong></span><font size="2"><font color="#000000" > <? print "$msg"; ?></font></font> </td>
          <!---  <font color="#000000" size="2"><? print "$msg2"; ?></font></span>-->
         <!-- <font color="#000000"><? print "$msg1"; ?>-->
<table width="86%" height="310" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr align="center"> 
    <td height="308" colspan="9" valign="top"> <div align="center"> 
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr align="center" valign="middle"> 
            <td width="13%" height="1"></td>
            <td width="10%"></td>
            <td width="9%"></td>
            <td width="9%"></td>
            <td width="8%"></td>
            <td width="8%"></td>
            <td width="10%"></td>
            <td width="11%"></td>
            <td width="10%"></td>
            <td width="12%"></td>
		$sql = "INSERT into biodata(id,name,nric,gender,dob,pob,nationality,prof_cat,employment,oadd,hadd,postcode,town,division,otel,mtel)";
	 $result=mysql_query($sql) or die(mysql_error()); 
			$result = mysql_query("select biodata.id, LEFT(biodata.nric,2),Right(utility.uti_yr,2) from biodata,utility");
				while ($row=mysql_fetch_array($result))
	echo "Form Successfully Registered";
	echo "</br>Membership Number = " .$dy."-".$uy."-".$id; 
	echo "<br /> <META HTTP-EQUIV = 'Refresh' Content = '4; URL =register_participant.php'>";	
      <div align="center"> </div>
        <div align="center"><strong> </strong></div>
    <td width="54" height="2"></td>
    <td width="54"></td>
    <td width="97"></td>
    <td width="4"></td>
    <td width="148"></td>
    <td width="148"></td>
    <td width="30"></td>
    <td width="303"></td>
    <td width="124"></td>
<!-- end .content -->

After i click submit button, it will pop up the membership number, the coding is as below, how do i insert this variable into the database?
echo "</br>Membership Number = " .$dy."-".$uy."-".$id; 

thank you .

Is This A Good Question/Topic? 0
  • +

Replies To: how to pass the variable into database after clicking submit button

#2 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: how to pass the variable into database after clicking submit button

Posted 04 March 2013 - 07:11 AM

Hey, first thing's first, learn to separate your code. It makes debugging harder and it throws off the entire structure of your application. Let's say you wanted to INSERT the data into your 'biodata' table from another script. That would mean you'd either have to duplicate the code from this script or call this entire script which isn't feasible at all with the HTML and Javascript in there.

Your code is a hacker's paradise. It's vulnerable to SQL injections so please look into Prepared Statements offered by both MySQLi and PDO. MySQLi is the improved version of the MySQL API so the learning curve is nothing really since you know MySQL.

You should be more specific when you say "INSERT into database". Did you write this code by the way? You're using code to INSERT other data into your 'biodata' table so I would assume you know who to INSERT data into other tables.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: how to pass the variable into database after clicking submit button

Posted 04 March 2013 - 07:16 AM

Welcome to PHP, Dreamweaver style.

Dreamweaver: Turning Designers Into Poor PHP Programmers Since 1997.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1