just trying to do simple site but no php hates me :(

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kkddrpg@gmail.com

    #1

    just trying to do simple site but no php hates me :(

    the database looks like this

    the database is called
    username_tpp (not really just using username as a sub)
    the table is called
    home
    it has
    field 1 : varchar(50) | latin1_swedish_ ci | no attributes | null = no |
    default = (nothing) | extra = (nothing) | action = primary key |
    comments = h

    field 2 : text | latin1_swedish_ ci | no attributes | null = no |
    default = (nothing) | extra = (nothing) | action = text | comments = b

    all i am trying to achive is to have someone post what they want to
    appear on their website on this page as in the header and the body of
    their site (i will do xhtml formating to make it look nicer if the
    script ever works)

    <?php // update_site.php
    // This script adds a entry to the database.

    // Address error handling.
    ini_set ('display_error s', 1);
    error_reporting (E_ALL & ~E_NOTICE);

    if (isset ($_POST['submit'])) { // Handle the form.

    // Connect and select.
    if ($dbc = @mysql_connect ('localhost', username', password)) {

    if (!@mysql_select _db ('username_tpp' )) {
    die ('<p>Could not select the database because:
    <b>' . mysql_error()
    .. '</b></p>');
    }

    } else {
    die ('<p>Could not connect to MySQL because: <b>' .
    mysql_error() .
    '</b></p>');
    }

    // Define the query.
    $query = "INSERT INTO home (1) VALUE ('{$_POST['header']}')";
    "INSERT
    INTO home (2) VALUE '{$_POST['body']}'";

    // Execute the query.
    if (@mysql_query ($query)) {
    print '<p>The blog entry has been added.</p>';
    } else {
    print "<p>Could not add the entry because: <b>" .
    mysql_error() .
    "</b>. The query was $query.</p>";
    }

    mysql_close();

    }

    // Display the form.
    ?>
    <form action="update_ site.php" method="post">
    <p>Page Header: <input type="text" name="header" size="40"
    maxsize="100" /></p>
    <p>Page Body :&nbsp;&nbsp;
    <textarea name="body" cols="40" rows="5"></textarea></p>
    <input type="submit" name="submit" value="Update My Website" />
    </form>

    i get this error...

    Could not add the entry because: You have an error in your SQL syntax;
    check the manual that corresponds to your MySQL server version for the
    right syntax to use near '1) VALUE ('hello')' at line 1. The query was
    INSERT INTO home (1) VALUE ('hello').

    then i have another script that is not working
    either which is:

    this is the script for their home page that retirves the data that this
    one posts into the table.

    <?php // index.php
    // This script retrieves header and body text from the database.

    // Address error handing.
    ini_set ('display_error s', 1);
    error_reporting (E_ALL & ~E_NOTICE);

    // Connect and select.
    if ($dbc = @mysql_connect ('localhost', 'username', 'password')) {

    if (!@mysql_select _db ('username_tpp' )) {
    die ('<p>Could select the database because: <b>' .
    mysql_error() .
    '</b></p>');
    }

    } else {

    die ('<p>Could not connect to MySQL because: <b>' .
    mysql_error() .
    '</b></p>');

    }

    // Define the query.
    $query = 'SELECT * FROM home';

    if ($r = mysql_query ($query)) { // Run the query.
    >>>>this is not in the actual script but im sure this is where im going wrong<<<<<<
    // Retrieve and print every record.
    while ($row = mysql_fetch_arr ay ($r)) {
    print "<p><h3>{$r ow['1']}</h3>
    {$row['2']}<br />
    </p><hr />\n";
    }

    } else { // Query didn't run.

    die ('<p>Could create the table because: <b>' . mysql_error() .
    "</b>.
    The query was $query.</p>");

    } // End of query IF.

    mysql_close(); // Close the database connection.
    ?>

    could you please help me ive been debugging for days now and my head is
    going to explode

    -thank you, philip (kirewire.com, leetmachines.co m, pealtech.com,
    leetbargains.co m)

  • Jerry Stuckle

    #2
    Re: just trying to do simple site but no php hates me :(

    kkddrpg@gmail.c om wrote:
    the database looks like this
    >
    I responded to this post in comp.database.m ysql.

    Please don't multi-post. If you wish to ask in multiple newsgroups,
    please cross-post.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • so many sites so little time

      #3
      Re: just trying to do simple site but no php hates me :(

      cross post? i did multipost cause i wasnt sure what group could help
      the most... plus it gives me a better chance of getting a decent
      response its not spamming a message board to get posts its to get good
      info what if you werent going to show up in site design group for 2
      weeks but showed up hear? eh.

      Jerry Stuckle wrote:
      kkddrpg@gmail.c om wrote:
      the database looks like this
      >
      I responded to this post in comp.database.m ysql.
      >
      Please don't multi-post. If you wish to ask in multiple newsgroups,
      please cross-post.
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • so many sites so little time

        #4
        Re: just trying to do simple site but no php hates me :(

        what i am trying to say here is

        // Define the query.
        $query = "INSERT INTO home (1) VALUE ('{$_POST['header']}')";
        "INSERT
        INTO home (2) VALUE '{$_POST['body']}'";

        the name of the table is home
        and that table whas two fields 1 and 2 and field 1 is a varchar 50 for
        the header and field to is text for the body of my site and 'header'
        and 'body' are the values im useing b/c those are the names of the
        fields in the form

        Comment

        • Gordon Burditt

          #5
          Re: just trying to do simple site but no php hates me :(

          >what i am trying to say here is
          >
          >// Define the query.
          $query = "INSERT INTO home (1) VALUE ('{$_POST['header']}')";
          >"INSERT
          >INTO home (2) VALUE '{$_POST['body']}'";
          >
          >the name of the table is home
          >and that table whas two fields 1 and 2 and field 1 is a varchar 50 for
          >the header and field to is text for the body of my site and 'header'
          >and 'body' are the values im useing b/c those are the names of the
          >fields in the form
          1 and 2 don't look like field names. I also suggest you pick
          something more descriptive. If you want them interpreted as field
          names, you'll need to backquote them.

          INSERT INTO home (`1`) ...


          Comment

          • Jerry Stuckle

            #6
            Re: just trying to do simple site but no php hates me :(

            so many sites so little time wrote:
            Jerry Stuckle wrote:
            >
            >>kkddrpg@gmail .com wrote:
            >>
            >>>the database looks like this
            >>>
            >>
            >>I responded to this post in comp.database.m ysql.
            >>
            >>Please don't multi-post. If you wish to ask in multiple newsgroups,
            >>please cross-post.
            >>
            >>--
            >>============= =====
            >>Remove the "x" from my email address
            >>Jerry Stuckle
            >>JDS Computer Training Corp.
            >>jstucklex@att global.net
            >>============= =====
            >
            >
            cross post? i did multipost cause i wasnt sure what group could help
            the most... plus it gives me a better chance of getting a decent
            response its not spamming a message board to get posts its to get good
            info what if you werent going to show up in site design group for 2
            weeks but showed up hear? eh.
            >
            (Top posting fixed)

            Yes. Cross posting is posting the same message to multiple groups *at
            the same time*. This way messages from either group shows up in both.

            Multi-posting is posting two messages (but the same text) to two
            different groups. Multiposting is not spamming - but it makes things
            very difficult to follow up. Also, people who don't read both groups
            don't know what's going on in the other one.

            I suggest you work with the messages in the mysql group. Right now this
            is a problem with your SQL syntax, not PHP.

            P.S. Please don't top post. Thanks.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...