AJAX code to save id value in database - javascript

I want to pass this value doctoridclickedRightNow into t_appointmentdetails table. I have made few changes to previous code using AJAX and JS as suggested on How to Pass variable from JavaScript to PHP Page using XMLHTTP . Appointment details are getting inserted into DB and I also want the doctorid of the corresponding doctor to be saved. So with the below changes I am able see the correct values being displayed when I use inspect element in mozilla. Kindly suggest me how to pass this to DB. Thanks in advance.
$sql = "SELECT doctorid, FIRST_NAME,LAST_NAME, Address, Qualification, Specialization, Consultation_Fee, Experience,image_path
from t_doctorprofile";
$results = mysqli_query($db,$sql)
or die('MySQL Error');
echo '<h3 style="color:#674172;margin- left:120px;float:center;display:inline-block"><strong>Available Dentists</strong></h3>';
while($result = mysqli_fetch_assoc($results)){
echo '<div class= "fetch" style="margin-left:120px">';
echo "<img src = 'uploads/".$result['image_path']."' width='150' height='150'>";
echo "<div id='info'>";
echo "<p><strong>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</strong></p></div>";
echo "<p>".$result['Qualification']."</p>";
echo "<p>".$result['Specialization']."</p>";
echo "<p>".$result['Address']."</p>";
echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"." </p>";
echo "<button class='btn btn-success btn-lg' id='$result[doctorid]' data-toggle='modal' data-target='#myModal' onclick='AssignDoctorIdClicked(id)'>
Appointment</button>";
echo "<script>var doctoridclickedRightNow;</script>";
echo "</div>";
echo '<form action="appointment_insert.php" method="POST">';
echo "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content' style='background-color:#F1A9A0'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
echo "<h4 class='modal-title' id='myModalLabel' style='text-align:center; color:#fff'>
<strong>Book Appointment</strong></h4><br>";
echo "</div><br><br>";
echo "<div class='modal-body'>";
script for AssignDoctorIdClicked function:
<script>
function AssignDoctorIdClicked(id) {
console.log(id);
var doctoridclickedRightNow = id;
console.log(doctoridclickedRightNow);
</script>
appointment_insert.php page
if (isset($_POST["submit"])) {
$login_user = $_SESSION['username'];
$datetime = $_POST['datetime'];
$info = $_POST['info'];
$recieved_1 = $_GET['FIRST_NAME'];
$query = mysqli_query($db, "INSERT INTO t_appointmentdetails (patient_name,datetime,info) VALUES ('$login_user','$datetime','$info');");
$insertedDataBoolean = true;
if($insertedDataBoolean){
echo "Name: " . $recieved_1 . " booked successfully.";
}
else{
echo "Data-insertion error.";
}
}

Related

Add Check Box to each product and use the selected Check boxes values on another page

The product list will be populated from MySql Database using PHP code and is having a check box for each product.
On that page, whenever a check box is clicked, I need that product to be highlighted and store its value to some other array type variable to pass that value to another page.
Code for product list creation:
<?php
$cnt=0;
$rslt = mysqli_query($conn,"SELECT Icode,Name,Size,Style FROM productinfo");
if(!$rslt){
die(mysqli_error($conn));
}else{
echo "<table width='100%'>";
while($row = mysqli_fetch_assoc($rslt)){
if($cnt==0){
echo "<tr>";
}
echo "<td width='30%'>
<div class='card'>
<img src='upload/"."download.jpg"."' alt='Avatar' style='width:100px' >
<div class='container'>
<h4><b>".$row['Name']." <input type='checkbox' name=".$row['Icode']." value=".$row['Icode']." onclick=' echo return OptionsSelected(this)'/> </b></h4>
<p>".$row['Size']."</p>
<p>".$row['Icode']."</p>
</div>";
?>
<!-- <button role="button" data-toggle="modal" data-id="<?php print $row['Icode']?>" onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Inquiry</button>
</div>
<?php
echo "</td>";
if($cnt==2){
$cnt=0;
echo "</tr>";
}
else
$cnt = $cnt + 1;
}
}
echo "</table>";
?>

$_GET not working on my php file [duplicate]

This question already has answers here:
The 3 different equals
(5 answers)
Closed 6 years ago.
I have a url link that has value of the id and process when clicked.
code:
<?php
<a href='settoActive.php?id=".$row['id']."&process=actives' style='font-size:15px;' name='active' value=".$row['id']." class='btn btn-info' />ACTIVE</a>
?>
<a href='settoActive.php?id=".$row['id']."&process=inactive' style='font-size:15px;' name='active' value=".$row['id']." class='btn btn-info' />inactive</a>
and this is where the page will be redirected to:
<?php
$value = $_GET['process'];
echo "<script> alert(".$value.");</script> ";
if($_GET['proc']="actives"){
$id = $_GET['id'];
$mysqli = new mysqli('10.237.2.152','root','c0k3float','monitoring');
$results = $mysqli->query("UPDATE Shipment_Target SET status='Active' where id=".$id." ") or mysqli0;
echo "<script>alert('Activessss!'); </script>";
//location.replace('addmodel.php')
}
if($_GET['process']="inactive"){
$id = $_GET['id'];
$mysqli = new mysqli('10.237.2.152','root','c0k3float','monitoring');
$results = $mysqli->query("UPDATE Shipment_Target SET status='Inactive' where id=".$id." ") or mysqli0;
echo "<script>alert('Inactive!'); </script>";
}
// location.replace('addmodel.php')
?>
The problem is the 2 if condition trigger and why it is triggering at the same time?
There are 3 mistakes noticed... 2 places '==' operator and 1 place GET variable name 'process'.
$value = $_GET['process'];
echo "<script> alert(".$value.");</script> ";
if($_GET['process']=="actives"){
$id = $_GET['id'];
$mysqli = new mysqli('10.237.2.152','root','c0k3float','monitoring');
$results = $mysqli->query("UPDATE Shipment_Target SET status='Active' where id=".$id." ") or mysqli0;
echo "<script>alert('Activessss!'); </script>";
//location.replace('addmodel.php')
}
if($_GET['process']=="inactive"){
$id = $_GET['id'];
$mysqli = new mysqli('10.237.2.152','root','c0k3float','monitoring');
$results = $mysqli->query("UPDATE Shipment_Target SET status='Inactive' where id=".$id." ") or mysqli0;
echo "<script>alert('Inactive!'); </script>";
}
// location.replace('addmodel.php')
?>
Problem in the html code, try following code
<a href='settoActive.php?id=<?php echo $row['id']; ?>&process=actives' style='font-size:15px;' name='active' value="<?php echo $row['id']; ?>" class='btn btn-info' />ACTIVE</a>
<a href='settoActive.php?id=<?php echo $row['id']; ?>&process=inactive' style='font-size:15px;' name='active' value="<?php echo $row['id']; ?>" class='btn btn-info' />inactive</a>

Place a list inside an session and display each session

Im trying to create a shopping cart style website. I'm able to display the products through setting the products as a class and passing that through to my shopping cart page. However, I need to save the list of products into a session so I can add and or clear each item added to the cart.
Products.php
<?php
require_once 'class_product.php';
$product = new product();
$product_id =(int)$_GET['product_id']; //get id from home page
$username = "";
$password = "";
$hostname = "";//blanked this out for public use
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("poti",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM products where product_id=$product_id");
echo '<form name="form1" method="post" action="cart.php" target="bottom_right">';
echo '<table class="Grocery-table">';
while($row = mysql_fetch_array($result))
{
$product->setProductId($row['product_id']);
$product->setProductName($row['product_name']);
$product->setStock($row['in_stock']);
$product->setUnitPrice($row['unit_price']);
$product->setUnitQuantity($row['unit_quantity']);
}
$_SESSION['product'] = serialize($product);
echo "<tr><td><b>Product ID</b></td>";
echo "<td>";
echo $product->getProductId();
echo "</td></tr>";
echo "<tr><td><b>Product Name</b></td>";
echo "<td>";
echo $product->getProductName();
echo "</td></tr>";
echo "<tr><td><b>Unit Price</b></td>";
echo "<td>";
echo $product->getUnitPrice();
echo "</td></tr>";
echo "<tr><td><b>Unit Quantity</b></td>";
echo "<td>";
echo $product->getUnitQuantity();
echo "</td></tr>";
echo "<tr><td><b>In Stock</b></td>";
echo "<td>";
echo $product->getStock();
echo "</td></tr>";
echo '<tr><td><b>Add</b></td><td><Input type="number" min="0" id="add_value" name="cart"></input>
<Input type="hidden" id="stock_value" name="stock_value" value ='.trim($product->getStock()).'></input></td></tr>';
echo '<tr><td></td><td><input type="submit" value="Submit" onclick="return numCheck()"></td></tr>';
echo "</table>";
echo "</form>";
?>
cart.php
<?php
session_start();
?>
<html>
<style type="text/css">
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Grocery Store</title>
</head>
<body>
<h2>Cart</h2>
<?php
require_once 'class_product.php';
$product = unserialize($_SESSION['product']);
//this allows me to see the information when i click submit
echo $product->getProductName();
echo $product->getProductId();
echo $product->getStock();
echo $product->getUnitPrice();
echo $_POST['cart'];
?>
</body>
</html>
How do i place the following $product->getProductName() etc into a Session that enables me to display all the products i've added to my cart.
Try this,
session_start();
$_SESSION['ProductName'] = $product->getProductName();
$_SESSION['ProductId'] = $product->getProductId();
$_SESSION['Stock'] = $product->getStock();
$_SESSION['UnitPrice'] = $product->getUnitPrice();
For multiple products, you may have to use an array of session.
<?php
session_start();
if(!isSet($_SESSION['cart_items']))
{
$_SESSION['cart_items'] = array();
}
$items =$product->getProductName()."|".$product->getProductId()."|".$product-
>getStock()."|".$product->getUnitPrice();
array_push($_SESSION['cart_items'],$items);
echo $_SESSION['cart_items'][0]; //First Product
echo "<br>";
echo $_SESSION['cart_items'][1]; //Second Product
?>

How to echo out multiple lines of HTML Code?

<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'
'<a target="_blank" class="mosaic-overlay">'
'<div class="details">'
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'
'<p class="font_us1">technische Umsetzung</p>'
'</div>'
'</a>'
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'
'</div>';
}
mysql_close();
?>
So I wanted to output the usernames of my database with some javascript effect, but it doesn't show. How do I have to echo this out?
echo 'foo
bar
baz';
No need to close the quote on each newline. Better though, simply go out of PHP mode:
<?php while ($row = mysql_fetch_array($result)) { ?>
<div>
...
<?php echo $row['user_name']; ?>
...
</div>
<?php } ?>
Even better yet for readability (IMO):
<?php while ($row = mysql_fetch_array($result)) : ?>
...
<?php endwhile; ?>
You should use pdo or mysqli.
You did not concat your string.
<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'.
'<a target="_blank" class="mosaic-overlay">'.
'<div class="details">'.
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'.
'<p class="font_us1">technische Umsetzung</p>'.
'</div>'.
'</a>'.
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'.
'</div>';
}
mysql_close();
?>

Colorbox working for the first time .. but not the second time .. I get a.removeEventListener is not a function

Ok , so i am using colorbox to pop up windows of dynamic data generated by PHP .. Below is my php code ... when I click on the link , the windows pop up with the data .... but if I click on the same link again , the window doesn't get the information and I get this in the console a.removeEventListener is not a function , for the second time on clicking on the link for the colorbox to show .. 1st time works .. what could be going wrong ?
jQuery(document).ready(function() {
var id_form;
var url;
$("a.madcomment").click(function(e) {
e.preventDefault();
id_form = $(this).attr('id');
url ="#madcomment_menu"+id_form;
$("a.madcomment").colorbox({inline:true, width:"350px", href:url});
});
});
<?php
$select = "SELECT * FROM COMMENTS INNER JOIN Twitter_Data ON Twitter_Data.screen_name=Comments.Twitter WHERE Category ='Comments'";
$result = mysql_query($select);
$result_count = mysql_num_rows($result);
echo " <table border =\"0\">";
echo "<tr>";
$user_array = array();
$counter = 0;
if($result_count > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div id ='scoring_scale' class='madscore".$row['ID']."' style='display:none;'>";
echo "<div id='madcomment_menu".$row['ID']."' style='padding:10px; background:#fff;'>";
echo "<a id='".$row['ID']."' class='green_circle' href='#'> +3 </a>";
echo "<a id='".$row['ID']."' class='orange_circle' href='#'> +1 </a>";
echo "<a id='".$row['ID']."' class='red_circle' href='#'> -1 </a>";
echo "<a id='".$row['ID']."' class='brown_circle' href='#'> -3 </a><br />";
echo"<form>";
echo "<textarea id='text".$row['ID']."'rows='5' cols='33'>";
echo "-";
echo "</textarea>";
echo"<button id='button".$row['ID']."'class='button_madscore'> MadComment </button>";
echo "</form>";
echo "</div>";
echo "</div>";
}
}
// Here is the link that will generate the COLORBOX pop-up
echo "<a id='".$row['ID']."'class=' madcomment' href='madcomment_menu".$row['ID']."'><img src='images/madcomment.png' /> </a>";
?>
You are binding your colorbox each time on anchor click so in order to prevent this replace you colorbox code with below :
$.fn.colorbox({inline:true, width:"350px", href:url});
This will fix your issue.

Categories