Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Apr 2013
    Posts
    18

    Unanswered: Greetings... and HELP!

    Hi all,

    I do hate joining forums cos I got stuck, but here I am.

    I'm building a website here in the UK for a not for profit organisation to help people with their energy costs.

    I'm self taught and have always managed to figure web design out UP UNTIL NOW!

    I am trying to link a form to mysql using php. I've managed to get a test db working but my main db keeps giving me the final error message (as in, i'm connecting to mysql, but the data is not going into the form). This is odd and I've spent many hours triple checking spellings etc, and Google can help me no more, I've hit a wall...

    Is there any chance Spry validation could be messing things up?

    I hope someone out there can help. Shall I post some scripts?

    Many many thanks in anticipation of your help.

    Ed

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hi Ed,

    Are you trying to submit data from a form to the database, or load a form with data from the database?

    I think this is a good resource to refer to: PHP MySQL Introduction

    If you want to share specific scripts with us that would be great, just pop the code between [code] tags. The closing tag looks like this (minus the space): [ /code]
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2013
    Posts
    18
    George,

    Many thanks for your swift response. I have tried that website before (and all others I could find). I really would have preferred to have sorted this myself but this time I am stumped.

    Ok, so here's my php code:
    PHP Code:
    $host="localhost";  
    $username="...";  
    $password="...";  
    $db_name="..."
    $tbl_name="..."

    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    $title=$_POST['title'];
    $firstname=$_POST['firstname'];
    $surname=$_POST['surname'];
    $firstlineofaddress=$_POST['firstlineofaddress'];
    $secondlineofaddress=$_POST['secondlineofaddress'];
    $town=$_POST['town'];
    $postcode=$_POST['postcode'];
    $phonenumber1=$_POST['phonenumber1'];
    $phonenumber2=$_POST['phonenumber2'];
    $email=$_POST['email'];
    $preferredcontact=$_POST['preferredcontact'];
    $whattypeofenergy=$_POST['whattypeofenergy'];
    $haveyouswitchedbefore=$_POST['haveyouswitchedbefore'];
    $currentsupplier=$_POST['currentsupplier'];
    $paymentmethod=$_POST['paymentmethod'];
    $monthlyquarterlyspend=$_POST['monthlyquarterlyspend'];
    $gender=$_POST['gender'];
    $agegroup=$_POST['agegroup'];
    $doyouhaveadisability=$_POST['doyouhaveadisability'];
    $ethnicbackground=$_POST['ethnicbackground'];
    $religiousbelief=$_POST['religiousbelief'];
    $sexualorientation=$_POST['sexualorientation'];
    $wheredidyouhearaboutus=$_POST['wheredidyouhearaboutus'];


    $sql="INSERT INTO $tbl_name(title, firstname, surname, firstlineofaddress, secondlineofaddress, town, postcode, phonenumber1, phonenumber2, email, preferredcontact, whattypeofenergy, haveyouswitchedbefore, currentsupplier, paymentmethod, monthlyquarterlyspend, gender, agegroup, doyouhaveadisability, ethnicbackground, religiousbackground, sexualorientation, wheredidyouhearaboutus) VALUES('$title', '$firstname', '$surname', '$firstlineofaddress', '$secondlineofaddress', '$town', '$postcode', '$phonenumber1', '$phonenumber2', '$email', '$preferredcontact', '$whattypeofenergy', '$haveyouswitchedbefore', '$currentsupplier', '$paymentmethod', '$monthlyquarterlyspend', '$gender', '$agegroup', '$doyouhaveadisability', '$ethnicbackground', '$religiousbelief', '$sexualorientation', '$wheredidyouhearaboutus')";
    $result=mysql_query($sql);

    if(
    $result){
    echo 
    "Successful";
    echo 
    "<BR>";
    echo 
    "<a href='insert.php'>Back to main page</a>";
    }

    else {
    echo 
    "ERROR";
    }
    ?> 
    I can easily post the form in html as well but its too many characters to fit in here in full. The action of the form is 'insert.php' so I think should function... As I say I get the simple ERROR message at the point of submitting the form...

    Thanks again,

    Ed

  4. #4
    Join Date
    Apr 2013
    Posts
    18
    Sorry. I am simply trying to submit data from a form into a database... my php file is saved as insert.php... and i have blanked out my logins for obvious reasons. The connection to mysql seems to be ok as when i change my password in my php script by any character (as an experiment) my error message alters back to one that tells me my login details are incorrect...

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    echo out the value of $sql

    Can you execute the resulting statement directly against the MySQL database (e.g. via phpMyAdmin)?

    Post the value of $sql back here
    George
    Home | Blog

  6. #6
    Join Date
    Apr 2013
    Posts
    18
    I'm sorry George. I don't understand...

    Thanks for your patience

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Add the following line of code before the $result=mysql_query($sql) line
    Code:
    echo $sql; die();
    George
    Home | Blog

  8. #8
    Join Date
    Apr 2013
    Posts
    18
    So this is what I got instead of the ERROR:

    INSERT INTO tblSwitchers(title, firstname, surname, firstlineofaddress, secondlineofaddress, town, postcode, phonenumber1, phonenumber2, email, preferredcontact, whattypeofenergy, haveyouswitchedbefore, currentsupplier, paymentmethod, monthlyquarterlyspend, gender, agegroup, doyouhaveadisability, ethnicbackground, religiousbackground, sexualorientation, wheredidyouhearaboutus) VALUES('Choose...', '', '', '', '', '', '', '', '', '', 'Choose...', 'Choose...', 'Choose...', 'Choose...', 'Choose...', '', 'Choose...', 'Choose...', 'Choose...', 'Choose...', 'Choose...', 'Choose...', '')

    Would it help to see my html form? Each of my drop down menus have 'Choose...' as the null answer, some of which are required fields: validation through dreamweaver spry text fields and menu/lists...

  9. #9
    Join Date
    Apr 2013
    Posts
    18
    Needless to say this Spry validation is having no effect now that my files are uploaded to my server.

    I was at the stage earlier of rewriting the form without the spry validation, but why would dreamweaver allow you to create spry validation form fields if they weren't going to work?

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ok, we're definitely getting somewhere

    What tool have you used to create your tables and what not? Have you been using phpMyAdmin or similar?

    Whatever it is you have used, open it back up and take the query that was shown above ("INSERT INTO ...") and run it using the tool.

    Hopefully you'll get a better error message being returned
    George
    Home | Blog

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    P.S. moving this to the PHP topic
    George
    Home | Blog

  12. #12
    Join Date
    Apr 2013
    Posts
    18
    GEORGE!!! YOU ABSOLUTE LEGEND!

    MAY THE KARMIC GODS SMILE UPON YOUR GENEROUS SOUL!!!!

    Now THAT is a useful lesson. phpMyAdmin is a clever clever piece of software... Predictably it was pure and simple human error... I'd put religious background instead of religious belief!

    Now... Why does my Spry validation have no effect whatsoever now my registration page is uploaded?!...

  13. #13
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by flattenedthird View Post
    Now... Why does my Spry validation have no effect whatsoever now my registration page is uploaded?!...
    I'm not familiar with "spry" validation - what is it and what is it supposed to be doing?
    George
    Home | Blog

  14. #14
    Join Date
    Apr 2013
    Posts
    18
    It's a form of javascript... I don't know if it's a Dreamweaver only thing. It's supposed to stop the form before it is submitted and highlight those fields that demand filling in if certain characteristics are not satisfied. It works perfectly when previewed but now that it is uploaded onto server it is not functioning...

  15. #15
    Join Date
    Apr 2013
    Posts
    18
    Hmmm. It wouldn't be right to leave a forum thread without a taste of embarrassment. I'm going to come clean to this rookie error. Yes, I had uploaded my js files into a folder with a different name than the one my script was looking for.
    *tail between legs*

    Genuinely, many many thanks for your help George.

Tags for this Thread

Posting Permissions

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