...

View Full Version : Won't deposit to DB



SBDTHRU
02-25-2010, 07:19 PM
I am trying to setup a report system. Code won't deposit to the database for some reason.. Heres the 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
?>

tomws
02-25-2010, 08:33 PM
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.

SBDTHRU
02-25-2010, 08:44 PM
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.

tomws
02-25-2010, 08:52 PM
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.

SBDTHRU
02-25-2010, 09:13 PM
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'.

SBDTHRU
02-25-2010, 10:31 PM
Figured it out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum