emarket Posted January 24, 2010 Share Posted January 24, 2010 Hi, I'm trying to extract the data that is entered into an aweber form (that is placed on my website) and post it into my personal database. I'm using the following code: <? $name =$_POST["name"]; $email =$_POST["email"]; mysql_connect("localhost", "test", "test123") or die ('Error: no db connection' . mysql_error()); mysql_select_db("test"); $query="INSERT INTO test ( name, email)VALUES ('NULL', '$name', '$email')"; mysql_query($query) or die ('error updating database'); mysql_close(); // close connection ?> aweber sample form code: <form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl" > <div style="display: none;"> <input type="hidden" name="meta_web_form_id" value="825978997" /> <input type="hidden" name="meta_split_id" value="" /> <input type="hidden" name="listname" value="xxx" /> <input type="hidden" name="redirect" value="http://wesite.com" id="redirect_5662dac80e4d40622hgh72bb48d229fd" /> <input type="hidden" name="meta_redirect_onlist" value="http://website.com/thankyou.php" /> <input type="hidden" name="meta_adtracking" value="My_Web_Form" /> <input type="hidden" name="meta_message" value="1" /> <input type="hidden" name="meta_required" value="name,email" /> <input type="hidden" name="meta_forward_vars" value="" /> <input type="hidden" name="meta_tooltip" value="" /> </div> <div id="af-form-825946900" class="af-form"><div id="af-header-825946900" class="af-header"><div class="bodyText"><p> </p></div></div> <div id="af-body-825946900" class="af-body af-standards"> <div class="af-element"> <label class="previewLabel" for="awf_field-2166497">Name: </label> <div class="af-textWrap"> <input id="awf_field-2166497" type="text" name="name" class="text" value="" /> </div> <div class="af-clear"></div></div> <div class="af-element"> <label class="previewLabel" for="awf_field-2166498">Email: </label> <div class="af-textWrap"><input class="text" id="awf_field-2166498" type="text" name="email" value='' /> </div><div class="af-clear"></div> </div> <div class="af-element buttonContainer"> <input name="submit" id="af-submit-image-825946900" type="image" class="image" style="background: none;" border="0" src="http://www.aweber.com/images/forms/coffee-shop/coffee-break/button.png"/> <div class="af-clear"></div> </div> <div class="af-element privacyPolicy" style="text-align: center"><p><a href="http://www.aweber.com/permission.htm" target="_blank">We respect your email privacy</a></p> <div class="af-clear"></div> </div> </div> <div id="af-footer-825946900" class="af-footer"><div class="bodyText"><p> </p></div></div> </div> <img src="http://forms.aweber.com/form/displays.htm?id=HEysnCxsnAwM" border="0" /> </form> I tried placing the code into the form code, outside the code form, but it didn't work. It doesen't give any errors, but it's not posting data into database. What is wrong or am I not using the proper php function? Thanks Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/ Share on other sites More sharing options...
Fergal Andrews Posted January 24, 2010 Share Posted January 24, 2010 Hi, I've put an updated version of your code below. The first thing you might want to check is what $_POST data you are receiving. You can do this by uncommenting var_dump($_POST); die(); This will print the contents of the $_POST array to screen and stop the rest of the code running. If you can see $_POST['name'] and $_POST['email'] then you can comment that again and continue. Inserting data from a form directly into a database is a very risky thing to do. This allows all sorts of rubbish into your database and can facilitate sql injection attacks. There are a number of ways to sanatize data but in this case, at the very least, use mysql_real_escape_string(). I've also altered your query. Since I don't know the structure of your database table, I'm just sending values to the name and email fields. In your insert statement, you seem to be sending 3 values to 2 form fields, the first of which is NULL being sent to the name field. Try this out and see if it works for you. <?php // debugging. Uncomment to see what $_POST data is being received // var_dump($_POST); die(); $name = $_POST["name"]; $email =$_POST["email"]; mysql_connect("localhost", "test", "test123") or die ('Error: no db connection' . mysql_error()); mysql_select_db("test"); // sanatize data $name = mysql_real_escape_string($name); $email = mysql_real_escape_string($email); $query="INSERT INTO test name='$name', email='$email'"; mysql_query($query) or die ('error updating database'); mysql_close(); // close connection ?> Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/#findComment-1000763 Share on other sites More sharing options...
emarket Posted January 24, 2010 Author Share Posted January 24, 2010 Hi, Thanks for your answere. I'm getting this on page "array(0) { }" after when runnig the code. <?php // debugging. Uncomment to see what $_POST data is being received var_dump($_POST); die(); $name = $_POST["name"]; $email =$_POST["email"]; mysql_connect("localhost", "test", "test123") or die ('Error: no db connection' . mysql_error()); mysql_select_db("test"); // sanatize data $name = mysql_real_escape_string($name); $email = mysql_real_escape_string($email); $query="INSERT INTO test name='$name', email='$email'"; mysql_query($query) or die (mysql_error()); mysql_close(); // close connection ?> Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/#findComment-1000876 Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 So you are getting no POST data on your page. The form has an action attribute that sends the POST data to aweber.com, so how are you expecting to see the POST data in your script. Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/#findComment-1000879 Share on other sites More sharing options...
emarket Posted January 25, 2010 Author Share Posted January 25, 2010 Yes, no post on page when debugging. I know that the form action is to POST data to aweber, but isn't it possible to capture that data in the same time? Or should I have to make somehow a double action in the form? Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/#findComment-1001306 Share on other sites More sharing options...
emarket Posted February 2, 2010 Author Share Posted February 2, 2010 I didn't find a solution to this probleme yet. If someone can help me solve this probleme, I would really appreciated I'm even willing to pay. Thanks. PS: I dosen't really need to be the script posted above. The ideea is to post data into my database from the aweber form (the page where is placed) and to not change the script (A. form) behaviour. Link to comment https://forums.phpfreaks.com/topic/189611-aweber-post-data-into-database/#findComment-1005410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.