kakashii Posted April 30, 2007 Share Posted April 30, 2007 hey guys thanks in advance i have my form uploading its information to a sql server the database is being updated but all fields in the table are blank. <?php $db_host = "mysql.bur.st"; $db_user = "hidden"; $db_pwd = "hidden"; $db_name = "hidden"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <html> <head> <title>BCDA Questionaire</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <label>Name: <input type="text" name="name" id="name" /> </label> <p> <label>Email Address: <input type="text" name="email" id="email" /> </label> </p> <p> <label>How long have you been diving? <input type="text" name="dt" id="dt" /> </label> </p> <p> <label>When was your last dive? <input type="text" name="ld" id="ld" /> </label> </p> <p> <label>What is your highest level of certification? <input type="text" name="cert" id="cert" /> </label> </p> <p> Courses That Interest you:</p> <p> </p> <p> <label> <input type="checkbox" name="sn" id="sn" /> Snorkeling</label> <label> <input type="checkbox" name="pd" id="pd" /> Passport Diver</label> <label> <input type="checkbox" name="sr" id="sr" /> Scuba Rangers</label> <label> <input type="checkbox" name="ssu" id="ssu" /> Scuba Skills Update</label> </p> <p> <label> <input type="checkbox" name="ow" id="ow" /> Open Water</label> <label> <input type="checkbox" name="jow" id="jow" /> Junior Open Water</label> <label> <input type="checkbox" name="aa" id="aa" /> Advanced Adventurer</label> <label> <input type="checkbox" name="aow" id="aow" /> Advanced Open Water</label> </p> <p>Advanced Specialties:</p> <p> <label> <input type="checkbox" name="wr" id="wr" /> Wreck</label> <label> <input type="checkbox" name="dp" id="dp" /> Deep</label> <label> <input type="checkbox" name="nv" id="nv" /> Navigation</label> <label> <input type="checkbox" name="cp" id="cp" /> Computer</label> <label> <input type="checkbox" name="ean" id="ean" /> Nitrox</label> <label> <input type="checkbox" name="sr2" id="sr2" /> Search And Recovery</label> </p> <p> <label> <input type="checkbox" name="str" id="str" /> Stress and Rescue</label> <label> <input type="checkbox" name="uwp" id="uwp" /> Underwater Photography</label> <label> <input type="checkbox" name="ds" id="ds" /> Dry Suit</label> <label> <input type="checkbox" name="bd" id="bd" /> Boat Diving</label> <label> <input type="checkbox" name="fid" id="fid" /> Fish ID</label> </p> <p> <label> <input type="checkbox" name="ht" id="ht" /> Hunter</label> <label> <input type="checkbox" name="bs" id="bs" /> Buoyancy Skills</label> <label> <input type="checkbox" name="et" id="et" /> Equipment Techniques</label> <label> <input type="checkbox" name="nd" id="nd" /> Night Diving</label> <label> <input type="checkbox" name="dd" id="dd" /> Drift Diving</label> </p> <p> <label> <input type="checkbox" name="cd" id="cd" /> Cave Diving</label> </p> <p>Professional Specialties:</p> <p> <label> <input type="checkbox" name="dc" id="dc" /> Dive Control Specialist</label> <label> <input type="checkbox" name="ai" id="ai" /> Assistant Instuctor</label> <label> <input type="checkbox" name="in" id="in" /> Instructor</label> <label> <input type="checkbox" name="adi" id="adi" /> Advanced Instuctor</label> </p> <p> <label> <input type="checkbox" name="dci" id="dci" /> Dive Con Instructor</label> <label> <input type="checkbox" name="sri" id="sri" /> Scuba Ranger Instructor</label> <label> <input type="checkbox" name="ic" id="ic" /> Instructor Certifier</label> </p> <p>Technical Diving:</p> <p> <label> <input type="checkbox" name="ant" id="ant" /> Advanced Nitrox / Technical Foundations</label> </p> <p> <label> <input type="checkbox" name="dcp" id="dcp" /> Decompression Procedures</label> </p> <p> <label> <input type="checkbox" name="tm" id="tm" /> Normoxic Trimix</label> </p> <p> <label> <input type="checkbox" name="adp" id="adp" /> Advanced Decompression Procedures</label> </p> <p>Dive Activities that interest you:</p> <p>Weekend Dives</p> <p> <label>Morning <input type="checkbox" name="wdm" id="wdm" /> </label> </p> <p> <label>Afternoon <input type="checkbox" name="man" id="man" /> </label> </p> <p> <label>Full Day Dives <input type="checkbox" name="fdd" id="fdd" /> </label> </p> <p> <label>Double Tank Dives <input type="checkbox" name="dtd" id="dtd" /> </label> </p> <p> <label>Mid Week Dives <input type="checkbox" name="mwd" id="mwd" /> </label> </p> <p> <label>Morning Dives <input type="checkbox" name="md" id="md" /> </label> </p> <p> <label>Short Trips <input type="checkbox" name="st" id="st" /> </label> </p> <p> <label>Night Dives <input type="checkbox" name="nds" id="nds" /> </label> </p> <p> <label>Helicopter Dives <input type="checkbox" name="hdd" id="hdd" /> </label> </p> <p> </p> <p> <label>Where would you like to dive next and at what level</label> ? </p> <p> <input type="text" name="nwd" id="nwd" /> </p> <p> <label>Do you require a dive buddy? <input type="text" name="db" id="db" /> </label> </p> <p> <label>Do you own your own equipment? <input type="text" name="own" id="own" /> </label> </p> <p> <label>Do you have your equipment serviced? <input type="text" name="ser" id="ser" /> </label> <label>How often <input type="text" name="ho" id="ho" /> </label> </p> <p> <label>Do you have any equipment needs? <input type="text" name="en" id="en" /> </label> </p> <p> <label>Do you live locally <input type="text" name="loc" id="loc" /> </label> <label>Would you like to be part of a dive club? <input type="text" name="dcv" id="dcv" /> </label> </p> <p> <label>Comments <input type="text" name="com" id="com" /> </label> </p> <p> <label>SUBMIT <input type="submit" name="sub" id="sub" value="Submit" /> RESET <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> </p> </form> <?php //This is information about the diver $name= $_post['name']; $email= $_post['email']; $divet= $_post['dt']; $lastd= $_post['ld']; $hcert= $_post['cert']; //This is information about courses that interest the diver $snorkeling= $_post['sn']; $passport= $_post['pd']; $scubaran= $_post['sr']; $scubaski= $_post['ssu']; $openwater= $_post['ow']; $juniorow= $_post['jow']; $advadevn= $_post['aa']; $advow= $_post['aow']; //This is information about specialties $wreckd= $_post['wr']; $deepd= $_post['dp']; $navi= $_post['nv']; $comput= $_post['cp']; $nitrox= $_post['ean']; $seandrec= $_post['sr2']; $strares= $_post['str']; $uwphoto= $_post['uwp']; $drysuit= $_post['ds']; $boatd= $_post['bd']; $fishid= $_post['fid']; $hunter= $_post['ht']; $bouyski= $_post['bs']; $equitech= $_post['et']; $nightdiv= $_post['nd']; $driftdiv= $_post['dd']; $cavediv= $_post['cd']; //This information is about professional Specialties $divecon= $_post['dc']; $assinst= $_post['ai']; $instruc= $_post['in']; $advinst= $_post['adi']; $divecin= $_post['dci']; $scrains= $_post['sri']; $iscert= $_post['ic']; //This information is about Technical Diving $advnitf= $_post['ant']; $decopro= $_post['dcp']; $normtmx= $_post['tm']; $adecpro= $_post['adp']; //This information is interesting activities $mord= $_post['wdm']; $aftd= $_post['man']; $fuldd= $_post['fdd']; $doutd= $_post['dtd']; $mdwkd= $_post['mwd']; $mrd= $_post['md']; $short= $_post['st']; $nidiv= $_post['nds']; $helid= $_post['hdd']; //This information is extra $nextdv= $_post['nwd']; $rqbud= $_post['db']; $owneq= $_post['own']; $serveq= $_post['ser']; $freq= $_post['ho']; $eqneed= $_post['en']; $local= $_post['loc']; $dclub= $_post['dcv']; $comm= $_post['com']; ?> <?php mysql_query("INSERT INTO divers (name, email, dive, lastd, hcert, snorkeling, passport, scubaran, scubaski, openwater, juniorow, advadven, advow, wreckd, deepd, navi, comput, nitrox, seandrec, strares, uwphoto, drysuit, boatd, fishid, hunter, bouyski, equitech, driftdiv, cavediv, divecon, asinst, instruc, advinst, divecin, scrains, iscert, advnitf, decopro, normtmx, adecpro, mord, aftd, fuldd, doutd, mdwkd, mrd, short, nidiv, helid, dextdv, rqbud, owneq, serveq, freq, eqneed, local, dclub, comm) VALUES ('$name', '$email', '$divet', '$lastd', '$hcert', '$snorkeling', '$passport', '$scubaran', '$scubaski', '$openwater', '$juniorow', '$advadven', '$advow', '$wreckd', '$deepd', '$navi', '$comput', '$nitrox', '$seandrec', '$strares', '$uwphoto', '$drysuit', '$boatd', '$fishid', '$hunter', '$bouyski', '$equitech', '$driftdiv', '$cavediv', '$divecon', '$asinst', '$instruc', '$advinst', '$divecin', '$scrains', '$iscert', '$advnitf', '$decopro', '$normtmx', '$adecpro', '$mord', '$aftd', '$fuldd', '$doutd', '$mdwkd', '$mrd', '$short', '$nidiv', '$helid', '$dextdv', '$rqbud', '$owneq', '$serveq', '$freq', '$eqneed', '$local', '$dclub', '$comm')"); ?> <label></label> </body> </html> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 30, 2007 Share Posted April 30, 2007 first thing, I wouldn't place the SQL in the same file as form, because once someone presses the submit button, the page will post to its self, then do the database stuff. Now lets say someone trys to refresh the page, it will insert into the database again. So I recomend that you place the insert in its own file, then do a redirect back to this page, then the person can refresh all they want an nothing will change the database. Anyways, add this after your SQL: mysql_query("INSERT INTO divers (name, email...)VALUES('$name', '$email'...)")or die(mysql_error()); I would also reccomend placing these: `` around your column names Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted April 30, 2007 Share Posted April 30, 2007 hey guys thanks in advance i have my form uploading its information to a sql server the database is being updated but all fields in the table are blank. It looks like you're attempting to create a sticky form, but your logic is a bit messed up. The typical logic flow is: Process the form if it's been submitted Display it if not, or if there are errors. Your current logic is: Connect to database Display form Process form So, you should start off with a conditional that checks if the form has been submitted: <?php if(isset($_POST['submit'])){ //process form } ?> Then display the HTML after you've done everything, including sending info to the database. Secondly, you never set an action for your form. If you want to have everything in one script, you'll need something like: <form method="post" action="<?php echo $_SERVER[php_SELF]; ?>" > This tells the form to use the current script for processing. Hope this helps you figure it out. Quote Link to comment Share on other sites More sharing options...
kakashii Posted May 1, 2007 Author Share Posted May 1, 2007 in relation to your question The Little Guy could you(or someone else) please show me or tell me how i would go about re-writing the page so all your recomendations will work Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 Put the form on one page (ex: form.html). Then put all of the processing stuff in another (ex: process.php). Your form.html will have something like this: <form action="process.php" method="POST"> ...form code goes here </form> And your process.php will have the PHP code in there. Quote Link to comment Share on other sites More sharing options...
kakashii Posted May 1, 2007 Author Share Posted May 1, 2007 Alright iv taken all the recomendation and compiled them into these, but there is still no information showing in the database (it creates a new line but no information is carried from the form) is this because i havnt defined the correct datatype for the checkboxes? or is it something else. Process.php <?php $db_host = "mysql.bur.st"; $db_user = "mikie"; $db_pwd = "asee3nah"; $db_name = "mikie"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); //This is information about the diver $name= $_post['name']; $email= $_post['email']; $divet= $_post['dt']; $lastd= $_post['ld']; $hcert= $_post['cert']; //This is information about courses that interest the diver $snorkeling= $_post['sn']; $passport= $_post['pd']; $scubaran= $_post['sr']; $scubaski= $_post['ssu']; $openwater= $_post['ow']; $juniorow= $_post['jow']; $advadevn= $_post['aa']; $advow= $_post['aow']; //This is information about specialties $wreckd= $_post['wr']; $deepd= $_post['dp']; $navi= $_post['nv']; $comput= $_post['cp']; $nitrox= $_post['ean']; $seandrec= $_post['sr2']; $strares= $_post['str']; $uwphoto= $_post['uwp']; $drysuit= $_post['ds']; $boatd= $_post['bd']; $fishid= $_post['fid']; $hunter= $_post['ht']; $bouyski= $_post['bs']; $equitech= $_post['et']; $nightdiv= $_post['nd']; $driftdiv= $_post['dd']; $cavediv= $_post['cd']; //This information is about professional Specialties $divecon= $_post['dc']; $assinst= $_post['ai']; $instruc= $_post['in']; $advinst= $_post['adi']; $divecin= $_post['dci']; $scrains= $_post['sri']; $iscert= $_post['ic']; //This information is about Technical Diving $advnitf= $_post['ant']; $decopro= $_post['dcp']; $normtmx= $_post['tm']; $adecpro= $_post['adp']; //This information is interesting activities $mord= $_post['wdm']; $aftd= $_post['man']; $fuldd= $_post['fdd']; $doutd= $_post['dtd']; $mdwkd= $_post['mwd']; $mrd= $_post['md']; $short= $_post['st']; $nidiv= $_post['nds']; $helid= $_post['hdd']; //This information is extra $nextdv= $_post['nwd']; $rqbud= $_post['db']; $owneq= $_post['own']; $serveq= $_post['ser']; $freq= $_post['ho']; $eqneed= $_post['en']; $local= $_post['loc']; $dclub= $_post['dcv']; $comm= $_post['com']; ?> <?php mysql_query("INSERT INTO divers (name, email, dive, lastd, hcert, snorkeling, passport, scubaran, scubaski, openwater, juniorow, advadven, advow, wreckd, deepd, navi, comput, nitrox, seandrec, strares, uwphoto, drysuit, boatd, fishid, hunter, bouyski, equitech, driftdiv, cavediv, divecon, asinst, instruc, advinst, divecin, scrains, iscert, advnitf, decopro, normtmx, adecpro, mord, aftd, fuldd, doutd, mdwkd, mrd, short, nidiv, helid, dextdv, rqbud, owneq, serveq, freq, eqneed, local, dclub, comm) VALUES ('$name', '$email', '$divet', '$lastd', '$hcert', '$snorkeling', '$passport', '$scubaran', '$scubaski', '$openwater', '$juniorow', '$advadven', '$advow', '$wreckd', '$deepd', '$navi', '$comput', '$nitrox', '$seandrec', '$strares', '$uwphoto', '$drysuit', '$boatd', '$fishid', '$hunter', '$bouyski', '$equitech', '$driftdiv', '$cavediv', '$divecon', '$asinst', '$instruc', '$advinst', '$divecin', '$scrains', '$iscert', '$advnitf', '$decopro', '$normtmx', '$adecpro', '$mord', '$aftd', '$fuldd', '$doutd', '$mdwkd', '$mrd', '$short', '$nidiv', '$helid', '$dextdv', '$rqbud', '$owneq', '$serveq', '$freq', '$eqneed', '$local', '$dclub', '$comm')")or die(mysql_error()); ?> And The form <html> <head> <title>BCDA Questionaire</title> </head> <body> <form id="form1" name="form1" method="post" action="process.php"> <label>Name: <input type="text" name="name" id="name" /> </label> <p> <label>Email Address: <input type="text" name="email" id="email" /> </label> </p> <p> <label>How long have you been diving? <input type="text" name="dt" id="dt" /> </label> </p> <p> <label>When was your last dive? <input type="text" name="ld" id="ld" /> </label> </p> <p> <label>What is your highest level of certification? <input type="text" name="cert" id="cert" /> </label> </p> <p> Courses That Interest you:</p> <p> </p> <p> <label> <input type="checkbox" name="sn" id="sn" /> Snorkeling</label> <label> <input type="checkbox" name="pd" id="pd" /> Passport Diver</label> <label> <input type="checkbox" name="sr" id="sr" /> Scuba Rangers</label> <label> <input type="checkbox" name="ssu" id="ssu" /> Scuba Skills Update</label> </p> <p> <label> <input type="checkbox" name="ow" id="ow" /> Open Water</label> <label> <input type="checkbox" name="jow" id="jow" /> Junior Open Water</label> <label> <input type="checkbox" name="aa" id="aa" /> Advanced Adventurer</label> <label> <input type="checkbox" name="aow" id="aow" /> Advanced Open Water</label> </p> <p>Advanced Specialties:</p> <p> <label> <input type="checkbox" name="wr" id="wr" /> Wreck</label> <label> <input type="checkbox" name="dp" id="dp" /> Deep</label> <label> <input type="checkbox" name="nv" id="nv" /> Navigation</label> <label> <input type="checkbox" name="cp" id="cp" /> Computer</label> <label> <input type="checkbox" name="ean" id="ean" /> Nitrox</label> <label> <input type="checkbox" name="sr2" id="sr2" /> Search And Recovery</label> </p> <p> <label> <input type="checkbox" name="str" id="str" /> Stress and Rescue</label> <label> <input type="checkbox" name="uwp" id="uwp" /> Underwater Photography</label> <label> <input type="checkbox" name="ds" id="ds" /> Dry Suit</label> <label> <input type="checkbox" name="bd" id="bd" /> Boat Diving</label> <label> <input type="checkbox" name="fid" id="fid" /> Fish ID</label> </p> <p> <label> <input type="checkbox" name="ht" id="ht" /> Hunter</label> <label> <input type="checkbox" name="bs" id="bs" /> Buoyancy Skills</label> <label> <input type="checkbox" name="et" id="et" /> Equipment Techniques</label> <label> <input type="checkbox" name="nd" id="nd" /> Night Diving</label> <label> <input type="checkbox" name="dd" id="dd" /> Drift Diving</label> </p> <p> <label> <input type="checkbox" name="cd" id="cd" /> Cave Diving</label> </p> <p>Professional Specialties:</p> <p> <label> <input type="checkbox" name="dc" id="dc" /> Dive Control Specialist</label> <label> <input type="checkbox" name="ai" id="ai" /> Assistant Instuctor</label> <label> <input type="checkbox" name="in" id="in" /> Instructor</label> <label> <input type="checkbox" name="adi" id="adi" /> Advanced Instuctor</label> </p> <p> <label> <input type="checkbox" name="dci" id="dci" /> Dive Con Instructor</label> <label> <input type="checkbox" name="sri" id="sri" /> Scuba Ranger Instructor</label> <label> <input type="checkbox" name="ic" id="ic" /> Instructor Certifier</label> </p> <p>Technical Diving:</p> <p> <label> <input type="checkbox" name="ant" id="ant" /> Advanced Nitrox / Technical Foundations</label> </p> <p> <label> <input type="checkbox" name="dcp" id="dcp" /> Decompression Procedures</label> </p> <p> <label> <input type="checkbox" name="tm" id="tm" /> Normoxic Trimix</label> </p> <p> <label> <input type="checkbox" name="adp" id="adp" /> Advanced Decompression Procedures</label> </p> <p>Dive Activities that interest you:</p> <p>Weekend Dives</p> <p> <label>Morning <input type="checkbox" name="wdm" id="wdm" /> </label> </p> <p> <label>Afternoon <input type="checkbox" name="man" id="man" /> </label> </p> <p> <label>Full Day Dives <input type="checkbox" name="fdd" id="fdd" /> </label> </p> <p> <label>Double Tank Dives <input type="checkbox" name="dtd" id="dtd" /> </label> </p> <p> <label>Mid Week Dives <input type="checkbox" name="mwd" id="mwd" /> </label> </p> <p> <label>Morning Dives <input type="checkbox" name="md" id="md" /> </label> </p> <p> <label>Short Trips <input type="checkbox" name="st" id="st" /> </label> </p> <p> <label>Night Dives <input type="checkbox" name="nds" id="nds" /> </label> </p> <p> <label>Helicopter Dives <input type="checkbox" name="hdd" id="hdd" /> </label> </p> <p> </p> <p> <label>Where would you like to dive next and at what level</label> ? </p> <p> <input type="text" name="nwd" id="nwd" /> </p> <p> <label>Do you require a dive buddy? <input type="text" name="db" id="db" /> </label> </p> <p> <label>Do you own your own equipment? <input type="text" name="own" id="own" /> </label> </p> <p> <label>Do you have your equipment serviced? <input type="text" name="ser" id="ser" /> </label> <label>How often <input type="text" name="ho" id="ho" /> </label> </p> <p> <label>Do you have any equipment needs? <input type="text" name="en" id="en" /> </label> </p> <p> <label>Do you live locally <input type="text" name="loc" id="loc" /> </label> <label>Would you like to be part of a dive club? <input type="text" name="dcv" id="dcv" /> </label> </p> <p> <label>Comments <input type="text" name="com" id="com" /> </label> </p> <p> <label> <input type="submit" name="sub" id="sub" value="Submit" /> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> </p> </form> <label></label> </body> </html> You guys are great this is really helping Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 The only thing I can suggest in this very late hour is to put backticks around the table name when you're inserting the data. mysql_query("INSERT INTO `divers` (name, email, dive, lastd, hcert, snorkeling, passport, scubaran, scubaski, openwater, juniorow, advadven, advow, wreckd, deepd, navi, comput, nitrox, seandrec, strares, uwphoto, drysuit, boatd, fishid, hunter, bouyski, equitech, driftdiv, cavediv, divecon, asinst, instruc, advinst, divecin, scrains, iscert, advnitf, decopro, normtmx, adecpro, mord, aftd, fuldd, doutd, mdwkd, mrd, short, nidiv, helid, dextdv, rqbud, owneq, serveq, freq, eqneed, local, dclub, comm) VALUES ('$name', '$email', '$divet', '$lastd', '$hcert', '$snorkeling', '$passport', '$scubaran', '$scubaski', '$openwater', '$juniorow', '$advadven', '$advow', '$wreckd', '$deepd', '$navi', '$comput', '$nitrox', '$seandrec', '$strares', '$uwphoto', '$drysuit', '$boatd', '$fishid', '$hunter', '$bouyski', '$equitech', '$driftdiv', '$cavediv', '$divecon', '$asinst', '$instruc', '$advinst', '$divecin', '$scrains', '$iscert', '$advnitf', '$decopro', '$normtmx', '$adecpro', '$mord', '$aftd', '$fuldd', '$doutd', '$mdwkd', '$mrd', '$short', '$nidiv', '$helid', '$dextdv', '$rqbud', '$owneq', '$serveq', '$freq', '$eqneed', '$local', '$dclub', '$comm')")or die(mysql_error()); Also, you don't have to end "?>" right before the query. So, after the variables list, it goes straight into the mysql_query. Hope that helps. Quote Link to comment Share on other sites More sharing options...
kakashii Posted May 1, 2007 Author Share Posted May 1, 2007 Worked it out thanks guys $_post is not the same as $_POST Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.