/    Sign up×
Community /Pin to ProfileBookmark

Saving values to database

Hello,

I have this problem how to save those values to database, for example $deposit = 75;? I know how to do it the other way for example
$deposit = $row_rsappointment[‘discount’];

Please see below a simple if elseif else statement, how do I save those appearing values to database?

<?php
if ($row_rsappointment[‘Bride1’] != $row_rsappointment[‘Bride2’]) {
echo $deposit = 75;

} elseif (($row_rsappointment[‘Bride1’] == 1) && ($row_rsappointment[‘Bride2’] == 1)) {
echo $deposit = 100;

}
else {
echo $deposit = 0;
}
?>

Cheers
Seb

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@Specht08Nov 30.2009 — which db? mysql? mysql_query("insert into tablename values(your values separated with a ',')");
Copy linkTweet thisAlerts:
@spacemocauthorNov 30.2009 — So it should be ?

dbdata mysql? mysql_query("insert into appointment values $deposit)");

Is that right ?

Cheers

Seb
Copy linkTweet thisAlerts:
@Specht08Nov 30.2009 — No, I don't know how the table structure looks like but but the exact code should be:
[CODE]mysql_query("insert into appointment (column name) values($deposit)");[/CODE]
Copy linkTweet thisAlerts:
@spacemocauthorNov 30.2009 — Can I use this in that combination please see below

<?php

if ($row_rsappointment['Bride1'] != $row_rsappointment['Bride2']) {

echo $deposit = 75;

mysql_query("insert into appointment (column name) values($deposit)");

} elseif (($row_rsappointment['Bride1'] == 1) && ($row_rsappointment['Bride2'] == 1)) {

echo $deposit = 100;

mysql_query("insert into appointment (column name) values($deposit)");

}

else {

echo $deposit = 0;

mysql_query("insert into appointment (column name) values($deposit)");

}

?>

CHeers

Seb
Copy linkTweet thisAlerts:
@Specht08Nov 30.2009 — Should work. Make sure you have a connection to the db.
Copy linkTweet thisAlerts:
@spacemocauthorNov 30.2009 — Okay I did this and doesnt work I am using a connection

<?php require_once('Connections/connection.php'); ?>

on the very top of the page with code

and then this one

<?php

if ($row_rsappointment['Bride1'] != $row_rsappointment['Bride2']) {

echo $deposit = 75;

mysql_query("insert into appointment (column name) values($deposit)");

} elseif (($row_rsappointment['Bride1'] == 1) && ($row_rsappointment['Bride2'] == 1)) {

echo $deposit = 100;

mysql_query("insert into appointment (column name) values($deposit)");

}

else {

echo $deposit = 0;

mysql_query("insert into appointment (column name) values($deposit)");

}

?>

Cheers

Seb
Copy linkTweet thisAlerts:
@SRobinsonNov 30.2009 — Your SQL statements need to acctually contain the field names that are in the database.

INSERT INTO table_name (column1, column2, column3,...)

VALUES (value1, value2, value3,...)

I.E

mysql_query("INSERT INTO t_cars ('color','make','wheels') VALUES ('red','bmw','yes')");

$color = 'red';

$make = 'bmw';

$wheels = 'yes'

mysql_query("INSERT INTO t_cars ('color','make','wheels') VALUES ($color,$make,$yes)");
Copy linkTweet thisAlerts:
@Specht08Nov 30.2009 — What error message do you get?
Copy linkTweet thisAlerts:
@spacemocauthorNov 30.2009 — The problem is that there is no error, query execut and nothing land in database. As you can see I have if elseif else statememnt so it's deppend which valuse will land in database but I don't think so this is a problem

as well I am getting those records by ID so meaby I need to grab ID and sign it to the insert statement, for example

mysql_query("insert into appointment (column name) values($deposit) WHERE id = $_GET[id]");

?

What do you think ?

Cheers

Seb
Copy linkTweet thisAlerts:
@Specht08Nov 30.2009 — you cant use where in combination with insert, what you mean is update, the part that says (column name) does it also say column name in your code? Because this can't work. You have to fill in the name of the column which should contain $deposit.

For update see the mysql manual.
Copy linkTweet thisAlerts:
@spacemocauthorDec 01.2009 — Hello,

I did like you advice me and still doesnt work nothing landing in database

please code below I think so everything is okay. But 75 still not landing in database

<?php
if ($row_rsappointment['Bride1'] != $row_rsappointment['Bride2']) {

echo $deposit = 75;

$con = mysql_connect("localhost","root","krasnal");
if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("database", $con);


mysql_query("UPDATE appointment SET DepositCost = '$deposit'

WHERE idAppointment = $_GET['idAppointment']");

mysql_close($con);

cheers

Seb
×

Success!

Help @spacemoc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...