Below is my code , I am trying to append values of $vid ,and than next time when my file loads i am trying to find currently passed value of $vid in array $ids, but every time i am getting success msg ,where i am going wrong, am i not able to append values properly ?
process.php
session_start();
if(isset($_POST)) {
$reason_data = trim($_POST['abuse_data']);
if($reason_data == "Video is offensive")
{
$reason = 'a:1:{i:0;s:18:"' . $reason_data .'";}';
}
else
{
$reason = 'a:1:{i:0;s:19:"' . $reason_data .'";}';
}
$motive = trim($_POST['remark_data']);
$uid = trim($_POST['abuse_uid']);
$vid = trim($_POST['abuse_vid']);
if(trim($_SESSION['abuse_vdo_id']) == '')
{
$_SESSION['abuse_vdo_id'] = $vid;
$str = $_SESSION['abuse_vdo_id'];
}
else {
$str = $str."," .$vid;
$_SESSION['abuse_vdo_id'] = $str;
}
print_r($_SESSION['abuse_vdo_id']);
echo "break";
print_r($str);
$ids = explode(',',$_SESSION['abuse_vdo_id']);
echo "break 2";
print_r($ids);
if(in_array($vid, $ids))
{
echo "already abused";
}
else
{
echo "success";
$query = "INSERT INTO ".DB_PREFIX."reports ( reason, motive, uid, vid ) VALUES ( '{$reason}','{$motive}', '{$uid}', '{$vid}' )";
$result = mysql_query($query);
}
}
Related
This is my code and it does not work, it's not inserting into the database. Please help me fix this problem.
$orgexist = $_POST['orgName1'];
$_SESSION['id'] = $_POST['id'];
$orgid = $_POST['id'];
$orgnme = $_POST['orgName1'];
$orgdesc = $_POST['orgDesc'];
$orgcat = $_POST['cat'];
$orgdept = $_POST['coldept'];
$orgvis = $_POST['vision'];
$orgmis = $_POST['mision'];
//get the value of category from database
//echo $orgdept;
$dept = "SELECT `col_id`, `col_description` FROM `college` WHERE `col_description` = '$orgdept'";
$deptresult = mysql_query($dept);
while ($rows = mysql_fetch_array($deptresult)) {
$getcol = $rows['col_id'];
//echo $getcol;
}
$sqlorg = mysql_query("SELECT * FROM `organization`");
while ($orgrows = mysql_fetch_array($sqlorg)) {
//$dborgid = $orgrows['org_id'];
$dborgnme = $orgrows['org_name'];
}
if ($dborgnme == $orgexist) {
echo "<script type='text/javascript'>
alert('Organization Name Already Used by other Organization');
history.back();
</script>";
} else {
$orginsrt = mysql_query("INSERT INTO `organization`(`org_id`,`org_name`,`org_desc`,`category`,`vision`,`mission`,`col_id`,`image`) VALUES ('$orgid','$orgexist','$orgdesc','$orgcat','$orgvis','$orgmis','$getcol','$image')");
echo "<script type='text/javascript'>
alert('Proceed to next Step');</script>";
//require ('orgsignup.php');
header('Location:orgsignup2.php');
//echo "Not in the Record";
}
}
You're using deprected functions, replace mysql_query by mysqli_query.
For more references see http://php.net/manual/en/function.mysql-query.php
I'm trying to make a php ajax search for the articles posted in database, but it gives me only : No results message. I've tested the connection to database and the select query, and it works.
This is the code:
<?php
require_once('dbconn.php');
$s = $_GET["s"];
$livesearch = '';
if (strlen($s) > 0)
{
$result = mysql_query("select * from articles where art_sts='1' ORDER BY title");
if ($result != FALSE)
{
foreach($result as $row)
{
if (stristr($row['title'], $s))
{
if ($livesearch == '')
{
$livesearch = ' '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'';
}
}
}
}
}
if ($livesearch == '')
{
$respond="No results...";
}
else
{
$respond = $livesearch;
}
echo $respond;
?>
You havent actually fetched the data that you are trying to output. You will need to add something like this...
while($row = mysql_fetch_assoc($result)) {
if (stristr($row['title'], $s))
{
if ($livesearch == '')
{
$livesearch = ' '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'';
}
}
}
I am attempting to display the contents of an array. I have a SELECT query that transfers two rows from the data base with a WHERE statement;
<?php
session_start();
include 'connection.php';
$inspectit = array();
$update1 = $_POST['inspect'];
$query1 = "SELECT title, reason FROM daysoff WHERE DATE(start) = '$update1' AND gighold = 1";
$day = mysql_query($query1);
while($requesting = mysql_fetch_array($day)) {
$inspectit[] = $requesting;
}
$_SESSION['inspect'] = $inspectit;
header('Location: '. $_SERVER['HTTP_REFERER']) ;
?>
I place the session variable into a new variable,$inspect, defined on a different page. I then try to display the array using;
<?php
session_start();
$inspect = $_SESSION['inspect'];
if($inspect == true) {
echo " </br>Name: </br><a> ". implode($inspect) ."</a></br></br>";
unset ($_SESSION['inspect']);
}
?>
If i var_dump($inspect) all the expected data is there, but it looks like an array holding another array. If i execute code as shown above, this gives a notice of array to string conversion. Where am i going wrong?
<?php
session_start();
$inspect = $_SESSION['inspect'];
if($inspect) {
echo " </br>Name: </br><a> ". implode($inspect) ."</a></br></br>";
unset ($_SESSION['inspect']);
}
?>
You are adding an array of query result into an array. try to change:
from:
while($requesting = mysql_fetch_array($day)) {
$inspectit[] = $requesting;
}
to:
$inspectit = mysql_fetch_array($day);
$_SESSION['inspect'] is an array, so you can used check like
$inspect = $_SESSION['inspect'];
if(count($inspect)>0) {
instead of
if($inspect == true) {
try
<?php
session_start();
$inspect = $_SESSION['inspect'];
if($inspect) {
echo " </br>Name: </br><a> ". implode("-",$inspect) ."</a></br></br>";
unset ($_SESSION['inspect']);
}
?>
or you can use empty() function too like
<?php
session_start();
$inspect = $_SESSION['inspect'];
if(!empty($inspect)) {
echo " </br>Name: </br><a> ". implode("-",$inspect) ."</a></br></br>";
unset ($_SESSION['inspect']);
}
?>
With $inspectit = array(); you are setting $inspectit to an array, then you are trying to set the string (or non-array) $_SESSION['inspect'] to equal that array. You can iterate multiple $_SESSION variables to each iteration of $inspectit as follows:
$n=0;
while($requesting = mysql_fetch_array($day)) {
$_SESSION['inspect'+$n] = $requesting;
$n++;
}
$_SESSION['inpect_count']=$n;
Thus you will know how many variables you setup with the $_SESSION['inpect_count']
I tried all above methods to no avail. I did however get it to work by doing;
<?php
session_start();
include 'connection.php';
$inspectname = array();
$inspectreason = array();
$update1 = $_POST['inspect'];
$query1 = "SELECT title, reason FROM daysoff WHERE DATE(start) = '$update1' AND gighold = 1";
$day = mysql_query($query1);
while($requesting = mysql_fetch_array($day)) {
$inspectname[] = $requesting['title'];
$inspectreason[] = $requesting['reason'];
}
$_SESSION['inspectname'] = $inspectname;
$_SESSION['inspectreason'] = $inspectreason;
header('Location: '. $_SERVER['HTTP_REFERER']) ;
?>
then to call and display the arrays;
<?php
if($inspectname == true) {
$size = sizeof($inspectname) - 1;
for($count = 0; $count <= $size; $count++){
echo " </br>Name: </br><a> ". $inspectname[$count] ."</a>";
echo " </br>Details: </br><a> ". $inspectreason[$count] ."</a></br></br>";
unset ($_SESSION['inspectname']);
unset ($_SESSION['inspectreason']);}
}
?>
I have an admin area where they can delete multiple users at a time. This is part of the code that handles the deletion. Basically it goes through the user ids and deletes each one that was marked checked.
if ($_POST['doDelete'] == 'Delete') {
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = escape($uid);
$delete = Nemesis::query("DELETE FROM users WHERE id = '{$id}' AND id <> '{$_SESSION[user_id]}'");
if (!$delete) {
$msg->add('e', QUERY_ERROR);
redirect('users.php');
exit();
}
}
}
/* we need a way to iterate over users deleted */
$msg = new Messages();
$msg->add('s', QUERY_DELETE_SUCCESS);
redirect('users.php');
exit();
}
function get_user_name_from_id($user_id)
{
if ($_SESSION['user_level'] == ADMIN_LEVEL) {
$viewUserMod = 1;
} else {
$config = Nemesis::select("usr_view_cm", "config");
$row_config = $config->fetch_assoc();
$viewUserMod = $row_config['usr_view_cm'];
}
if (is_numeric($user_id) && $viewUserMod == 1) {
$sql = Nemesis::select("full_name", "users", "id = {$user_id}");
if ($sql->num_rows > 0) {
$user_name = $sql->fetch_assoc();
return $user_name['full_name'];
} else {
// user name cannot be matched with db, either error, or most likely user was deleted
return 'User ' . $user_id;
}
} else {
return $user_id;
}
}
Where it says QUERY_DELETE_SUCCESS I would like to output something like "Deleted Bob, Jack, Tim" .etc I have a function that uses the users id and gets their names. The issue is that once the iteration is complete. Obviously those users no longer exist in the database and I cannot get their names. Is there a way of running this function during the loop, and building a string or array. That can be outputted in place of the message?
You should just be able to do this:
if ($_POST['doDelete'] == 'Delete') {
$deleted = array();
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = escape($uid);
$username = get_user_name_from_id($uid);
$delete = Nemesis::query("DELETE FROM users WHERE id = '{$id}' AND id <> '{$_SESSION[user_id]}'");
if (!$delete) {
$msg->add('e', QUERY_ERROR);
redirect('users.php');
exit();
}
$deleted[] = $username // push name to array after deletion is successful
}
}
/* The $deleted array now holds the names of the deleted users.
* Do with it what you want.
*/
$names = implode(",", $deleted)
$msg = new Messages();
$msg->add('s', QUERY_DELETE_SUCCESS . " Deleted: $names");
redirect('users.php');
exit();
}
There are several improvements that can be made here, including efficiency (combining many small single queries into a few larger ones) and error handling (don't redirect on the first error - instead redirect after all processing is complete to a page with a list of successes and errors), but this is the basic idea.
Here is a quick change that will do all of the operations, even if one of them errors:
if ($_POST['doDelete'] == 'Delete') {
$deleted = array();
$errored = array();
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = escape($uid);
$username = get_user_name_from_id($uid);
$delete = Nemesis::query("DELETE FROM users WHERE id = '{$id}' AND id <> '{$_SESSION[user_id]}'");
if (!$delete) {
$errored[] = $username;
} else {
$deleted[] = $username // push name to array after deletion is successful
}
}
}
/* The $deleted array now holds the names of the deleted users.
* The $errored array now holds the names of users who were not deleted due to errors.
* Do with them what you want.
*/
$msg = new Messages();
$names_deleted = implode(",", $deleted)
$msg->add('s', QUERY_DELETE_SUCCESS . " Deleted: $names_deleted");
if (count($errored) > 0) {
$names_errored = implode(",", $errored)
$msg->add('e', QUERY_ERROR . " Did not delete: $names_errored");
}
redirect('users.php');
exit();
}
You could add the names to an array as you are looping over the uids with something like this:
$names = array();
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$names[] = get_user_name_from_id($uid);
$id = escape($uid);
$delete = Nemesis::query("DELETE FROM users WHERE id = '{$id}' AND id <> '{$_SESSION[user_id]}'");
if (!$delete) {
$msg->add('e', QUERY_ERROR);
redirect('users.php');
exit();
}
}
}
Then when you want to output the confirmation message, you could turn that array into a comma separated string with something like this:
$names = implode(', ',$names);
$message = "Deleted $names";
I am passing the string value through link in the URL to the next page like this <a href="ApplicationRegister.php?plan=trial">
In the ApplicationRegister.php page, i am getting this value like this $plan = $_GET["plan"];
and i will put this into a session variable like this $_SESSION['plans'] = $plan;
Here i am getting the value. but after the if statement i am not getting the value for this plan even after using Session variable.
My complete code is like this
$plan = $_GET["plan"];
echo $plan;
$_SESSION['plan'] = $plan;
$plans = $_SESSION['plan'];
echo $_SESSION['plans'];
include('connect.php');
If (isset($_POST['submit']))
{
$CompanyName = $_POST['CompanyName'];
$CompanyEmail = $_POST['CompanyEmail'];
$CompanyContact = $_POST['CompanyContact'];
$CompanyAddress = $_POST['CompanyAddress'];
$StoreName = $_POST['StoreName'];
echo $plans;
$myURL ="$_SERVER[HTTP_HOST]";
$myURL =$StoreName.'.'.$myURL;
if (stripos($myURL, 'www.') !== 0) {
$myURL = 'www.' . $myURL;
}
if (stripos($myURL, 'http://') !== 0) {
$myURL = 'http://' .$myURL;
}
if(stripos($myURL, '.com') !== 0) {
$myURL = $myURL . '.com';
}
echo $plans;
$RegistrationType = $_POST['RegistrationType'];
$Status = "Active";
$sql = "select * from plans where planname = '$plans'";
echo $sql;
mysql_query($sql) or die (mysql_error());
$planID = $row['planid'];
$query1 = "select count(CompanyEmail) from ApplicationRegister where CompanyEmail = '$CompanyEmail'" ;
$result1 = mysql_query($query1) or die ("ERROR: " . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result1))
{
if($row['count(CompanyEmail)'] > 0)
{
$msg = "<font color='red'> <b>This E-mail id is already registered </b></font> ";
break;
}
}
if($msg == "")
{
$query2 = "select count(URL) from ApplicationRegister where URL = '$myURL' ";
$result2 = mysql_query($query2) or die ("ERROR: " . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result2))
{
if($row['count(URL)'] > 0)
{
$msg = "<font color='red'> <b>This Stroename is already registered </b></font> ";
break;
}
}
if($msg == "")
{
$sql = "INSERT INTO ApplicationRegister(planid, CompanyName, CompanyEmail, CompanyContact, CompanyAddress, RegistrationType, ApplicationPlan, ApplicationStatus, URL, CreatedDate) VALUES ('$planID', '$CompanyName', '$CompanyEmail', '$CompanyContact', '$CompanyAddress', '$RegistrationType', '$plans', '$Status', '$myURL', NOW() )";
mysql_query($sql) or die(mysql_error());
$id = mysql_insert_id();
$_SESSION['application_id'] = $id;
if($plans == "trail")
{
header("Location: userRegister.php");
exit();
}
else
{
header("Location : PaymentGateway.php");
exit();
}
}
}
}
?>
Only in the beginning it holds the value , if i try to display it within theIf (isset($_POST['submit'])) it shows blank value for plans. Do not know what to do. Plz suggest
EDITED
Even after using like this, its the same. i do not know what may be the problem :(
$plan = $_GET["plan"];
echo $plan;
$_SESSION['plans'] = $plans;
echo $_SESSION['plans'];
// $plan = +$plan;
include('connect.php');
If (isset($_POST['submit']))
{
$CompanyName = $_POST['CompanyName'];
$CompanyEmail = $_POST['CompanyEmail'];
$CompanyContact = $_POST['CompanyContact'];
$CompanyAddress = $_POST['CompanyAddress'];
$StoreName = $_POST['StoreName'];
echo $_SESSION['plans'];
EDITED
In ApplicationRegister.php, i have passed the hiddenvalue which i got fro\m previous page like this
<input type="hidden" name="plan" value="<?php echo $plan ?>"/>
then POST method i have used this. Now i am getting the value for it. Thanks to all
EDITED
if($PlanName == "trail")
{
header("Location: userRegister.php");
exit();
}
else
{
header("Location : PaymentGateway.php");
exit();
}
It's because you're not calling session_start() at the top of the page. You need that for your sessions to persist across requests (which is the point of sessions)
As well as not calling session_start();, this code is wrong:
$plan = $_GET["plan"];
echo $plan;
$_SESSION['plan'] = $plan;
$plans = $_SESSION['plan'];
echo $_SESSION['plans'];
It should be:
$plan = $_GET["plan"];
echo $plan;
$_SESSION['plan'] = $plan;
$plans = $_SESSION['plans'];
echo $_SESSION['plans'];
You are setting $_SESSION['plan'] and then trying to access $_SESSION['plans'].
Also, are you clicking a link or submitting a form? You say that you have a link, yet your code tries to access values passed from a form.
If you are using a form, don't use links. Instead, use a select element to select a plan, and then change $plan = $_GET["plan"]; to $plan = $_POST["plan"];.
EDIT:
For the redirection problem, try this code:
echo "<pre>** Plan Name: **\n";
var_dump($PlanName);
echo "</pre>";
if($PlanName == "trail")
{
header("Location: userRegister.php");
exit();
}
else
{
header("Location: PaymentGateway.php");
exit();
}
and see what it outputs.
When someone clicks the link, it's going to set the variable properly. However, it's not going to hit the $_POST['submit'] logic, because it's not a post, just a get. Then, assuming your actually posting to that page at a later point, trying to access anything in $_GET will be null, and will then reset the session variable to null.
Your first page should have code something like this
<form action="ApplicationRegister.php" method="post">
<select name="plan">
<option value="trial">Trial</option>
</select>
<input type="submit"/>
</form>
Then, you check for $_POST['plan'] and $_POST['submit']