/    Sign up×
Community /Pin to ProfileBookmark

How can I update a SQL database table using PHP

Hello, please I need help with this, i’m new to PHP I’ve been trying to figure out for over a week, an I’ve still found no answers.

I want to send out emails to the subscribers of my eBook. I want to include a link in the email, so when the link is clicked, the subscribers database will be updated.

When this link is clicked, the subscribers are redirected to my homepage.

So i’m having trouble with everything, from start to finish.

This is the code I’ve written so far:

[CODE]<body>

<a href=”” target=”_blank”>Click Here To Say YES!</a>

<?php

mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“rmn”);

$sql = mysql_query(“UPDATE subscribe SET confirmaton =’YES’ WHERE email= [email]”);

?>
</body>

Thank you very much![/CODE]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Strider64Mar 07.2013 — Mysql has been depreciated I would either us Mysqli or PDO for security reasons (I am using mysqli).

Here's my connections screen to the database

[code=php]<?php
$db = new mysqli("localhost", "root", "******", "bhr_db");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}[/code]


Here's how I insert to the database (I'll explain a few things after the code).

[code=php] function insert_content($page, $user_date) {
global $db;

$stmt = $db->prepare("INSERT INTO pages (blog_name, content, new_blog_date, update_date) VALUES (?,?,?,?)");
$stmt->bind_param('ssss', $page['blog_name'], $page['content'], $user_date, $user_date);

/* execute prepared statement */
$stmt->execute();

/* close statement and connection */
$stmt->close();
}[/code]


I use prepare statements (prepare & bind_param) and this is in OPP format....go to PHP dot net for a procedural example if it will make more sense to you. Notice how the ? marks corresponds to all the fieldnames in the database in the prepare statement. Then on the next line it binds it to your prepare statement. The s (stands for string, i for integer...etc.) corresponds to how many variable you will be binding. Finally it is executed withe execute statement.

Doing something like this example will hopefully help you.


John
Copy linkTweet thisAlerts:
@Strider64Mar 07.2013 — I meant to write OOP ....
Copy linkTweet thisAlerts:
@Strider64Mar 07.2013 — Updating a database even even easier...

[code=php]function update_content($id, $page, $user_date) {

global $db;

// define sensible test values

// create a prepared statement
$update_stmt = $db->prepare('
UPDATE
pages
SET
blog_name =?,
content = ?,
update_date = ?
WHERE
id = ?
');

/* bind parameters for markers */
$update_stmt->bind_param('ssss', $page['blog_name'], $page['content'], $user_date, $id);

/* execute query */
$update_stmt->execute();

/* close statement */
$update_stmt->close();
} [/code]
Copy linkTweet thisAlerts:
@Strider64Mar 07.2013 — For some strange reason I re-read your question I don't think I answer your question properly.

Well, semi-partially.

I would do a user form instead....

something like this....

[code=html]<form action="example.php?page" method="post">
Username:<br />
<input type="text" name="username" value="" />
<br />
<br />
E-Mail:<br />
<input type="text" name="email" value="" />
<br />
<br />
Password:<br />
<input type="password" name="password" value="" />
<br />
<br />
<input type="submit" value="Register" />
</form>[/code]


then just have your code in the php file....

but to do it the way you want I'm sure someone else can answer you that part of the question...sorry about that....
×

Success!

Help @namo77 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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