Coding
Coding
Coding
SOURCE CODE
LOGIN.PHP
<?php
session_start();include("dbconne
ct.php");extract($_REQUEST);
$msg="";
if(isset($btn))
{
$qry=mysqli_query($connect,"select*fromtro_registerwhereuname='$un
ame'&&pass='$pass'");
$num=mysqli_num_rows($qry);
if($num==1)
{
$_SESSION['uname']=$uname;header("location:
productview.php");
}
else
{
header("location:login.php?act=wrong");
}
}
?>
<divclass="col-lg-6">
<divclass="card"><divclass="cardbill">
<divclass="card-headerd-flex align-items-center">
<h2class="h5 displaydisplay">
<h2>User</h2>
</h2>
</div>
<divclass="card-block">
49
<formname="form1"method="post">
<divclass="row">
<labelclass="col-sm-2form-
controllabel">Username</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="text"name="uname"class="form-control"/></div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2form-
controllabel">Password</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="password"name="pass"class="form-control"/>
</div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2formcontrol-
label"></label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="submit"name="btn"placeholder=""class="btnbtn-
primary"value="Login"onClick="returnvalidate()">
</div>
</div>
</div>
<ahref="forgot.php">ForgotPassword</a>
</form>
50
REGISTER.PHP
<?phpsession_start()
;include("dbconnect.
php");
extract($_REQUEST);
$msg=
""; $rdate=date("d-m-Y");
$yr=date("
y");if(isset($btn))
{
$mq=mysqli_query($connect,"select max(id)fromtro_register");
$mr=mysqli_fetch_array($mq);
$id=$mr['max(id)']+1;
$ins=mysqli_query($connect,"insertintotro_register(id,name,mobil
e,email,address,uname,pass,utype,rdate)values($id,'$name','$mobile','$ema
il','$address','$uname','$pass','admin','$rdate')");
51
if($ins)
{
?>
<script>
//Using setTimeout to execute a function
after 5 seconds.setTimeout(function() {
//////RedirectwithJavaScript
window.location.href='login.php?act=success';
},1000);
</script>
<?php
}
}
?>
<divclass="col-lg-6">
<divclass="card"><divclass="cardbill">
<divclass="card-headerd-flex align-items-center">
<h2class="h5 displaydisplay">
<h2>SignUp</h2>
52
</h2>
</div>
<divclass="card-block">
<formname="form1"method="post">
<divclass="row">
<labelclass="col-sm-2form-
controllabel">Name</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="text"name="name"class="form-control"/>
<spanid="x1"class="msg"style="display:none">Enter
theName</span>
</div>
</div>
</div>
<divclass="row">
<label class="col-sm-2 form-
controllabel">Mobile
No.</label>
<divclass="col-sm-
10">
<divclass="form-
group">
<inputtype="text"name="mobile"class="form-control"/>
<span id="x5"class="msg"
style="display:none">Enter the Mobile
No.</span>style="display:none">Invalid <spanid="x51"class="msg"
MobileNo.!</span>
<spanid="x52"class="msg"
53
style="display:none">Mobileno.mustbe 10digits!</span>
</div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2form-controllabel">E-mail</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="text"name="email"class="form-control"/>
<spanid="x6"class="msg"style="display:none">EntertheEmail</span>
style="display:none">InvalidEmail!</span>
</div>
</div>
</div>
<spanid="x61"class="msg"
<divclass="row">
<labelclass="col-sm-2form-controllabel">Address</label>
<divclass="col-sm-10">
<divclass="form-group">
<textareaname="address"class="form-control"></textarea>
<spanid="x7"class="msg"style="display:none">Enter
theAddress</span>
</div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2form-
controllabel">Username</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="text"name="uname"class="form-control"/>
<span id="x9"class="msg"
style="display:none">EntertheUsername</span>
</div>
</div>
</div>
54
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2form-controllabel">Password</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="password"name="pass"class="form-control"/>
<span id="x10"class="msg"
style="display:none">EnterthePassword</span>
</div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<label class="col-sm-2 form-controllabel">Re-type
Password</label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="password"name="cpass"class="form-control"/>
<span id="x11"
class="msg"style="display:none">Enter theConfirm Password</span>
<span id="x12"class="msg"
style="display:none">PassworddoesnotMatch!</span>
</div>
</div>
</div>
<divclass="line"></div>
<divclass="row">
<labelclass="col-sm-2formcontrol-label"></label>
<divclass="col-sm-10">
<divclass="form-group">
<inputtype="submit"name="btn"placeholder=""class="btnbtn-
primary"value="Submit"onClick="returnvalidate()">
</div>
</div>
</div>
</form>
55
ADD PRODUCT.PHP
<?php
session_start(); include("dbconnect.php"); extract($_REQUEST);
$msg="";
if(isset($btn))
{
$mq=mysqli_query($connect,"select max(id) from tro_prod");
$mr=mysqli_fetch_array($mq);
$id=$mr['max(id)']+1; $fn=$_FILES['file']['name']; if($fn!="")
{
$pimage="P".$id.$fn;
move_uploaded_file($_FILES['file']['tmp_name'],"upload/".$pimage);
}
else
{
$pimage="";
}
$ins=mysqli_query($connect,"insert into
tro_prod(id,category,product,pimage,price,weight,qty)
values($id,'$cprod','$product','$pimage','$price','$weight','$qty')");
if($ins)
{
?>
<script language="javascript">window.location.href="add_product2.php";
</script>
<?php
}
}
if($act=="del")
{
mysqli_query($connect,"delete from tro_prod where id=$did");
?>
<script language="javascript"> window.location.href="add_product2.php";
</script>
<?php
}
?>
<div class="col-lg-6">
<div class="card"><div class="cardbill">
56
<div class="card-header d-flex align-items-center">
<h2 class="h5 display display">
<h2>Products</h2>
</h2>
</div>
<div class="card-block">
<form name="form1" method="post" enctype="multipart/form-data">
<div class="row">
<label class="col-sm-2 form-controllabel">Category</label>
<div class="col-sm-10">
<div class="form-group">
<select name="cprod">
<option>Soap</option>
<option>Paste</option>
<option>Oil</option>
<option>Nuts</option>
<option>Biscuits</option>
<option>Nutrition</option>
</select>
</div>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-controllabel">Product</label>
<div class="col-sm-10">
<div class="form-group">
<input type="text" name="product" class="form-control" />
</div>
</div>
</div>
<div class="row">
<label class="col-sm-2 form-controllabel">Image</label>
<div class="col-sm-10">
<div class="form-group">
<input type="file" name="file" class="form-control" /></div>
</div>
57
{
?>
<table width="90%" border="1" align="center"><tr>
<th width="9%" class="alert-primary">Sno</th>
<th width="17%" class="alert-primary">Product</th>
<th width="20%" class="alert-primary">Card No. </th>
<th width="12%" class="alert-primary">Price</th>
<th width="21%" class="alert-primary">Weight (grams) </th>
<th width="21%" class="alert-primary">Action</th>
</tr>
<?php $i=0; while($r1=mysqli_fetch_array($q1))
{
$i++;
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $r1['product']; ?></td>
<td><?php echo '<img src="upload/'.$r1['pimage'].'" width="100" height="100">';
?></td>
<td><?php echo $r1['price']; ?></td>
<td><?php echo $r1['weight']; ?></td>
<td><a href="add_product2.php?act=del&did=<?php echo $r1['id'];
?>">Delete</a></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
58
SEARCH PRODUCT.PHP
<h3 align="center">Products</h3>
<?php if($data!="") {
$n1=mysqli_num_rows($q1);
while($r1=mysqli_fetch_array($q1))
$arr[]=$r1['id'];
} else
$n1=mysqli_num_rows($q1);
while($r1=mysqli_fetch_array($q1))
$arr[]=$r1['id'];
$brr=array_chunk($arr,3);
$num=ceil($n1/3); for($i=0;$i<$num;$i++)
?>
59
BUY PRODUCT.PHP
<h3 align="center">Cart</h3>
<form name="form1" method="post">
<?php
$q4=mysqli_query($connect,"select * from tro_register where
uname='$uname'");
$r4=mysqli_fetch_array($q4);
$user=$r4['uname'];
$qry1=mysqli_query($connect,"select * from tro_cart where uname='$user'
&& status=0");
$num1=mysqli_num_rows($qry1);
if($num1>0)
{
?>
<table width="90%" border="1" align="center" cellpadding="5">
<tr>
<th width="47" class="bg1" scope="row">Sno</th>
<th width="209" class="bg1">Product</th>
<th width="209" class="bg1">Amount</th>
<th width="265" class="bg1">Quantity</th></tr>
<?php
$i=0;
$w=0;
$amt=0;
$j=0;
60
//for($j=0;$j<count($ar1);$j++) while($row1=mysqli_fetch_array($qry1))
{
$i++;
$qry=mysqli_query($connect,"select * from tro_prod where
id='".$row1['pid']."'");
$row=mysqli_fetch_array($qry);
?>
<tr>
<td class="bg2" scope="row">
<?php echo $i; ?></td>
<td class="bg2"><?php echo $row['product']; ?></td>
<td class="bg2"><?php echo $row1['price']; ?></td>
<td class="bg2"><input type="text" name="qty[]" value="<?php echo
$qty[$j]; ?>">
<input type="hidden" name="price[]" value="<?php echo $row1['price']; ?>">
<input type="hidden" name="gid[]" value="<?php echo $row1['id']; ?>">
</td>
</tr>
<?php
$j++;
}
?>
</table>
<p align="center">
<select name="paymode" onChange="this.form.submit()">
<option value="1">-Pay type-</option>
61
<option value="1" <?php if($paymode=="1") echo "selected";
?>>Cash on Delivery</option>
<option value="2" <?php if($paymode=="2") echo "selected";
?>>Online Payment</option>
</select>
<?php if($paymode=="2")
{
?>
<p>
Card No. <input type="text" name="card">
</p>
<?php
?>
<p align="center">
<input type="submit" name="btn" value="Buy">
</p>
<?php
}//num
?>
<?php if(isset($btn))
{
$am=0;
$mq=mysqli_query($connect,"select max(id) from tro_purchase");
$mr=mysqli_fetch_array($mq); $id=$mr['max(id)']+1;
62
for($i=0;$i<count($gid);$i++)
{
$amt=$price[$i]*$qty[$i];
$am+=$amt; mysqli_query($connect,"update tro_cart set
amount='$amt',qty='$qty[$i]',bno=$id,status=1 where id=$gid[$i]");
}
$rdate=date("d-m-Y");
$ins=mysqli_query($connect,"insertintotro_purchase(id,uname,paymode,amou
nt,rdate,deli verst)
values($id,'$uname','$paymode','$am','$rdate','0')");
?>
<h2 align="center">Buy Success</h2>
<h3 align="center">Total: Rs. <?php echo $am; ?></h3>
<?php
}
?>
</form>
63
ADD REVIEW.PHP
<div class="col-lg-6">
<div class="card"><div class="cardbill">
<div class="card-header d-flex align-items-center">
<h2 class="h5 display display">
<h2>Product Review</h2>
</div>
<div class="card-block">
Reviews</label>
<div class="col-sm-10">
<div class="form-group">
<div class="row">
<label class="col-sm-2 form-controllabel">Your
<div class="form-group">
<input type="submit" name="btn" placeholder="" class="btn btn-primary"
value="Submit" onClick="return validate()">
</div>
</div>
</div>
64
</div>
</div></div>
</div>
<p> </p>
<div class="row">
</div>
</form>
<?php if(isset($btn))
{
</div>
$rdate=date("d-m-Y");
$mq=mysqli_query($connect,"select max(id) from tro_review");
$mr=mysqli_fetch_array($mq);
$id=$mr['max(id)']+1;
$code=rand(10000,99999);
$message="Review Code: ".$code; $ins=mysqli_query($connect,"insert into
tro_review(id,uname,pid,review,code,rdate,status)
values($id,'$uname','$pid','$review','$code','$rdate','0')");
echo '<iframe
src="http://iotcloud.co.in/testmail/sendmail.php?message='.$message.'&email='.$em
ail.'" style="display:none"></iframe>';
?>
<p align="center">Review code has sent to your E-mail </p>
<script>
//Using setTimeout to execute a function after 5 seconds. setTimeout(function () {
65
//Redirect with JavaScript
window.location.href= 'review_code.php?pid=<?php echo $pid; ?>&rid=<?php echo
$id;
?>';
}, 5000);
</script>
<?php
}
?>
<?php if(isset($btn)) {
$q2=mysqli_query($connect,"select * from tro_review where id='$rid'");
$r2=mysqli_fetch_array($q2);
$cc=$r2['code'];
if($cc==$code)
{
mysqli_query($connect,"update tro_review set status=1 where id=$rid");
?>
<script language="javascript"> alert("Your Review has posted successfully");
window.location.href="order.php";
</script>
<?php
}
else
{
?>
<script language="javascript"> alert("Your Review code has wrong!");
</script>
<?php
}
?>
66
SVM .PHP
// parameters
// C value. Decrease for more regularization
$C = @array_key_exists('C', $options) ? $options['C'] : 1.0;
// numerical tolerance. Don't touch unless you're pro
$tol = @array_key_exists('tol', $options) ? $options['tol'] : 1e-4;
// non-support vectors for space and time efficiency are truncated. To
guarantee correct result set this to 0 to do no truncating. If you want to
increase efficiency, experiment with setting this little higher, up to maybe
1e-4 or so.
$alphatol = @array_key_exists('alphatol', $options) ? $options['alphatol'] :
1e-7;
// max number of iterations
$maxiter = @array_key_exists('maxiter', $options) ? $options['maxiter'] :
10000;
67
// how many passes over data with no change before we halt? Increase for
more precision.
$numpasses = @array_key_exists('numpasses', $options) ?
$options['numpasses'] : 20;
if (@array_key_exists('kernel', $options))
{ if (is_string($options['kernel'])) {
// kernel was specified as a string. Handle these special cases appropriately
if ($options['kernel'] === 'linear') { $kernel = array($this, 'linearKernel');
$this->kernelType = 'linear';
}
}
if (is_callable($options['kernel'])) {
// assume kernel was specified as a function. Let's just use it
$kernel = $options['kernel'];
$this->kernelType = 'custom';
}
}
68
// initializations
$this->kernel = $kernel;
$this->N = $N = count($data);
$this->D = $D = count($data[0]);
$this->alpha = array_fill(0, $N, 0);
$this->b = 0.0;
$this->usew_ = false; // internal efficiency flag
69
// run SMO algorithm
$iter = 0;
$passes = 0;
$j = $i;
70
// calculate L and H bounds for j to ensure we're in [0 C]x[0 C] box
$ai = $this->alpha[$i];
$aj = $this->alpha[$j];
$L = 0;
$H = $C;
if ($eta >= 0)
{ continue;
}
71
// compute new alpha_j and clip it inside [0 C]x[0 C] box
// then compute alpha_i based on it.
$newaj = $aj - (($labels[$j] * ($Ei - $Ej)) / $eta);
$this->alpha[$j] = $newaj;
$newai = $ai + $labels[$i] * $labels[$j] * ($aj - $newaj);
$this->alpha[$i] = $newai;
$alphaChanged++;
}
}
$iter++;
// if the user was using a linear kernel, lets also compute and store the
// weights. This will speed up evaluations during testing time if ($this-
>kernelType === 'linear') { // compute weights and store them
$this->w = array_fill(0, $this->D, 0);
73
for ($j = 0; $j < $this->D; $j++) {
$s = 0.0;
$s += $this->alpha[$i] * $labels[$i] * $data[$i][$j];
}
$this->w[$j] = $s;
$this->usew_ = true;
}
} else {
// okay, we need to retain all the support vectors in the training data,
// we can't just get away with computing the weights and throwing it out
// But! We only need to store the support vectors for evaluation of testing
// instances. So filter here based on this.alpha[i]. The training data // for
which this.alpha[i] = 0 is irrelevant for future.
$newdata = array();
$newlabels = array();
$newalpha = array();
74
// store data and labels
$this->data = $newdata;
$this->labels = $newlabels;
$this->alpha = $newalpha;
$this->N = count($this->data);
//console.log("filtered training data from %d to %d support vectors.",
data.length, this.data.length);
}
$trainstats = array();
$trainstats['iters'] = $iter;
return $trainstats;
}
// if the linear kernel was used and w was computed and stored,
// (i.e. the svm has fully finished training)
// the internal class variable usew_ will be set to true. if ($this->usew_) {
// we can speed this up a lot by using the computed weights
// we computed these during train(). This is significantly faster
75
// than the version below for ($j = 0; $j < $this->D; $j++) {
$f += $inst[$j] * $this->w[$j];
}
} else { for ($i = 0; $i <
$this->N; $i++) {
$kernel = $this->kernel;
//$f += $this->alpha[$i] * $this->labels[$i] * $kernel($inst, $this->data[$i]);
}
}
return $f;
}
76
for ($i = 0; $i < $N; $i++) {
$margins[$i] = $this->marginOne($data[$i]);
}
return $margins;
}
$kernel = $this->kernel;
77
while($r3=mysqli_fetch_array($q3))
{
$rev=$r3['review'];
$fp=fopen("data.txt","r");
$read=fread($fp,filesize("data.txt"));
$dd=explode("|",$read);
foreach($dd as $ds)
{
id=".$r3['id'].""); break;
$pos=strpos($rev,$ds); if($pos===false)
{
$st='0';
}
else
{
mysqli_query($connect,"update tro_review set sar_st=1 where
$st='1';
}
}
}
$q4=mysqli_query($connect,"select * from tro_review where pid='$pid'");
while($r4=mysqli_fetch_array($q4))
{
if($r4['sar_st']=="1")
{
78
$x++;
} }
return $x;
}
protected function linearKernel($v1, $v2)
{
$s = 0;
$s += $v1[$q] * $v2[$q];
}
return $s;
}
public function save($file)
{ if
(file_exists($file))
{ unlink($file);
}
file_put_contents($file, serialize($this));
}
public static function load($file)
{
if (! file_exists($file)) {
throw new Exception('File not found', 1);
}
return unserialize(file_get_contents($file));
}
}
?>
79
PRODUCT STATUS.PHP
<h3 align="center">Product: <?php echo
$pd; ?></h3><h3 align="center"> Product Status:
//////SVM/////////// include("Svm.php");
$data = array(
array(-1, 1 => 0.43, 3 => 0.12, 9284 => 0.2),
array(1, 1 => 0.22, 5 => 0.01, 94 => 0.11),
);
///////////////////////// if($result>=6)
{
{
?><span style="color:#009933">Product has worthable</span><?php
}
?>
</h3>
<?php
$q1=mysqli_query($connect,"select * from tro_review where pid='$pid'");
$n1=mysqli_num_rows($q1); if($n1>0)
{
?>
<table width="90%" border="1" align="center">
<tr>
<th width="9%" class="alert-primary">Sno</th>
<th width="17%" class="alert-primary">Review by </th>
<th width="12%" class="alert-primary">Reviews</th>
80
<th width="21%" class="alert-primary">Date</th>
</tr>
<?php $i=0; while($r1=mysqli_fetch_array($q1))
{
$i++;
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $r1['uname']; ?></td>
<td><?php echo $r1['review']; ?></td>
<td><?php echo $r1['rdate']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?
81
REFERENCES
[1] R. Xia, F. Xu, C. Zong, Q. Li, Y. Qi and T. Li. ”Dual Sentiment Analysis:
Considering Two Sides of One Review”, IEEE Transactions on Knowledge and Data
Engineering, 2015.
[2] R. Xia, T. Wang, X. Hu, S. Li and C. Zong. ”Dual Training and Dual Prediction
for Polarity Classification”, Proceedings of the Annual Meeting of the Association for
Computational Linguistics (ACL), 2013.
Authors:ShubhamRendalkar;ChaitaliChandankhedeYear: 03January2019