user3148352
user3148352

Reputation:

Concatenation of variable based on input in php

Hey guys am working on a project for my college and there is one last part where i am stuck. It is about the user entering data into database and has a concatenation part where am stuck. The user has to insert a prize id and based on the prize name he enters there is a concatenation part which i will explain in the last.

this is my file where the insertion takes place:

$con=mysqli_connect("localhost","xxx","yyy","zzz");
if ($_POST['pid'] == ''||$_POST['pname'] == ''||$_POST['pamt'] == '')
    {
    header("location:adawdins_err.php");
    }
    else
    {
$class = $_POST['class'];
$dept = $_POST['dept'];
$did = $_POST['did'];
$dcode = $_POST['dcode'];
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$sql1="INSERT INTO prizemaster (`prizeid`, `name`, `class`, `department`, `amount`, `donorid`, `deptcode`) VALUES ('$_POST[pid]', '$_POST[pname]', '$_POST[class]', '$_POST[dept]', '$_POST[pamt]', '$_POST[did]', '$_POST[dcode]')";
if (!mysqli_query($con,$sql1))
  {
  die('Error: ' . mysqli_error($con));
  }
  else
  {
    header("location:adawdins_suc.php");
  }
  }
mysqli_close($con);

and i want the output like this:

say if the user enters "best project" in prize name then i want it like

if(pname=="Best Project")
{
pidtemp="ABC"+$pid;
}

and after this i will use pidtemp to insert in the database file!

Upvotes: 0

Views: 57

Answers (1)

MAK
MAK

Reputation: 775

if(pname=="Best Project")
{
pidtemp="ABC"+$pid;
}

replace above code with below

if($pname=="Best Project")
{

$pidtemp="ABC".$pid;
}

Upvotes: 1

Related Questions