Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Php Problem

asdfghmak

Novice
Advanced Member
Messages
33
Reaction score
0
Points
26
Patulong naman po. Pano mo pagsabayin ang dalawang query? insert tapos update po
 
Parang ganito ba?

$save=$sql->prepare(INSERT INTO table(id,value) VALUES(1,sample));
if($save->execute) {
$update=$sql->prepare(UPDATE table set value='sample ulit' where id=1);
if($update->execute) {
return "success";
}
else {
return "error update";
}
}
else {
return "error insert";
}
 
Last edited:
Parang ganito ba?

$save=$sql->prepare(INSERT INTO table(id,value) VALUES(1,sample));
if($save->execute) {
$update=$sql->prepare(UPDATE table set value='sample ulit' where id=1);
if($update->execute) {
return "success";
}
else {
return "error update";
}
}
else {
return "error insert";
}
dalawang query po ba ngagawa nyan?
 
uu. dalawa...

nag process sya ng insert once na magsuccess ang insert. magpa-process naman ng update.
 
Patulong naman po. Pano mo pagsabayin ang dalawang query? insert tapos update po

table test
id name

$sql="if(select count(*) as is_exist from test where id='$test_id' > 0 ,update test set name='$test_name',insert into test set name='$test_name' )";

Goodluck :)
 
uu. dalawa...

nag process sya ng insert once na magsuccess ang insert. magpa-process naman ng update.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shoeline_db";
$cat=$_POST["category"];
$name=$_POST["name"];
$price=$_POST["price"];
$qty=1;
echo $name;
echo $price;
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$save=$sql->prepare(INSERT INTO cart_tbl (category, item_name,item_price,quantity)
VALUES ('$cat', '$name' , '$price' , '$qty'));
if($save->execute) {
$update=$sql->prepare(UPDATE product_tbl set quantity=quantity-1 where id=1);
if($update->execute) {
return "success";
}
else {
return "error update";
}
}
else {
return "error insert";
}
$conn->close();
exit();

?>


sir may error sya
 
PDO kc yan si master xxx___p_e_r_t_o .. ausin ko sau lang ha..

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shoeline_db";
$cat=$_POST["category"];
$name=$_POST["name"];
$price=$_POST["price"];
$qty=1;
echo $name;
echo $price;
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$save= $conn->query(INSERT INTO cart_tbl (category, item_name,item_price,quantity)
VALUES ('$cat', '$name' , '$price' , '$qty'));
if($save)
{

$update=$conn->query(UPDATE product_tbl set quantity=quantity-1 where id=1);
if($update)
{
echo "<script> alert('success'); </script>";
}else{
echo "<script> alert(error update); </script>";
}

}else{
echo "<script> alert(error insert); </script>";
}

?>

kailangan aucin mo ito. dahil puro sa id=1 ang magbabawas nyan
 
Last edited:
PDO kc yan si master xxx___p_e_r_t_o .. ausin ko sau lang ha..

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shoeline_db";
$cat=$_POST["category"];
$name=$_POST["name"];
$price=$_POST["price"];
$qty=1;
echo $name;
echo $price;
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$save= $conn->query(INSERT INTO cart_tbl (category, item_name,item_price,quantity)
VALUES ('$cat', '$name' , '$price' , '$qty'));
if($save)
{

$update=$conn->query(UPDATE product_tbl set quantity=quantity-1 where id=1);
if($update)
{
echo "<script> alert('success'); </script>";
}else{
echo "<script> alert(error update); </script>";
}

}else{
echo "<script> alert(error insert); </script>";
}

?>

kailangan aucin mo ito. dahil puro sa id=1 ang magbabawas nyan


Parse error: syntax error, unexpected 'INTO' (T_STRING) in C:\Xammppp\Xampp\htdocs\ShoeLine PH\php\total.php on line 20

eto po error sir sorry beginner po
 
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shoeline_db";
$cat=$_POST["category"];
$name=$_POST["name"];
$price=$_POST["price"];
$qty=1;
echo $name;
echo $price;
$conn = new MySQLi($servername, $username, $password, $dbname);

// Check connection
if($conn->connect_errno)
{
die("Connection failed: " . $conn->connect_error);
}


$save = $conn->query(INSERT INTO cart_tbl (category, item_name, item_price, quantity)
VALUES ('$cat', '$name' , '$price' , '$qty'));
if($save)
{

$update = $conn->query(UPDATE product_tbl set quantity=quantity-1 where id=1);
if($update)
{
echo "<script> alert('success'); </script>";
}else{
echo "<script> alert(error update); </script>";
}

}else{
echo "<script> alert(error insert); </script>";
}

?>
 
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shoeline_db";
$cat=$_POST["category"];
$name=$_POST["name"];
$price=$_POST["price"];
$qty=1;
echo $name;
echo $price;
$conn = new MySQLi($servername, $username, $password, $dbname);

// Check connection
if($conn->connect_errno)
{
die("Connection failed: " . $conn->connect_error);
}


$save = $conn->query(INSERT INTO cart_tbl (category, item_name, item_price, quantity)
VALUES ('$cat', '$name' , '$price' , '$qty'));
if($save)
{

$update = $conn->query(UPDATE product_tbl set quantity=quantity-1 where id=1);
if($update)
{
echo "<script> alert('success'); </script>";
}else{
echo "<script> alert(error update); </script>";
}

}else{
echo "<script> alert(error insert); </script>";
}

?>
Okay na sir Gumagana na sya :) Thankyou Po :)
 
Last edited:
good! :D post ka lang kung meron pa.. hahahha
 
Back
Top Bottom