Not able to figure out why my ajax code is not sending the data to the php file. have tried many things but it doesn't seem to work.
can anybody help me out here please.
My html code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ABC Fashion</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert((this).id);
var id=(this).id;
var params ={id : (this).id};
$.post("code.php", params);
alert(1);
});
});
</script>
</head>
<body>
<div id="main_container">
<div class="center_content" align="center">
<div class="center_title_bar" align="center">Latest Products</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T1.jpg" name="tshirt" alt="" border="0" id="T1"/></div>
<div class="product_img"><button id="d1" onclick="">Dislike</button></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T2.jpg" name="tshirt" alt="" border="0" id="T2"/></div>
<div class="product_img"><div class="product_img"><button id="d2" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T3.jpg" name="tshirt" alt="" border="0" id="T3"/></div>
<div class="product_img"><div class="product_img"><button id="d3" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T4.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d4" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T5.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d5" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T6.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d6" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T7.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d7" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T8.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d8" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T9.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d9" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T10.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d10" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T11.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d11" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T12.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d12" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
</div>
</body>
</html>
and my php code is as follows:
<?php
$servername = "localhost:3306";
$username = "admin";
$password = "password";
$dbname = "testdb";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_error($conn));
}
$num= (int)$_POST["params"];
$str = $num;
$tempid = substr_replace($str,"T",0);
echo $str;
$sql = "INSERT INTO `test` (`disliked`) VALUES ('$num')";
if (mysqli_query($conn, $sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
You have in your code var params ={id : (this).id}; which is wrong. Should be var params ={id : $(this)[0].id}; (And change all instances of (this).id to $(this)[0].id)
And you're passing the id parameter, so on the server side, change $_POST["params"]; to $_POST["id"];
$num= $_POST["params"]; // REMOVE(int) casting, you're doing it on the next line
Related
This is my coding line. the
<?php include '../includes/amazon-cart.php' ?>
is not responsive.
<section class="bg-secondary py-4">
<div class="container">
<div class="row no-gutters">
<div class="col-lg-5">
<img src="https://cdn.truegcloud.com/cholibrium/oto1/cholibrium-up3ds-3-bottles.png" alt="" class="img-fluid d-block mx-auto pb-4 pb-md-0" type="image">
</div>
<div class="col-lg-7">
<h2 class="text-blue text-center">
<b>New Customers Only
<br class="d-none d-md-block">- Price Per Bottle:
<span style="opacity:25%; font-weight: 600;">
<br class="d-none d-lg-block">
<s>$99</s>
</span> $27
</b>
</h2>
<h3 class="text-success text-center" style="font-size:35px;">
<b><u>Savings: $216</u></b>
</h3>
<?php include '../includes/amazon-cart.php' ?>
<form id="buy-form" action="/go/order.php" method="get">
<input type="hidden" name="pid" value="<?php echo ${$funnel.'_SKU'}; ?>">
<button type="submit"
name="submit-test"
value="1"
class="submit-order-btn btn-lg btn-yellow1 p-4 p-relative"
alt="Submit Form"
>
<h3 class="submit-texts m-0"><b>ADD TO ORDER</b></h3>
<div class="loader-wrap">
<span class="loader" style="top: 20%; left: 40%;"></span>
</div>
</button>
<?php if(!isset($_COOKIE['pp_preference']) && isset($_COOKIE['vault'])){ ?>
<p class="text-pink text-center" style="margin-top: 15px !important;text-transform: none;font-weight: 300;font-size: 15px !important;">By clicking "Add To Order" button, your card will automatically be charged.</p>
<?php } ?>
</form>
<div class="row align-items-center justify-content-around">
<div class="col-6">
<img src="https://cdn.truegcloud.com/epishieldplus/up1dssl-4b.png" alt="" class="img-fluid align-self-center d-block mx-auto" type="image">
</div>
<div class="col-6">
<img src="https://cdn.truegcloud.com/epishieldplus/up1dssl-2b.png" alt="" class="img-fluid align-self-center d-block mx-auto" type="image">
</div>
</div>
</div>
</div>
</div>
</section>
but now it became like this
It supposed to be like this
i have 3 image field like this
<?php echo $row['thumbnail1']; ?>
<?php echo $row['thumbnail2']; ?>
<?php echo $row['thumbnail3']; ?>
if there only one exp thumbnail1 is have image..
how to show
and how if only image 1 and 2 have data..
please help how to show php query if there only 1 or 2 and 3 image upload
this css style
<div class="col-xs-12">
<img src="#" class="w-full">
</div>
<!-- IF only 2 image available uploaded USE this -->
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<!-- IF only ALL/3 image available uploaded USE this -->
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
</div>
dsa sdas
Replace your old code with this (Someone edited So i have Re writtent the code again) :
<?php
if(isset($row['thumbnail1']))
{
?>
<div class="col-xs-12">
<img src="#" class="w-full">
</div>
<?php } ?>
<!-- IF only 2 image available uploaded USE this -->
<?php
if(isset($row['thumbnail2']))
{
?>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<?php } ?>
<!-- IF only ALL/3 image available uploaded USE this -->
<?php
if(isset($row['thumbnail3']))
{
?>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<div class="col-xs-4">
<img src="#" class="w-full">
</div>
<?php } ?>
Give me the update, if you have tested.
Code for index.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include ('recherchecommande.php') ;
?>
<title>Pâtisserie Baya</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="styles/960.css" />
<link rel="stylesheet" type="text/css" media="all" href="styles/reset.css" />
<link rel="stylesheet" type="text/css" media="all" href="styles/text.css" />
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<link rel="stylesheet" type="text/css" media="all" href="themes/brown/style.css" />
<link rel="stylesheet" type="text/css" media="all" href="styles/sample.css" />
<link rel="stylesheet" type="text/css" media="all" href="styles/table.css" />
<script type="text/javascript" src="scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="scripts/jquery.tools.min.js"></script>
<script type="text/javascript" src="scripts/dapur.js"></script>
</head>
<body>
<div id="warp" >
<div id="main" class="container_16">
<div id="header" class="grid_16">
<div id="logo" class="grid_4 alpha">
<h1>DapurKue</h1>
<h2>Famously Delicious</h2>
</div>
<div id="headright" class="grid_7 prefix_5 omega">
<h3 class="login">Sign up / Login</h3>
<p><span class="vChart">View Cart</span> <span class="cOut">Checkout</span></p>
</div>
</div>
<div id="mainMenu" class="grid_16">
<ul>
<li>Home</li>
<li>Cakes</li>
<li>Order & Delivery</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
<li>Reclamation</li>
</ul>
</div>
<div id="stickySearch" class="grid_16">
<div class="stickyNews grid_12 alpha">
<p>Valentine’s BrownieCheese Special Package. <em>Free Delivery.</em> More »</p>
</div>
<div class="search grid_4 omega">
<form action="#" method="get">
<input type="text" value="Type your keyword" id="s" name="s" onFocus="if (this.value == 'Type your keyword') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Type your keyword';}" />
</form>
</div>
</div>
<div class="products grid_16">
<div class="productsWarp" id="style1"><img src="images\email.png"></div>
<div id="style2" /> </div>
<div id ="style3">
<h3>Recherche par numero de commande</h3>
<p> Searcch button</p>
<form action="recherchecommande.php?go" id="commandeForm" method="post">
<input placeholder="Numero de commande.." id="form2" type="text" name="numero">
<input type="submit" name="submit" style="display: none" /><br>
</form>
</div>
<div id="style1"></div>
</div>
<div class="productThumb ">
<ul>
<li class="grid_2 alpha"><img src="images/cake1.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake2.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake3.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake4.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake5.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake6.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2"><img src="images/cake7.jpg" alt="" width="100" height="60" /></li>
<li class="grid_2 omega"><img src="images/cake8.jpg" alt="" width="100" height="60" /></li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
<div id="fresh">
<div class="container_16">
<div id="freshCake" class="grid_16">
<div class="grid_1 alpha"> <a class="prevButton">«</a></div>
<div class="headLine grid_14">
<h3>Fresh from the oven</h3>
</div>
<div class="grid_1 omega"> <a class="nextButton">»</a></div>
</div>
<div class="newCakes">
<div class="scroller">
<div class="newCake"><img src="images/freshCake1.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake2.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake3.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake4.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake5.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake6.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake7.jpg" alt="" width="220" height="120" /></div>
<div class="newCake"><img src="images/freshCake8.jpg" alt="" width="220" height="120" /></div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<div id="richContent">
<div class="container_16">
<div class="popularCakes grid_4">
<h4>Popular Cakes</h4>
<ul>
<li>Ultimate Choco Brownie</li>
<li>Mokakokoa Brownie</li>
<li>CoffeeBrown</li>
<li>Delicacheese</li>
<li>Berries Cheesecake</li>
</ul>
</div>
<div class="recommended grid_4">
<h4>Recommended</h4>
<ul>
<li>Ultimate Choco Brownie</li>
<li>Mokakokoa Brownie</li>
<li>CoffeeBrown</li>
<li>Delicacheese</li>
<li>Berries Cheesecake</li>
</ul>
</div>
<div class="specialOffer grid_4">
<h4>Special Offer</h4>
<ul>
<li>Ultimate Choco Brownie</li>
<li>Mokakokoa Brownie</li>
<li>CoffeeBrown</li>
<li>Delicacheese</li>
<li>Berries Cheesecake</li>
</ul>
</div>
<div class="orderPhone grid_4">
<h4><em>Order by Phone</em> <span>20.321.331</span></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div id="richContent2">
<div class="container_16">
<div class="fromBlog grid_4">
<h4>From the blog</h4>
<h5>New Recipes in Our Basket</h5>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. vivamus tempor justo sit amet metus cursus consequat. Nulla viverra, felis vel accumsan fermentum... more »</p>
</div>
<div class="corporateInfo grid_4">
<h4>Corporate Info</h4>
<ul>
<li>Privacy Policy</li>
<li>Term & Conditions</li>
<li>Franchise</li>
<li>About us</li>
<li>FAQ</li>
</ul>
</div>
<div class="storeDelivery grid_4">
<h4>Store & Delivery</h4>
<ul>
<li>Store Locator</li>
<li>Delivery Terms & Pricing</li>
<li>Delivery Coverage</li>
<li>Gift Services</li>
<li>Track my order</li>
</ul>
</div>
<div class="socialNet grid_4">
<h4>Keep in touch</h4>
<ul>
<li>Facebook</li>
<li>Twitter</li>
<li>Feed</li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
<div id="footer">
<div class="container_16">
<div class="copyright grid_16">
<p class="left">Copyright © 2016, Athenas, All Rights Reserved</p>
<p class="right">Design by Tokokoo & instantShift</p>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
</body>
</html>
Code for search.php
<?php
include ('connect.php') ;
$mysqli = new mysqli("localhost", "root", "", "baya");
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$cmd=$_POST['numero'];
$sql="SELECT * from commande WHERE commande_id LIKE ".$cmd."";
$result=mysqli_query($db,$sql);
$number=$result->num_rows ;
echo "
" ;
if ($number==1)
{
while($row=mysqli_fetch_assoc($result))
{
$commande_id =$row['commande_id'];
$description=$row['description'];
$status=$row['status'];
$report=$row['report'] ;
echo "
<table border=1>
<thead>
<tr>
<th>commande_id</th>
<th>description</th>
<th>status</th>
<th>report</th>
</tr>
</thead>
<tr>
<td>$commande_id</td>
<td>$description</td>
<td>$status</td>
<td>$report</td>
</tr>
";
header('location reclamation.html') ;
}
}
else{
echo "<p>Command id n'existe pas</p>";
}
}
}
else{
echo "search query is empty" ;
}
?>
I want to show the query in the same page not another one
For example if i type 1 it should returns this query from database
not to show the result in another page ..
Is it possible to show the result at the bottom of the Search button with
the same style sheet !
Thank you everybody for helping !
Best regards
change your form action attribute like this
<form action="" mehtode="post">
and write the php code on the same page to process the data send.
<?php
if(isset($_POST['submit'])){
//process the form
//output
// etc....
}
?>
Please post the code sample. So we can have a look at it.
You can use other php file with includes with the same css and html structure of you other php, or you can use Ajax with javascript for get the data and then show it.
$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
I have a html form with code shown below in which i have used ajax to send the id of the clicked button to the php page, but i am not getting any value to the php page, it is sending null.
I am a beginner in this and have studied via tutorials, can anybody point out the mistake i am doing?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ABC Fashion</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert((this).id);
var id=(this).id;
$.post("code.php", id);
});
});
</script>
</head>
<body>
<div id="main_container">
<div class="center_content" align="center">
<div class="center_title_bar" align="center">Latest Products</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T1.jpg" name="tshirt" alt="" border="0" id="T1"/></div>
<div class="product_img"><button id="d1" onclick="">Dislike</button></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T2.jpg" name="tshirt" alt="" border="0" id="T2"/></div>
<div class="product_img"><div class="product_img"><button id="d2" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T3.jpg" name="tshirt" alt="" border="0" id="T3"/></div>
<div class="product_img"><div class="product_img"><button id="d3" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T4.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d4" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T5.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d5" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T6.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d6" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T7.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d7" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T8.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d8" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T9.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d9" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Levi's Men's Cotton T-Shirt</div>
<div class="product_img"><img src="images/T10.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d10" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">UB Stylish T-shirt</div>
<div class="product_img"><img src="images/T11.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d11" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title">Jacob n John T-Shirt</div>
<div class="product_img"><img src="images/T12.jpg" alt="" border="0" /></div>
<div class="product_img"><div class="product_img"><button id="d12" onclick="">Dislike</button></div></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab"> <img src="images/cart.gif" alt="" border="0" class="left_bt" /> <img src="images/favs.gif" alt="" border="0" class="left_bt" /> <img src="images/favorites.gif" alt="" border="0" class="left_bt" /> details </div>
</div>
</div>
</body>
</html>
My php code is as follows:
<?php
$servername = "localhost";
$username = "admin";
$password = "pwd";
$dbname = "testdb";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_error($conn));
}
$num= (int)$_POST[id];
$str = $num;
$tempid = substr_replace($str,"T",0);
echo $tempid;
$sql = "INSERT INTO `test` (`disliked`) VALUES ('$num')";
if (mysqli_query($conn, $sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
The issue is in the $.post call, you're passing the value of id with no identifier.
Change this:
$.post("code.php", id);
to this:
$.post("code.php", {id: id});
Remember we need to send
Key=>value pair.
You are directly passing value in your Ajax post method so key is missing and you are trying to access using key.
Var params = {id:id};//first Id is key : second id is value.
$.post("code.php", params);
replace the $.post("code.php", id); with
var request = $.ajax({
url: "code.php",
type: "POST",
data: {id:id},
dataType: "html"
});
request.done(function(msg){
alert(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
i will very thankful if someone could help me figure out why there is an error on line 37,i tried to change the location of the ""; after echo but nothing worked.... i also tried to put the whole php code in img class="profilePic" src="http://i.imgur.com/ZICYW5z.png"/> then to use echo for the name (i want it to change image and name on login.)
code:
<?php
require ('steamauth/steamauth.php');
# You would uncomment the line beneath to make it refresh the data every time the page is loaded
// $_SESSION['steam_uptodate'] = false;
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./css/stylesheet.css" media="screen" title="no title" charset="utf-8">
<script src="./js/jquery-2.1.4.min.js" charset="utf-8"></script>
<title>CSGOSuprise.party</title>
<style>
html
{ background-image: url("images/background.jpg"); }
</style>
<body ondragstart="return false" onselectstart="return false">
<div class="header">
<ul>
<li class="logo">CSGOSuprise</li>
<?php
if(!isset($_SESSION['steamid'])) {
steamlogin();
} else {
include ('steamauth/userInfo.php');
?>
<li>Help</li>
</ul>
</div>
</head>
<body ondragstart="return false" onselectstart="return false">
<div class="container">
<div class="leftMain">
<div class="profile">
<div class="profileTop">
<?php echo '<img class="profilePic" src=.$steamprofile['avatarfull'].'; ?>
<?php echo '' . $steamprofile['personaname'] . ''; ?>
<div class="medals">
<img src="./images/medals/italy_small.png" alt="" />
<img src="./images/medals/dust2_small.png" alt="" />
<img src="./images/medals/victory_small.png" alt="" />
<img src="./images/medals/inferno_small.png" alt="" />
</div>
<div class="rankXP">
<img class="rankXPImage" src="./images/ranks/xp/level39.png" alt="" />
<span class="rankXPCurrent">Rank 39</span>
<span class="rankXPNext">Rank 40</span>
<progress id="xp" value="95" max="100"></progress>
</div>
</div>
<div class="rankComp">
<img class="rankCompImage" src="./images/ranks/comp/14.png" alt="" />
<div class="rankCompText">Distinguished Master Guardian</div>
<div class="wins">
<img class="rankTrophy" src="./images/trophy.png"/>
<span class="winNumber">232</span>
</div>
</div>
</div>
<div class="friendsMain">
<div class="friendsTop">
<span>Friends</span>
</div>
<div class="friendsList">
<div class="friendOnline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOnline">8</div>
</div>
<div class="friendOnline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOnline">7</div>
</div>
<div class="friendOnline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOnline">4</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">6</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">5</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">4</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">3</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">2</div>
</div>
<div class="friendOffline">
<img class="profilePicSmall" src="http://i.imgur.com/ZICYW5z.png" alt="" />
<div class="friendNameOffline">1</div>
</div>
</div>
</div>
</div>
<div class="rightMain">
<div class="main"></div>
</div>
</div>
<script src="./js/script.js" charset="utf-8"></script>
</body>
</html>
I think instead of
<?php echo '<img class="profilePic" src=.$steamprofile['avatarfull'].'; ?>
you mean
<?php echo '<img class="profilePic" src="' . $steamprofile['avatarfull'] . '">'; ?>
But you could also do
<img class="profilePic" src="<?= $steamprofile['avatarfull'] ?>">