data not ariving in MYSQL
Results 1 to 7 of 7

Thread: data not ariving in MYSQL

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3

    data not ariving in MYSQL

    Hi, im a little bit of a newbie, but i have a question on the below:

    I imported my sql tables like this:

    Code:
    CREATE TABLE website123(
            id integer NOT NULL AUTO_INCREMENT,
            sitetitle VARCHAR(500),
            google VARCHAR(500),
            keywords VARCHAR(500),
            txtcolor VARCHAR(500),
            bgdcolor VARCHAR(500),
            bgheader VARCHAR(500),
            bgleft VARCHAR(500),
            bgright VARCHAR(500),
            bgfooter VARCHAR(500),
            bgmiddle VARCHAR(500),
            link VARCHAR(500),
            hoverbg VARCHAR(500),
            hovertext VARCHAR(500),
            inhoud VARCHAR(2000),
            link1 VARCHAR(500),
            link2 VARCHAR(500),        
            rechtertekst VARCHAR(2000),        
            footertext VARCHAR(2000),            
            PRIMARY KEY(id));
    The above variables are based on a former form form, which is working, the form form got linked to the below page, but nothing gets posted in my sql database, and i get no error after the click. The form is set on method=post, and the input tags from the form are included with an id and a name:

    Code:
    <?php
    // Connecting to the MySQL server
    
    mysql_connect("localhost", "usernamehidden", "passwordhidden")  or 
            die("Could not connect to database (1): " . mysql_error()); 
    mysql_select_db("database name") or die( "Could not select database" ); 
    // Storing form values into PHP variables
    $sitetitle = $_POST["sitetitle"];
    $google = $_POST['google'];
    $keywords = $_POST["keywords"];
    $txtcolor = $_POST["txtcolor"];
    $bgdcolor = $_POST["bgdcolor"];
    $bgheader = $_POST["bgheader"];
    $bgleft = $_POST["bgleft"];
    $bgright = $_POST["bgright"];
    $bgfooter = $_POST["bgfooter"];
    $bgmiddle = $_POST["bgmiddle"];
    $link = $_POST["link"];
    $hoverbg = $_POST["hoverbg"];
    $hovertext = $_POST["hovertext"];
    $inhoud = $_POST["inhoud"];
    $link1 = $_POST["link1"];
    $link2 = $_POST["link2"];
    $rechtertekst = $_POST["rechtertekst"];
    $footertext = $_POST["footertext"];
    // Inserting these values into the MySQL table
    // we created above
    $query = "insert into website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ( . $sitetitle . ,  . $google . ,  . $keywords . ,  . $txtcolor . ,  . $bgdcolor . ,  . $bgheader . ,  . $bgleft . ,  . $bgright . ,  . $bgfooter . ,  . $bgmiddle . ,  . $link . ,  . $hoverbg . ,  . $hovertext . ,  . $inhoud . ,  . $link1 . ,  . $link2 . ,  . $rechtertekst . ,  . $footertext . )";
    $result = mysql_query($query);
    
    echo 'Thank you for submitting your details!';
    ?>

    Can someone help me i am clueless, and want to prevent that i destory the script by making small adjustments until i find the problem (which happend to me a few times allready) ;-)


    gr Maarten

  2. #2
    Chamberlain Sxooter's Avatar
    Join Date
    Aug 2002
    Location
    Denver, CO
    Posts
    4,027
    See how your open connect and select db have 'or die ("some message" . mysql_error())' after them? Add that to the line for the mysql query and see what error, if any, you are getting.
    PostgreSQL, because your data matters.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    3

    update, still not working

    Hi, I updated the code slightly (after 4 hours), but i still did not succeed in getting it to work:
    Im now getting Parse error:

    syntax error, unexpected T_STRING in website.php on line 28

    Below the new code, can someone advise me, mayb explain me how to code line 28?

    here is line 28:
    Code:
    $query = INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ("$sitetitle", "$google", "$keywords", "$txtcolor", "$bgdcolor", "$bgheader", "$bgleft", "$bgright", "$bgfooter", "$bgmiddle", "$link", "$hoverbg", "$hovertext", "$inhoud", "$link1", "$link2", "$rechtertekst", "$footertext");
    here is the complete code:
    Code:
    <? 
    $db_host = 'server';
    $db_user = 'user';
    $db_pass = 'pass';
    mysql_connect ('$db_host', '$db_user', '$db_pass') or die (mysql_error()); 
    mysql_select_db ('website123') or die (mysql_error()); 
    // Storing form values into PHP variables
    $sitetitle = $_POST['sitetitle'];
    $google = $_POST['google'];
    $keywords = $_POST['keywords'];
    $txtcolor = $_POST['txtcolor'];
    $bgdcolor = $_POST['bgdcolor'];
    $bgheader = $_POST['bgheader'];
    $bgleft = $_POST['bgleft'];
    $bgright = $_POST['bgright'];
    $bgfooter = $_POST['bgfooter'];
    $bgmiddle = $_POST['bgmiddle'];
    $link = $_POST['link'];
    $hoverbg = $_POST['hoverbg'];
    $hovertext = $_POST['hovertext'];
    $inhoud = $_POST['inhoud'];
    $link1 = $_POST['link1'];
    $link2 = $_POST['link2'];
    $rechtertekst = $_POST['rechtertekst'];
    $footertext = $_POST['footertext'];
    // Inserting these values into the MySQL table
    // we created above
    $query = INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ("$sitetitle", "$google", "$keywords", "$txtcolor", "$bgdcolor", "$bgheader", "$bgleft", "$bgright", "$bgfooter", "$bgmiddle", "$link", "$hoverbg", "$hovertext", "$inhoud", "$link1", "$link2", "$rechtertekst", "$footertext");
    $result = mysql_query ($query);
    
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    
    ?> 
    
    
    <?php  
    
    // close mysql
    
    mysql_close ();

  4. #4
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,850
    You haven't quoted your SQL string.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  5. #5
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,834
    The first thing you need to sort out is that your file has a big fat syntax error in it. A syntax error will prevent the script from doing anything at all because it is not valid PHP

    This line is improper syntax:
    PHP Code:
    $query INSERT INTO website123 (sitetitlegooglekeywordstxtcolorbgdcolorbgheaderbgleftbgrightbgfooterbgmiddlelinkhoverbghovertextinhoudlink1link2rechtertekstfootertextvalues ("$sitetitle""$google""$keywords""$txtcolor""$bgdcolor""$bgheader""$bgleft""$bgright""$bgfooter""$bgmiddle""$link""$hoverbg""$hovertext""$inhoud""$link1""$link2""$rechtertekst""$footertext"); 
    Like weedpacket said, you need to put quotes around your query. Queries are text strings (see string in the docs). Defining a string that has quotes in it gets tricky because you have to escape any quote marks in your string that are the same as the quote type (single or double) that you used to delineate your string in the first place. Since your string contains many instances of double quotes, I would be inclined to just use single quotes around your query:
    PHP Code:
    $query 'INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ("$sitetitle", "$google", "$keywords", "$txtcolor", "$bgdcolor", "$bgheader", "$bgleft", "$bgright", "$bgfooter", "$bgmiddle", "$link", "$hoverbg", "$hovertext", "$inhoud", "$link1", "$link2", "$rechtertekst", "$footertext")'
    HOWEVER using single quotes means that each of those variables you have specified in your query will not be evaluated so instead of inserting the contents of the variable $keywords into your database, you would literally be inserting the string $keywords. If you use double quotes to define your string, you must escape each occurrence of double quotes with a backslash like so:
    PHP Code:
    $query="INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values (\"$sitetitle\", \"$google\", \"$keywords\", \"$txtcolor\", \"$bgdcolor\", \"$bgheader\", \"$bgleft\", \"$bgright\", \"$bgfooter\", \"$bgmiddle\", \"$link\", \"$hoverbg\", \"$hovertext\", \"$inhoud\", \"$link1\", \"$link2\", \"$rechtertekst\", \"$footertext\")"
    As you can see, it's a bit of a pain in the ass and also quite messy looking.

    Another alternative is to put single quotes in your query and use double quotes to define your query string:
    PHP Code:
    $query="INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ('$sitetitle', '$google', '$keywords', '$txtcolor', '$bgdcolor', '$bgheader', '$bgleft', '$bgright', '$bgfooter', '$bgmiddle', '$link', '$hoverbg', '$hovertext', '$inhoud', '$link1', '$link2', '$rechtertekst', '$footertext')"
    Another thing you must do when putting user input into a query is use [/man]mysql_real_escape_string[/man] to escape each variable before you stick it into a query. Otherwise, you'll have a problem if the submitted data contains quotation marks. You will also be vulnerable to sql injection.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  6. #6
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,850
    Quote Originally Posted by sneakyimp
    Another alternative is to put single quotes in your query and use double quotes to define your query string:
    And of course the third, fourth, and fifth methods would be
    1. Use heredoc quoting;
    2. Use sprintf; and
    3. Stop using the outdated and deprecated MySQL extension in favour of something that (has been updated at some point in the past ten years and) supports the use of prepared statements.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thank you very very very much! I now succeeded to put in data to my database thank to you guys! If others are experiencing the same: below i posted the below part of my php code, which now i putting in the data:

    Code:
    $sitetitle = mysql_real_escape_string($_POST['sitetitle']);
    $google = mysql_real_escape_string($_POST['google']);
    $keywords = mysql_real_escape_string($_POST['keywords']);
    $txtcolor = mysql_real_escape_string($_POST['txtcolor']);
    $bgdcolor = mysql_real_escape_string($_POST['bgdcolor']);
    $bgheader = mysql_real_escape_string($_POST['bgheader']);
    $bgleft = mysql_real_escape_string($_POST['bgleft']);
    $bgright = mysql_real_escape_string($_POST['bgright']);
    $bgfooter = mysql_real_escape_string($_POST['bgfooter']);
    $bgmiddle = mysql_real_escape_string($_POST['bgmiddle']);
    $link = mysql_real_escape_string($_POST['link']);
    $hoverbg = mysql_real_escape_string($_POST['hoverbg']);
    $hovertext = mysql_real_escape_string($_POST['hovertext']);
    $inhoud = mysql_real_escape_string($_POST['inhoud']);
    $link1 = mysql_real_escape_string($_POST['link1']);
    $link2 = mysql_real_escape_string($_POST['link2']);
    $rechtertekst = mysql_real_escape_string($_POST['rechtertekst']);
    $footertext = mysql_real_escape_string($_POST['footertext']);
    // Inserting these values into the MySQL table
    // we created above
    $query="INSERT INTO website123 (sitetitle, google, keywords, txtcolor, bgdcolor, bgheader, bgleft, bgright, bgfooter, bgmiddle, link, hoverbg, hovertext, inhoud, link1, link2, rechtertekst, footertext) values ('$sitetitle', '$google', '$keywords', '$txtcolor', '$bgdcolor', '$bgheader', '$bgleft', '$bgright', '$bgfooter', '$bgmiddle', '$link', '$hoverbg', '$hovertext', '$inhoud', '$link1', '$link2', '$rechtertekst', '$footertext')";  
    $result = mysql_query ($query);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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