PHP not pulling data from Database and being able to be edited.

I am writing PHP code for a database that (for this particular file) will pull up a particular item within the database with the fields first name, last name, and prayer request. The idea is that you select the item and can edit either the first name, last name, or prayer request if there was a typo, misspelled word, etc. We do have column within database called REG_ID which allows you to choose which entry you want to change. When I click the “Approve Prayer Request Button” literally nothing happens. I think it is a problem with my mySQL statements but I have tried numerous things and cannot get it to work. I am wanting everything to be done within this file. Any suggestions would be GREATLY appreciated.

This file is named Approve Deny Prayer Request.

<?php $DB_HOST = "XXXXXX"; $DB_NAME = "XXXXXX"; $DB_PASS = "XXXXXX"; $DB_USER = "XXXXX"; $link = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if($link->connect_errno > 0) { die('Connection failed [' . $db->connect_error . ']'); } $query = "SELECT * FROM Request"; $result = mysqli_query($link,$query); //<----- Added link $row = mysqli_fetch_array($result); if(isset($_POST['add'])){ $id = mysqli_real_escape_string($link,$_POST['REG_ID']); $firstname = mysqli_real_escape_string($link,$_POST['first']); $lastname = mysqli_real_escape_string($link,$_POST['last']); $phone = mysqli_real_escape_string($link,$_POST['phone']); $query2=mysqli_query($link,"UPDATE Request SET Reg_F_Name='$firstname', Reg_L_Name='$lastname',Reg_Request='$phone' WHERE id='$Reg_ID'" ); if($query2){ header("Location: fbcaltusprayerorg.ipagemysql.com"); } } // brace if(isset($_POST['add'])) ?> ">
First Name: ">
Last Name: ">
Prayer Request: ">

Even though I a little foggy in what you are trying to do, I’ll give you some advice:
First turn on error reporting:

[php]ini_set(‘display_errors’, 1);
error_reporting(E_ALL);[/php]

Second, don’t try to do everything at once, for example I have a cms for my website. I enter new data on a page that does nothing but insert that new page. If I made a mistake after I post it, I’ll just go to the edit page where I can edit that data and re-save it back to the database table via update. If I decide I no longer like that post I simply delete it, actually writing the code for delete page is the easiest of the three and maybe that is why it’s the most dangerous for it is easy to write.

First, create where you can insert data to the database table. Second, create where you can edit / update that inserted data and third have it where you can delete the row from the table if desired. You have three different mysqli / form with their own queries, but it will be simpler to manage the data.

For example this is how I store data for a registration page:
[php] // Store user’s credentials, if form data is validated:
if($displayStatus == ‘undetermined’) {
// Using prepared statements:
$query = “INSERT INTO users (username, password) VALUES (?,?)”;
$stmt = $mysqli->prepare($query);
$stmt->bind_param(‘ss’, $username, $password);
$displayStatus = ‘PASS’;
/* execute prepared statement /
$stmt->execute();
$displayStatus = ‘SUCCESS’;
$displayUsername = $username;
/
close statement and connection */
$stmt->close();
} [/php]

It does nothing but insert new data, but if I want to update that data I would read it in, edit and the update that data back to the table in a different script (Though I would never do that for a password, but that’s a different topic).

Lastly, you’re using mysqli, might as well take full advantage of it by using prepared statements, see php.net on that and other mysqli functions.

Sponsor our Newsletter | Privacy Policy | Terms of Service