Starringstars Posted February 2, 2009 Report Share Posted February 2, 2009 Who can help me with a php code I wrote? It's just a simple form and I want to put the input into mysql database. The script is working in pieces but now I want the whole script to run. I'm a newby and the script has also dutch. Ore where can i post this? And why do I get an blank page when I ran the script on the server of my provider? :/ Thanx Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 2, 2009 Report Share Posted February 2, 2009 Post the script here, within [ code][/ code] tags, and I can take a look. Saving things to a database shouldn't be that difficult. If you are getting a blank page when you run the script on your provider, most likely there are errors in your current script that are preventing it from running. Again, I would need the PHP code to be sure. I suppose I should mention... I can't read dutch, but I'll give it my best shot, and hopefully you can provide a translation if there is anything I have a question about. Quote Link to comment Share on other sites More sharing options...
Starringstars Posted February 3, 2009 Author Report Share Posted February 3, 2009 (edited) OKay Benjamin I have also put some comments in english. The only thing I want for now is to insert formdata into database. First I made an page with the form: I comment out the mail function. I will do this with swift mailer. For now I want to printout the database tables which users put into the database successfully, to a webpage. Let me know if you also need the 1 html page with the form Here is the script vewerk.php which is called from the action on index.php: <?php // this are the variables for the users input of the form $Naam = $_POST['naam']; print $Naam; $Cat = $_POST['cat']; print $Cat; $Onderwerp = $_POST['onderwerp'].' '; print $Onderwerp; $Email = $_POST['email'].' '; print $Email.' '; $Vraag = $_POST['vraag'].' '; print $Vraag.' '; $Merk = $_POST['merk'].' '; print $Merk.' '; $All = $Naam.$Onderwerp.$Cat.$Vraag.$Merk; // mijn mail $Mail = "mymailadres"; //mail($Mail, $Cat, $All, "From: $Email"); // Controle of een formulier gepost is if($_SERVER['REQUEST_METHOD'] == 'POST') { // Arrays declareren voor opslag van fouten en data $aErrors = array(); $aData = array(); // Velden die in het formulier aanwezig moeten zijn // array of form $aFormulierVelden = array('$Naam', '$Email', '$Cat', '$Vraag'); // Alle formuliervelden doorlopen foreach($aFormulierVelden as $sVeld) { // Controleren of er een waarde voor het formulierveld bestaat if(isset($_POST[$sVeld])) { // Spaties aan begin en eind weghalen $sValue = trim($_POST[$sVeld]); // Controle of variabele gevuld is if($sValue == '') { // Foutmelding toevoegen $aErrors[] = 'Je bent vergeten om je '.$sVeld.' in te vullen'; } // Ingevulde waarden aan data array toevoegen $aData[$sVeld] = $sValue; } else { $aErrors[] = 'Het veld '.$sVeld.' is niet gepost!'; } } } // Controleren of er geen fouten opgetreden zijn if(empty($aErrors)) { // Formulier succes! // form succes echo ' Je hebt het formulier succesvol ingevuld '.$Naam.'! De volgende gegevens zijn bekend:'; echo ' Naam: '.$aData['naam'].' '; echo 'Categorie: '.$aData['cat'].''; // inserts users input into db require 'db_config.php'; $sql = "INSERT INTO gegevens(naam, cat) VALUES('" . mysql_real_escape_string($aData['naam']) . "', '" . mysql_real_escape_string($aData['cat']) . "')"; $result = mysql_query($sql); } if(!$result) { trigger_error('Het is niet gelukt de gegevens in de database te plaatsen!'); } else { echo 'Uw gegevens zijn succesvol toegevoegd!'; } ?> Edited February 3, 2009 by Starringstars Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 3, 2009 Report Share Posted February 3, 2009 Here are two links that explain the process better than I probably could. Basically, this is what you need to do: -- set up the database on your hosting environment. Set up a table to store the data, and figure out what columns you need in that table. -- in the end of your PHP script, after you send the email, you'll need to connect to the database: http://www.tizag.com/mysqlTutorial/mysqlconnection.php -- then using the different variables you have already collected from your form ($naam, $cat, $Onderwerp, etc.) format the data in whatever way you need to save it to the database. You'll probably want to run each variable through the PHP function mysql_real_escape_string() to prevent errors in your database (this has more information on this step: http://www.roughguidetophp.com/cleaning-up-user-data-in-mysql/) -- Using MySQL's INSERT, insert the data into the database http://www.tizag.com/mysqlTutorial/mysqlinsert.php Hopefully that will get you started. Quote Link to comment Share on other sites More sharing options...
Starringstars Posted February 4, 2009 Author Report Share Posted February 4, 2009 (edited) Thank you for the reply! I setup my one local SQLserver with xamp. Now the script is working and it puts the record in the database. I also have another script which easily shows my sql records. My problem is that the form validation is working but I want the respond from the validation on the same page. Now the respond is coming on page 2 because of the post action. How to fix this? So the form validation respond will be on the same page. I also implemented a micropayment system and I want to use it as validation before it sends out the form input to database. Maybe you can help with that? Thanx Edited February 6, 2009 by Starringstars Quote Link to comment Share on other sites More sharing options...
Starringstars Posted February 9, 2009 Author Report Share Posted February 9, 2009 OKay I fixed that validation problem:) My only problem now is with the micro payment script which I have. Can someone help with a small thing? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 9, 2009 Report Share Posted February 9, 2009 OKay I fixed that validation problem:) My only problem now is with the micro payment script which I have. Can someone help with a small thing? Can you specify what the problem is? Quote Link to comment Share on other sites More sharing options...
Starringstars Posted February 11, 2009 Author Report Share Posted February 11, 2009 Okay I've fixed that. Now how know how to give access to a secure page in php? Thanx 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.
Note: Your post will require moderator approval before it will be visible.