Jump to content

[SOLVED] Wont input into mysql


jamesxg1

Recommended Posts

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");

isloggedin();
accessneeded("C");

?>

<?php
$userrep = $_GET['username'];
$usern = $_SESSION['username'];
?>

<?php
if(isset($_POST['submit'])) {
  $reporteduser = strip_tags(mysql_real_escape_string($_POST['reporteduser']));
  $reporter = strip_tags(mysql_real_escape_string($_POST['reporter']));
  $report = strip_tags(mysql_real_escape_string($_POST['report']));
  $sql = "INSERT INTO reports (reporteduser, reporter, report) VALUES('$userrep', '$usern', '$report')";
  mysql_query($sql) or die(mysql_error());
  print ("<P ALIGN=CENTER>The user $userr has been reported to Admin.<br>Please Return Back To The <a href='../main/index.php'>Home Page</a></P>");
  exit;
}
?>


<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<P ALIGN=CENTER><center>
<h3>You Are Reporting An Offence On: <?php print $userrep ?></h3>
<textarea rows="5" cols="40" name="report" id="$report">The report you want to make about <?php print $userrep ?> goes here.</textarea><br />
<br>
<INPUT type="hidden" name="userrep" id="$userrep" value="<?php print $userrep ?>"><br>

<input type="submit" name="submit" value="Submit">
</form></P></center>






 

 

it inputs everything except $userrep :S

Link to comment
https://forums.phpfreaks.com/topic/143928-solved-wont-input-into-mysql/
Share on other sites

i assume it's a GET variable (in the URL) when the page first loads, but you then make it a POST variable by putting it into a hidden form element. update your section of code to be this:

<?php
if(isset($_POST['submit'])) {
  $reporteduser = strip_tags(mysql_real_escape_string($_POST['reporteduser']));
  $reporter = strip_tags(mysql_real_escape_string($_POST['reporter']));
  $report = strip_tags(mysql_real_escape_string($_POST['report']));
  $userrep = strip_tags(mysql_real_escape_string($_POST['userrep']));
  $sql = "INSERT INTO reports (reporteduser, reporter, report) VALUES('$userrep', '$usern', '$report')";
  mysql_query($sql) or die(mysql_error());
  print ("<P ALIGN=CENTER>The user $userr has been reported to Admin.<br>Please Return Back To The <a href='../main/index.php'>Home Page</a></P>");
  exit;
}
?>

i assume it's a GET variable (in the URL) when the page first loads, but you then make it a POST variable by putting it into a hidden form element. update your section of code to be this:

<?php
if(isset($_POST['submit'])) {
  $reporteduser = strip_tags(mysql_real_escape_string($_POST['reporteduser']));
  $reporter = strip_tags(mysql_real_escape_string($_POST['reporter']));
  $report = strip_tags(mysql_real_escape_string($_POST['report']));
  $userrep = strip_tags(mysql_real_escape_string($_POST['userrep']));
  $sql = "INSERT INTO reports (reporteduser, reporter, report) VALUES('$userrep', '$usern', '$report')";
  mysql_query($sql) or die(mysql_error());
  print ("<P ALIGN=CENTER>The user $userr has been reported to Admin.<br>Please Return Back To The <a href='../main/index.php'>Home Page</a></P>");
  exit;
}
?>

 

 

 

Worked thanks mate Ace!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.