Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: mysql_query isnt working

  1. #1

    mysql_query isnt working

    I have a form that is suposed to insert a new record in to the db when someone clicks on the submit button

    I think i have it set u p correctly her is my page

    PHP Code:
    <?php
     
    if (isset ($_POST['post'])){
        
        
    $tanounce $_POST['announcements'];
        
    $announce trim($tannounce);
                    if ( !empty(
    $announce) ) 
                {    
    mysql_query("INSERT INTO `impactathletics`.`team` (`announcements`)
    WHERE team_id = '1' 
    VALUES ('
    $announce')");
                  
                 }
        } 
    ?>
    <html>
    <head>
    </head>
    <body>
                <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
                    <textarea name="announcements" cols="45" rows="5"></textarea>
                    <br />
                    <input type="submit" value="Submit" />
                    <br />
                </form>
    </body>
    </heml>
    can any one see the problem?
    side note the table its supposed to be inserted into already contains info. Will it add to the field? or will it drop it.

  2. #2
    not much help with there php, but there is a spelling mistake on the closing tag for html.

    </html> you put </heml>
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

  3. #3
    INSERT will ONLY add NEW entries not UPDATE them

    if you needed to insert something the format is
    Code:
    mysql_query("INSERT INTO table (col1, col2) VALUES('val1', 'val2' ) ")
    notice there is no WHERE statement in an insert... so what you're looking for is UPDATE
    Code:
    mysql_query("UPDATE table SET col = 'val' WHERE col = 'currentval' ")
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  4. #4
    oooooo. I see now. Thanks again. It was weird i ran the script and i didnt receive any errors but it also didn't post to the db when i executed. Ill give it a go. thanks again guys.

  5. #5
    im an idiot... i did the update query and it still didn't work.. but i figured out my problem... i forgot to give a name to the submit button ><

    at least i found it

    thanks again every1

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012