Insert Data Into Table From Link.

Hello,

I have followed a tutorial and go it working correctly. It lets the user click 1 - 10 and rate the information present.

I want to change my code so that each time someone clicks the link to vote (rate) it will add that number to the database. (This is happening already) but I want to make it so that it also does not go back to the rating officer page but back to the main rating page, where all posts are shown.

So this line of code lets someone vote and then it reloads the same page. I want to go from the officer page back to the main page (copfeed.com/rating) when someone presses 1 - 10.

Each time I change the code it will not update the database.

What EXACTLY do i need to do with this line to make it work:
[php]<?php echo $rating; ?>[/php] Remember I want to go back to the ratings page…

Links:
copfeed.com/rating
http://copfeed.com/rating/officername.php?id=1

Thanks,
Bdenn

Probably nothing, you need to change rate.php so it redirects after inserting the data

Thanks JimL,

So here is the code for rate.php what would I need to edit. Sorry I no very very little about php.

[php]<?php

require_once ‘app/init.php’;

if(isset($_GET[‘officername’], $_GET[‘rating’])){

$officername = (int)$_GET[‘officername’];
$rating = (int)$_GET[‘rating’];

if(in_array($rating, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) {

$exists = $db->query("SELECT id FROM officers WHERE id = {$officername}")->num_rows ? true : false;

if($exists) {
    $db->query("INSERT INTO officers_ratings (officername, rating) VALUES ({$officername}, {$rating})");
}

}
header(‘Location: officername.php?id=’ . $officername);

}[/php]

I got it working from the rate.php page. I change:

[php]header(‘Location: officername.php?id=’ . $officername);[/php]

To:
[php]header(“Location: copfeed/rating/”);[/php]

works good and still updates the database.

Sponsor our Newsletter | Privacy Policy | Terms of Service