Verify string in PHP from URL [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have a Wordpress site and a front end posting form on it.
When form is submitted, the user gets link to his email with unique string (example 432879374982) saved as a custom field and post gets status "pending":
http://www.mysite.com/verify.php?verify=432879374982
I now want to change status to "published" when user click on a link.
I know that I should use GET parameter, and check if the string is saved in database, and publish the post where there is a match in db, but dont know how to code this.
EDIT:
Made it working!
In the landing page- on wordpress I created a page named "verify" and in template (php) I included code from #Bora- only the database connection has to be established before and it changes the status of a post.
Status has to be set as "publish", not "published"

Try something like following codes:
$verify = $mysqli->real_escape_string($_GET['verify']); // escape GET var
$query = "SELECT * FROM table WHERE code = '$verify'"; // Build query
if ($result = $mysqli->query($query)) { // Check return query
while ($row = $result->fetch_assoc()) { // Fetch Row
$query = "UPDATE table SET status = 'published' WHERE code = '$verify'"; // Update query
$mysqli->query($query); // Run query
}
$result->close(); // free result set
}

Related

Make the page do nothing if $_GET is empty [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am trying to get my page to update a DB when there is $_GET data.
However even when www.myurl.com?status= is blank the page updates the DB with nothing.
Here is my code
$status=$_GET["status"];
$sql="UPDATE users SET status =$status WHERE personID='$user'" or die(mysql_error());
mysql_query($sql);
Can anyone help? I am trying to get the page to do nothing if the URL is just www.myurl.com
if(!empty($_GET['status']) { // Check if `status` is not empty
$sql="UPDATE users SET status = $_GET['status'] WHERE personID='$user'";
mysql_query($sql); // Continue with sql query
}
empty - http://us2.php.net/empty
isset - http://us2.php.net/isset
Make use of empty() in PHP to achieve this.
if(!empty($_GET["status"])) //<--- Control to the inside will be passed only if the status variable is not empty
{
$status=$_GET["status"];
$sql="UPDATE users SET status =$status WHERE personID='$user'" or die(mysql_error());
mysql_query($sql);
}
That was the first thing. Secondly you are using an obsolete deprecated API i.e. the mysql_* functions. You need to switch over to PreparedStatements.

How can I get the ID of the inserted record? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I had tried to find last inserted id in php, but I am unable to get.
It displays value 0.
This is my code:
require_once "../config.php";
$query = "call experience_insert('$uid','$title','$cname','$sdate','$edt')";
$result = $connection->ServerDb->query($query);
$id = $connection->ServerDb->insert_id;
You should post the relevant sections of the stored procedure you're calling. It should have a return statement that gives back the ID. Keep in mind there are weird gotchas with MySQL stored procedures and last_insert_id() as well.
http://dev.mysql.com/doc/refman/5.7/en/stored-routines-last-insert-id.html

Update database via link [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am busy with an employee record project and would like to know if it is possible at all to have my project update the database via links?
Let me explain.
Within the editing of an employee I would like to add a menu with a couple of links. These links will only be used by our employers. The will (if the above mentioned is possible) be able to click on the link "dismissed", then that should update the database by means of changing the field "Employed_Status" to "0".
I could really use the help from professionals as I am still at the "Very beginner" stage. Thanks in advance.
Use $_GET like
if(isset($_GET['status']) and $_GET['status']=='dismiss' and isset($_GET['empId']))
{
$sql="Update employee SET Employed_Status=0
WHERE Emp_id=".(int)$_GET['empId'];// if empid is integer
// or use WHERE Emp_id=".mysql_real_escape_string($_GET['empId']);
// execute query $sql
}
calling link like, http://example.com/page.php?empId=1&status=dismiss
Edit Page:
Dismissed
Activate
action.php
$val=$_REQUEST['val'];
$sql = "UPDATE employee SET status = ? WHERE id = ?";
$q = $conn->prepare($sql);
$q->execute(array($val,$empid));
You can do this by transferring values from query string to tha page
<td><a href="insert.php?id=?"<?php echo (int) $_GET['id'] ?> >insert</a></td>
and on insert.php
extract this values using get method as:
$id = $_GET["id"];
Also extract other values in similar manner and then fire your insert query with these values.

how do i display id on page using php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
On THIS PAGE, I have the word "category =" before my campaigns.
My problem is: I am unable to find the code that can display the page id as shown in the url.
How can I get this to echo the page id as shown in the URL? to say "category = FREE".
can someone please help me.
thank you.
echo "category = ", htmlspecialchars($_GET['id']);
Any URL parameter can be retrieved using $_GET["param_name"], in your case: $_GET["id"]. You can save that as a variable, or echo it right away.

php - data entry and order issue [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Im having a little trouble with a php script ive made.
you can see all the relevant info at http://click-media.co.uk/Client/Lisa/Admin/admin.php (password: "hey")
I basically need the classes to be ordered by day/time when a new class is created, either by changing the column names in the database to a timestamp or something or by making a new column to and ordering it by this.. then using the php to switch the order values when the admin clicks "moveup"/"move down" next to the row.
any help would be much appreciated.
Thanks
You can implement this by doing the following:
Add a column in the database and call it class_order
Your SQL query should have ORDER BY class_order
Moving up UPDATE table set class_order = THE_ORDER_OF_THE_CLASS_ABOVE WHERE id = TARGET_CLASS and UPDATE table set class_order = TARGET_CLASS_ORDER WHERE id = THE_CLASS_ABOVE
Moving down is the opposite of moving up

Categories