SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query won't insert

    I want to insert a persons status and username into a database. No error shows up, but when I click submit, either the action runs or nothing happens, or the page just refershes. Could anybody help me debug this code? Thanks!

    PHP Code:
    <?php
    require("includes/connect.php");
    require(
    "includes/redirect.php");
    require(
    "includes/userInfo.php");
    $status $_POST['status'];
    $upSQL "INSERT INTO sq_status (UID, Status) VALUES (".$id.", ".$status.")";
    $upRun mysql_query($upSQL);
    if(!
    res){
        die(
    mysql_error());
        
    mysql_close($con);
        exit;
    }
    else{
        
    header('Location: '$profile);
        
    mysql_close($con);
        exit;
    }
    ?>
    Here is the HTML, but I don't think you'll need it.

    HTML Code:
        <form id="form1" name="form1" method="post" action="statusUp.php">
          <span id="sprytextarea1">
          <label>
            <textarea name="status" id="status" cols="52" rows="5">What are you doing?</textarea>
          </label>
          <br />
    <span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span>
          <p>
            <input type="submit" name="submit" id="submit" value="Update" />
          </p>
        </form>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could anybody help me debug this code?
    Print out variables - are they what you expect?
    Print out queries - are they what you expect? do they run (test in phpmyadmin)?

  3. #3
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright! I found out that it's the query that's not working. What would be wrong?

    PHP Code:
    $status $_POST['status'];
    $upSQL "INSERT INTO sq_status (UID, Status) VALUES (".$id.", ".$status.")";
    $upRun mysql_query($upSQL); 

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,047
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Well the first obvious problem is that your missing quotes around the status string.

    PHP Code:
    $upSQL "INSERT INTO sq_status (UID, Status) VALUES ($id,'$status')"
    I'm also about 99&#37; certain that the label element can't contain block elements. So your textarea should reside outside the label but that is HTML thing.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here i want to tell you 3 errors!
    1,you design your database table,table id better chose auto_increment,and insert into table not insert table id.
    2,you'll insert into string in php,you should add quote .example:insert into table(name) values("$name")
    3,In your form,your textarea should reside outside the label.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by oddz View Post
    Well the first obvious problem is that your missing quotes around the status string.
    why is that obvious?

    post #1 says "I want to insert a persons status and username into a database"

    what's obvious to me is that status is probably numeric while username is string

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    why is that obvious?
    was actually my first thought as well.

    we need a poll to sort this out, it should have tigers and goats on it.

    :smiley

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    what's obvious to me is that status is probably numeric while username is string
    There's a textarea in his form called status, prefilled with the text "What are you doing?"

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    doh!! i totally overlooked that

    my excuse is "Here is the HTML, but I don't think you'll need it."
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just need someone to find the error in the code, I don't know where it is and I need some help. Thanks!


  11. #11
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the problem. IN one of the required files, the connection was closed, so, I couldn't make the connection.


Bookmarks

Posting Permissions

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