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

I imported my sql tables like this:

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:

<?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

    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.

      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:

      $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:

      <? 
      $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 ();
      
      

        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:

        $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");
        

        Like weedpacket said, you need to put quotes around your query. Queries are text strings (see [man]string[/man] 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:

        $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:

        $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:

        $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.

          sneakyimp wrote:

          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 [man]heredoc[/man] quoting;

          2. Use [man]sprintf[/man]; 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.

            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:

            $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);
              Write a Reply...