PHP: Simple form to posts to database -
i've been out of touch using php outside of content management systems i've forgot of basic syntax etc. i'm trying build simple form collects user data , sends database table called 'creathive_applications'.
here html form:
<form action="<?php bloginfo('home'); ?>" method="post"> <fieldset id="membershipform"> <ul class="clearfix"> <li id="li-status"> <span>i a:</span> <menu> <li><label for="student"><input disabled="disabled" type="radio" name="status" id="student" checked="checked" value="graduate" /> graduate</label></li> <li><label for="student2"><input disabled="disabled" type="radio" name="status" id="student2" value="undergraduate" /> undergraduate</label></li> </menu> </li> <li id="li-firstname"> <label for="firstname">first name</label> <input name="firstname" disabled="disabled" type="text" placeholder="first name" id="firstname" title="first name" /> </li> <li id="li-lastname"> <label for="lastname">last name</label> <input name="lastname" disabled="disabled" type="text" placeholder="last name" id="lastname" title="last name" /> </li> <li id="li-email"> <label for="email">email address</label> <input name="email" disabled="disabled" type="text" placeholder="email address" id="email" title="email address" /> </li> <li id="li-url"> <label for="url">url</label> <input name="url" disabled="disabled" type="text" placeholder="url of you've made" id="url" title="url of you've made" /> </li> <li id="li-buttons"> <input name="submit" type="submit" value="send application ►" title="send application" onclick="alert('invites available march 2011');" /> </li> </ui> </fieldset> </form>
and here php jazz:
if(isset($_post['submit'])) { $status = $_post['status']; $firstname = $_post['firstname']; $lastname = $_post['lastname']; $email = $_post['email']; $url = $_post['url']; $host = '####'; $username = '####'; $pass = '####'; mysql_connect($host,$username,$pass); mysql_select_db($username); $query = "insert creathive_applications values (null,'".$status."','".$firstname."','".$lastname."','".$email."','".$url."')"; $result = mysql_query($query); }
can me fix can't remember how run sql statement , send data database :/ i've added database username , password host database name? go again?
i know rather n00b question, appreciated.
thanks lot
well, no error it's impossible tell fix.
however, there obvious things do.
see comments:
<? //show possible errors. should set level error_reporting(e_all); echo "landed @ form handler<br>"; // buttons not being sent or gets misspelled if($_server['request_method'] == 'post') { echo "here goes post processing<br>"; $host = '####'; $username = '####'; $pass = '####'; mysql_connect($host,$username,$pass); mysql_select_db($username); // strings should escaped // , should done after connecting db $status = mysql_real_escape_string($_post['status']); $firstname = mysql_real_escape_string($_post['firstname']); $lastname = mysql_real_escape_string($_post['lastname']); $email = mysql_real_escape_string($_post['email']); $url = mysql_real_escape_string($_post['url']); $query = "insert creathive_applications values (null,'$status','$firstname','$lastname','$email','$url')"; echo $query; // run queries way notified in case of error $result = mysql_query($query) or trigger_error(mysql_error().". query: ".$query); var_dump($result); }
in case still see no error, add line temporarily top of script
ini_set('display_errors',1);
and remove after problem solved.
edit added debug info.
if see none of it's messages, you're sending form wrong url. if see of them, post here
Comments
Post a Comment