Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Won't deposit to DB

    I am trying to setup a report system. Code won't deposit to the database for some reason.. Heres the code.

    PHP Code:
    <?php
    ob_start
    (); //Allow cookies
    include("config.php"); //get config file
    switch($_GET[act]){ //change links to ?act=
    default: //Make this our default page.
    if($logged[username] && !$_POST[report]){ //check if they are logged in
    echo "<font type='verdana' size='2'><body link='black' alink='black' vlink='black'>
    <form method=\"post\" action=\"index.php?x=Report&act=Do\">
    <b>Username</b>:<br />
    <input type=\"text\" name=\"user\" size=\"15\"><br />
    <b>Current Bankroll</b>:<br />
    <input type=\"text\" name=\"report\" size=\"15\"><br />
    <b>Starting Bankroll</b>:<br />
    <input type=\"text\" name=\"prev\" size=\"15\"><br />
    <input type=\"submit\" name=\"report\" value=\"Report User\">
    </form>
    "
    //Echo the form
    }elseif(!$logged[username] && !$_POST[report]){ //If Not Logged in
    echo "<b>Error</b>: You Are Not Logged In"//Echo Error
    //End Else If
    break; //End the page

    case 'Do'//Make the Go case.
    if($logged[username] && $_POST[report]){ //Check if they are logged in and the form is submitted
    $user stripslashes(htmlspecialchars($_POST[user])); //User Variable
    $reason stripslashes(addslashes(htmlspecialchars($_POST[reason]))); //Reason Variable
    $prev stripslashes(addslashes(htmlspecialchars($_POST[reason])));
    $date date("l, F d, Y");
    $errs = array(); //Make An Array
    if(empty($user)){
    $errs[] = "<b>Error</b>: You Must Enter A Username<br />"//echo error
    }//end
    if(empty($reason)){ //if reason is empty
    $errs[] = "<b>Error</b>: You Must Enter Bankroll Info<br />"//echo error
    //End
    if(count($errs) > 1){ //If there are more than 1 errors
    foreach($errs as $oops){ //Count them up
    echo "$oops"//Echo Errors
    }
    }else{
    $report mysql_query("INSERT INTO reps(`username`,`reason`,`prev`,`date`,`reported_by`) VALUES ('$user','$reason','$prev','$date','$logged[username]')") or die(mysql_error()); //do the query or die with an error
    echo "$user Has Been Reported."//Echo Error
    //End the queryness
    }elseif($logged[username] && !$_POST[report]){ //If logged in but form not submitted
    echo "<b>Error</b>: You Must Go Back And Submit The Form"//Echo error
    }elseif(!$logged[username] && !$_POST[report]){ //If not loged in and no form
    echo "<b>Error</b>: You Are Not Logged In"//Echo Error
    }//End check login
    break; //End The Page
    //End switch get
    ?>

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by SBDTHRU View Post
    Code won't deposit to the database for some reason..
    What happens? Errors? Warnings? Any output? No output? At least toss out some bare minimum of information for someone to help, if that's what you really want.
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    What happens? Errors? Warnings? Any output? No output? At least toss out some bare minimum of information for someone to help, if that's what you really want.
    Like the form should sent information into the MySQL database. But when I click submit, I go look and there is nothing there. I know the config.php is good. The file that lets you read the reports is fine as well. For some reason it just wont submit the info and I can't figure it out.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Once again, any output? After you click submit, how does the page behave? What is the output? If you don't see "$user Has Been Reported.", you're never getting to the query section. But I can't tell if you get into that section because you haven't posted what happens.

    I notice that you're not testing the result of mysql_query, so you don't know whether anything is being inserted (assuming you actually reach that section). Always test return values. They tell you what your application is doing.
    Are you a Help Vampire?

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    Once again, any output? After you click submit, how does the page behave? What is the output? If you don't see "$user Has Been Reported.", you're never getting to the query section. But I can't tell if you get into that section because you haven't posted what happens.

    I notice that you're not testing the result of mysql_query, so you don't know whether anything is being inserted (assuming you actually reach that section). Always test return values. They tell you what your application is doing.
    I'm not quite sure what you mean. (Total n00b)

    But I think I figured out the problem. It doesn't execute the 'Do' function because when the form is submitted it refreshes to 'index.php?x=Report&act=Do' instead of 'report.php?x=Report&act=Do'.

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Figured it out.


  •  

    Posting Permissions

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