Sinisterly
Help with Updating database from PHP? - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: Help with Updating database from PHP? (/Thread-Help-with-Updating-database-from-PHP)

Pages: 1 2 3


RE: Help with Updating database from PHP? - mudrig - 07-27-2016

(07-27-2016, 09:06 PM)Ex094 Wrote: Oh jeez, I think we got it. You forgot to add the Value attribute to the OPTION tags hence it's returning gamer_tag null I think

Replace this line:
Code:
echo "<option>" . $row['user_name'] . "</option>";

With this:
Code:
echo "<option value='" . $row['user_name'] .  "'>" . $row['user_name'] . "</option>";

Also just in case to make sure inputs are coming correctly, Echo out all the POST variables like:
Code:
echo $gamertag; echo $rank; echo $tag; echo $order;

Okay so it is doing it correctly by pulling in the values

Its outputting like tis

New records created successfully test Recruit [DSxR] 27

but it is still not updating it in the database


RE: Help with Updating database from PHP? - Ex094 - 07-27-2016

Then it might be that the mysql account you are using to query changes to the database does not have the UPDATE privilege, Try running the query in PHPMyAdmin, then see if the change gets applied there, it might be the permission problem

EDIT: I see your order field is an INT,

Try this line:
Code:
$stmt->bind_param("ssds", $_POST['select_rank'], $_POST['select_tag'], $_POST['select_order'], $_POST['select_gamertag']);

I hope you noticed, I made a mistake in my previous query that I provided for the bind_param, I accidentally added SELECT_ORDER twice and SELECT_GAMERTAG got neglected. I think that might be why it's not updating:
Code:
$stmt->bind_param("ssss", $_POST['select_rank'], $_POST['select_tag'], $_POST['select_order'], $_POST['select_gamertag']);



RE: Help with Updating database from PHP? - mudrig - 07-27-2016

Ive never ran a query threw PHPMyAdmin . How could I run a statement with out having the form and all in it?


RE: Help with Updating database from PHP? - Ex094 - 07-27-2016

(07-27-2016, 09:50 PM)mudrig Wrote: Ive never ran a query threw PHPMyAdmin . How could I run a statement with out having the form and all in it?

First try out what I just said in the EDIT on my previous post, might as well work


RE: Help with Updating database from PHP? - mudrig - 07-27-2016

(07-27-2016, 09:34 PM)Ex094 Wrote: Then it might be that the mysql account you are using to query changes to the database does not have the UPDATE privilege, Try running the query in PHPMyAdmin, then see if the change gets applied there, it might be the permission problem

EDIT: I see your order field is an INT,

Try this line:
Code:
$stmt->bind_param("ssds", $_POST['select_rank'], $_POST['select_tag'], $_POST['select_order'], $_POST['select_gamertag']);

I hope you noticed, I made a mistake in my previous query that I provided for the bind_param, I accidentally added SELECT_ORDER twice and SELECT_GAMERTAG got neglected. I think that might be why it's not updating:
Code:
$stmt->bind_param("ssss", $_POST['select_rank'], $_POST['select_tag'], $_POST['select_order'], $_POST['select_gamertag']);

(07-27-2016, 09:55 PM)Ex094 Wrote:
(07-27-2016, 09:50 PM)mudrig Wrote: Ive never ran a query threw PHPMyAdmin . How could I run a statement with out having the form and all in it?

First try out what I just said in the EDIT on my previous post, might as well work

Okay I changed it to that and now im getting this
No data supplied for parameters in prepared statement test Recruit [DSxP] 26


RE: Help with Updating database from PHP? - Ex094 - 07-27-2016

(07-27-2016, 10:01 PM)mudrig Wrote: Okay I changed it to that and now im getting this
No data supplied for parameters in prepared statement test Recruit [DSxP] 26
Did you try both?


RE: Help with Updating database from PHP? - mudrig - 07-27-2016

(07-27-2016, 10:05 PM)Ex094 Wrote:
(07-27-2016, 10:01 PM)mudrig Wrote: Okay I changed it to that and now im getting this
No data supplied for parameters in prepared statement test Recruit [DSxP] 26
Did you try both?

Yes I tried both and got the same thing on each.

its almost like no data is being supplied to this now

Code:
$stmt = $conn->prepare("UPDATE users SET user_rank =?, user_tag =?, list_order =? WHERE user_name = '$gamertag'");



RE: Help with Updating database from PHP? - Ex094 - 07-27-2016

Here's the complete shebang, run this:

HTML:
Code:
<form method='post' action='user_rank_change.php'> <!-- Gamertag Select --> <h3 for='select_gamertag' >Select GamerTag</h3> <select class="form-control" id='select_gamertag' type='text' name='select_gamertag'> <? while($row = mysqli_fetch_array($result6)) { echo "<option value='" . $row['user_name'] .  "'>" . $row['user_name'] . "</option>"; } ?> </select> <!-- Select Rank --> <h3 for='select_rank' >Type rank as it is shown below</h3> <input id='select_rank' type='text' name='select_rank' class="form-control" placeholder="Example: Recruit"> <!-- Select Tag --> <h3 for='select_tag' >Type tag as it is shown below</h3> <input id='select_tag' type='text' name='select_tag' class="form-control" placeholder="Example: [DSxR]"> <!-- Select Order --> <h3 for='select_order' >Type order as it is shown below</h3> <input id='select_order' type='text' name='select_order' class="form-control" placeholder="Example: 27"> <!-- Submit Form --> <button type="submit" class="btn btn-default">Change Rank</button> </form>

PHP:
Code:
// set parameters $gamertag = $_POST['select_gamertag']; $rank = $_POST['select_rank']; $tag = $_POST['select_tag']; $order = $_POST['select_order']; //Check if all params recieved echo $rank . " " . $tag . " " . $order . " " . $gamertag; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) {    die("Connection failed: " . $conn->connect_error); } // prepare and bind $stmt = $conn->prepare("UPDATE users SET user_rank =?, user_tag =?, list_order =? WHERE user_name =?"); $stmt->bind_param("ssss", $rank, $tag, $order, $gamertag); if(!$stmt->execute()) {     echo $stmt->error; } else {    echo "New records created successfully"; } $stmt->close(); $conn->close(); ?>

If this doesn't work, I can help you over team viewer later. need to get some shut eye


RE: Help with Updating database from PHP? - mudrig - 07-28-2016

Alright thanks for all the help I'll try this when I get home and let you know how it goes.


RE: Help with Updating database from PHP? - mudrig - 07-28-2016

That worked. Looks like I just had the parameters backwards on that.

Now one more question since you have been so helpful. How would I make this form after submitted go back to same page and Display above form the result from the action of the form submit.