Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109

    Unanswered: form doesnt save in mysql

    i have a problem with phpmysql i want to save form data in mysql
    i created a form and coding just like this
    PHP Code:
    <?
    $name
    =$_post['name'];
    $email=$_post['email'];
    $subject=$_post['subject'];
    $comment=$_post['comment'];
    $host="localhost";//mysql host
    $user="root";//mysql user
    $pass="";//mysql password
    $con=mysql_connect($host,$user,$pass);
    $select=mysql_select_db(a,$con);
    $sql="insert into alrehman(name,email,subject,comment)Values('$name','$email','$subject','$comments');";
    $query=mysql_query($sql);
    mysql_close();
    ?>

    but it doesn't save just empty box shown in mysql database it created row but emptied why this happen

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have you checked there are values in the variables '$name','$email','$subject','$comments'
    depending on how your PHP instgallation is configured you may need to prefix the values with $POST_ or $GET_
    whilst you are at it you need to validate the data you write to the db.. accepting user input without validation OR converting to HTMLENTITIES you are leaving yourself open to attack from people wanting to subvert your site
    PHP is a capitalisation aware environment $MAIL is not the same as $Mail

    I'd sugegst you always examine the $MySQL_ErrNO function after each call to the DB
    I'd suggest you learn some debugging skills, not least the judicious use of the die statement

    eg
    die (echo $sql);
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    i agree with you healdem can you please suggest me the ready made contact form which will i place on my site and save form data in mysql is there any ready made form just i have to install that .

  4. #4
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    you said

    I'd sugegst you always examine the $MySQL_ErrNO function after each call to the DB
    I'd suggest you learn some debugging skills, not least the judicious use of the die statement


    tell me where can i learn this skill as well as making of content management system

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    <?
    $name=$_post['name'];
    $email=$_post['email'];
    $subject=$_post['subject'];
    $comment=$_post['comment'];
    $out .="name= $name, POST =".$_post['name']."\n";
    $out .="email= $email, POST =".$_post['email']."\n";
    $out ."subject= $subject, POST =".$_post['subject']."\n;
    $out .="comment= $comment=, POST =".$_post['comment']."\n
    die (echo $out);


    debugging is the art of carefully examining what your program is doing against what you expect it to be doing. so check what inputs you are getting
    test the program with known good data

    so in thsi case
    you knwo you are getting something written to the db, its blank lines, but the sql is doing something

    so you need to develop a strategy to work out what is going wrong with your program. work through a block of code and make certain that what you expect to happen is happening.
    check inputs
    check outputs
    analyse the evidence and come to a conclusion as to where the fault lies, or where you think it lies. you are seeking to find the fault, so finding areas which are working is just as useful as finding areas which aren't working.

    as you cross off each bit of code that is working you come closer to where the fault is. sometimes thats the real black art in debugging, making a good guess where the fault lies.

    the other option here is to echo the sql you are suign to the screen and make certain that what you are sending to the sql engine is what you think. it also pays to examine the response from the sql engine before doing any further processing. in php you need to examine the mysql_errno and/or mysql_error functions to see if the sql engine complained about what it was sent.

    unlike many other languages php is very (many would argue too) fault tolerant

    make certain that whilst in development you set the error reporting level appropriately
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109

    explanation please

    can you please explain the coding that you write about just explain 1st line

    $out .="name= $name, POST =".$_post['name'].

    what's mean of . after $out
    and another is name=$name
    i couldn't understand what the mean cause i am new in such things new thing you tellme and i couldn't understand

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    thats a building a variable to display the values of your varaibles
    its the equivalent of

    $out .="name=".$name; //add the $name to the displa\y variable $out
    $out .=" POST =".$_post['name'] //add the value from the $POST_ global variable 'name'
    $out .="\n"; //add a form feed to $out

    //repeat for the other 3 variables

    die (echo $out); //then stop execution of the script and display the value of $out on the screen

    whilst you are at it make certain that you switch on full error reporting
    error_reporting(E_All & E_STRICT)

    I can't remmebr if its | or & to doo a bitwise add.. check da manuel (PHP: Hypertext Preprocessor) for details
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    or you could just print out all the POST values at once with :
    Code:
    print_r( $_POST );

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    true
    but I'm hoping to convince DON_LOG to develop some debugging skills, or at least the vesitge of analysing a problem and try to develop a strategy to devise a solution or a methodology to get a solution

    after all there is a world of difference between $_post and $_POST
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •