-
Posts
8 -
Joined
-
Last visited
Never
Posts posted by AllenHobson
-
-
Hi Everyone
I found some code to decrease the writing of $_POST variables especially on big forms, but I cannot seem to get it to work:
I am trying to get the $_POST variables from this:
<?php $callsign = $_POST['mf_callsign']; $surname = $_POST['mf_surname']; $firstnames = $_POST['mf_firstnames']; $knownas = $_POST['mf_knownas']; $rsaid = $_POST['mf_rsaid']; $birthdate = $_POST['mf_birthdate']; //more code [code] to this (see //Create $_POST Variables section) [code] <?php //Initailise Database first mysql_connect ("localhost", "***", "***") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("***"); ========================= //Create $_POST Variables foreach($_POST as $inputKey=>$inputValue): //find all form fields starting with 'mf_' if((strstr($inputKey,'mf_') === true)): $inputKey = mysql_real_escape_string($inputValue); endif; endforeach; ========================= //Then do the Insert into the Table $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$mf_callsign', '$mf_surname', '$mf_firstnames', '$mf_knownas', '$mf_rsaid', '$mf_birthdate')"; mysql_query($query) or die ('Error Inserting Data into Database'); //If Insert Successful, Goto next Form header("Location: contactdetails.html"); die; ?>
The //Create $_POST Variables section is not correct as it is not setting the variables correctly.
If I go back to the old way and use that ($callsign = $_POST['mf_callsign'] it inserts no problem.
What Am I doing wrong?
Regards
Allen
-
My answer remains. Use sessions.
Hi
thanks for the advice. Will go look see what I can find in Sessions.
-
Hi Everyone,
I thought I better attach the code for better understanding....
Thanks in Advance...
First Form
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Personal Details</title></head> <body> <form method="post" action="personaldetails_add.php"><font face="Arial"> Call Sign:<br> <input name="callsign" size="5" type="text" AUTOCOMPLETE=OFF><br> Surame:<br> <input name="surname" size="30" type="text" AUTOCOMPLETE=OFF><br> First Name:<br> <input name="firstnames" size="30" type="text" AUTOCOMPLETE=OFF><br> Known as:<br> <input name="knownas" size="30" type="text" AUTOCOMPLETE=OFF><br> RSA ID No.:<br> <input name="rsaid" size="13" type="text" AUTOCOMPLETE=OFF><br> Birth Date:<br> <input name="birthdate" size="12" type="text" AUTOCOMPLETE=OFF><br> </font><br> <input name="Next" value="Next" type="submit"> </form> </body> </html>
First php processor
<?php $callsign = $_POST['callsign']; $surname = $_POST['surname']; $firstnames = $_POST['firstnames']; $knownas = $_POST['knownas']; $rsaid = $_POST['rsaid']; $birthdate = $_POST['birthdate']; mysql_connect ("localhost", "jredpixm_testuse", "PHPDevelopment") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("jredpixm_test"); $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$callsign', '$surname', '$firstnames', '$knownas', '$rsaid', '$birthdate')"; mysql_query($query) or die ('Error Inserting Data into Database'); header("Location: contactdetails.html"); die; ?>
Second Form
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Contact Details</title> </head> <body> <form method="post" action="contactdetails_add.php"><font face="Arial"> Call Sign:<br> <input name="callsign" size="5" type="text" AUTOCOMPLETE=OFF><br> Company:<br> <input name="company" size="30" type="text" AUTOCOMPLETE=OFF><br> Email:<br> <input name="email" size="50" type="text" AUTOCOMPLETE=OFF><br> Job Title:<br> <input name="jobtitle" size="50" type="text" AUTOCOMPLETE=OFF><br> Business Phone:<br> <input name="bphone" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Phone:<br> <input name="hphone" size="50" type="text" AUTOCOMPLETE=OFF><br> Mobile Phone:<br> <input name="mphone" size="50" type="text" AUTOCOMPLETE=OFF><br> Facsimile Phone:<br> <input name="fphone" size="50" type="text" AUTOCOMPLETE=OFF><br> <br> Home Address:<br> <input name="haddress" size="50" type="text" AUTOCOMPLETE=OFF><br> Home City:<br> <input name="hcity" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Code:<br> <input name="hcode" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Province:<br> <input name="hprovince" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Country:<br> <input name="hcountry" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Co Ordinates Southings:<br> <input name="hsouthings" size="50" type="text" AUTOCOMPLETE=OFF><br> Home Co Ordinates Eastings:<br> <input name="heastings" size="50" type="text" AUTOCOMPLETE=OFF><br> <br> Work Address:<br> <input name="waddress" size="50" type="text" AUTOCOMPLETE=OFF><br> Work City:<br> <input name="wcity" size="50" type="text" AUTOCOMPLETE=OFF><br> Work Code:<br> <input name="wcode" size="50" type="text" AUTOCOMPLETE=OFF><br> Work Province:<br> <input name="wprovince" size="50" type="text" AUTOCOMPLETE=OFF><br> Work Country:<br> <input name="wcountry" size="50" type="text" AUTOCOMPLETE=OFF><br> <br> </font><br> <input name="Next" value="Next" type="submit"></form> </body> </html>
Second Form php processor
<?php> $callsign = $_POST['callsign']; $company = $_POST['company']; $email = $_POST['email']; $jobtitle = $_POST['jobtitle']; $bphone = $_POST['bphone']; $hphone = $_POST['hphone']; $mphone = $_POST['mphone']; $fphone = $_POST['fphone']; $haddress = $_POST['haddress']; $hcity = $_POST['hcity']; $hcode = $_POST['hcode']; $hprovince = $_POST['hprovinc']; $hcountry = $_POST['hcountry']; $hsouthings = $_POST['hsouthings']; $heastings = $_POST['heastings']; $waddress = $_POST['waddress']; $wcity = $_POST['wcity']; $wcode = $_POST['wcode']; $wprovince = $_POST['wprovince']; $wcountry = $_POST['wcountry']; mysql_connect ("localhost", "jredpixm_testuse", "PHPDevelopment") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("jredpixm_test"); $query="INSERT INTO contactdetails (callsign, company, email, jobtitle, bphone, hphone, mphone, fphone, haddress, hcity, hcode, hprovince, hcountry, hsouthings, heastings, waddress, wcity, wcode, wprovince, wcountry) Values ('$callsign', '$callsign', '$company', '$email', '$jobtitle', '$bphone', '$hphone', '$mphone', '$fphone', '$haddress', '$hcity', '$hcode', '$hprovince', '$hcountry', '$hsouthings', '$heastings', '$waddress', '$wcity', '$wcode', '$wprovince', '$wcountry')"; mysql_query($query) or die ('Error Inserting Data into Database'); header("Location: contactdetails.html"); die; ?>
-
Hi Everyone,
Please can you guide me to solving my issue:
I have Form1 with fields one being the PK in mySQL (called callsign)
Once I submit the data it enters into the DB no issues.
I want to be able to take Form1.callsign once submitted, redirect and insert it into Form2.callsign
Is this possible? I got the Redirect to work no problem after the data is inserted.
I have been looking on Web and here and cant seem to find the answer to populate form2 from form1 field.
Can I use a Variable somehow?
I know there is an issue with submitting data to a 3rd party for security reasons etc, but I want when entering records on my own domain to autopopulate the next form with this callsign (which is the primary key) This way I get to link all 10 tables together using this key making the entire full record for the member.
Any Assistance would be greatly appreciated.
Thanks
Allen
-
That page should be a PHP document not an HTML document.
I then get
Parse error: syntax error, unexpected '<' in /home/jredpixm/public_html/personaldetails.php on line 2
Which is:
<?php> <html> <head> <title>Personal Details</title> ...
-
Thanks for that
I get some test on the page echoing... Please guide me to my mistake
you can view the file at
http://www.redpixel.co.za/personaldetails.html
Here is my latest code see bottom where you suggest the "if (isset($_POST['submit'])){"
<?php> <html> <head> <title>Personal Details</title> </head> <body> <form method="post" action="contactdetails.html"><font face="Arial"> Call Sign:<br> <input name="callsign" size="5" type="text"><br> Surame:<br> <input name="surname" size="30" type="text"><br> First Name:<br> <input name="firstnames" size="30" type="text"><br> Known as:<br> <input name="knownas" size="30" type="text"><br> RSA ID No.:<br> <input name="rsaid" size="13" type="text"><br> Birth Date:<br> <input name="birthdate" size="12" type="text"><br> </font><br> </body> </html> //php to insert data into table <input name="Insert" value="Next" type="submit"></form> if (isset($_POST['submit'])){ $callsign = $_POST['callsign']; $surname = $_POST['surname']; $firstnames = $_POST['firstnames']; $knownas = $_POST['knownas']; $rsaid = $_POST['rsaid']; $birthdate = $_POST['birthdate']; mysql_connect ("localhost", "jredpixm_testuse", "PHPDevelopment") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("jredpixm_test"); $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$callsign', '$surname', '$firstnames', '$knownas', '$rsaid', '$birthdate')"; mysql_query($query) or die ('Error updating Database'); echo "<p>Thanks, your information has been added to the database.</p>"; } ?>
-
Hello Everyone,
I have put my hand up to rewrite the Contact and skills Website for a volenteer Search and Rescue group I am with.
I have Database Experience although with MSSQL and Oracle not really mySQL although I am really enjoying mySQL.
Web Development Experience is NULL.
So I might / will be asking lots of "stupid" questions and researching information on this forum to better by skills in this department.
Thanks in Advance for the assistance.
Regards
Allen
-
Hello Everyone
I am new to php and indeed Web Development.
After testing and Playing a bit, I can get the following code to work as two files, the form calling the *.php file to insert into the database, however, I am trying to create one html/php file that displays the form and then executes the php code to insert into the database once user clickes the button.
Please can you assist me with the code? I have something horribly wrong and I cannot find it.
<?php> <html> <head> <title>Personal Details</title> </head> <body> <form method="post" action="contactdetails.html"><font face="Arial"> Call Sign:<br> <input name="callsign" size="5" type="text"><br> Surame:<br> <input name="surname" size="30" type="text"><br> First Name:<br> <input name="firstnames" size="30" type="text"><br> Known as:<br> <input name="knownas" size="30" type="text"><br> RSA ID No.:<br> <input name="rsaid" size="13" type="text"><br> Birth Date:<br> <input name="birthdate" size="12" type="text"><br> <input name="Insert" value="Next" type="submit"></form> </font><br> </body> </html> //php to insert data into table $callsign = $_POST['callsign']; $surname = $_POST['surname']; $firstnames = $_POST['firstnames']; $knownas = $_POST['knownas']; $rsaid = $_POST['rsaid']; $birthdate = $_POST['birthdate']; mysql_connect ("localhost", "jredpixm_testuse", "PHPDevelopment") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("jredpixm_test"); $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$callsign', '$surname', '$firstnames', '$knownas', '$rsaid', '$birthdate')"; mysql_query($query) or die ('Error updating Database'); echo "<p>Thanks, your information has been added to the database.</p>"; ?>
Regards
Allen
Dynamic Creating $_POST
in PHP Coding Help
Posted
Thanks People,
I implemented both Suggested changes and it works a Treat...
You guys Rock...
thanks very much