Jump to content

Inserting multiple values for one user in new column

Go to solution Solved by kicken,

Recommended Posts

Hello. It's been a while since I've been here and I hope everyone is doing well. 
My task that I'm taking on is adding a value to all entries based on username. I added the new column and need to add that in for a different project. But I haven't started the other one yet because I need to get this done first.
I tried to google this and I keep getting results that aren't what I need (IE How to insert multiple rows, or how to replace values in phpmyadmin, etc)

To be more specific, lets say user "joe" has 200 entries.
Joe is a user that has a reqid that is the number 75
Now I've added the column "reqid"
I need to add the number 75 in the column reqid, to all the entries made be Joe

The column is INT(255)

Note: Each user has a different name, and I already have a working way to add the reqid to the database from this point on. So what I need to do is edit all the past entries before today with their reqid's

I don't have anything that I have tried because I'm running in circles on what to do. If anyone has an example script that will get me in the right direction, or a link where I can see how this is done, I would appreciate it so very much.

Note 2: Ultimately I would like to make a form where I can just search a name and add that in for all of that users entries, but if this can be done in phpmyadmin in a batch update that will work too (the search doesn't seem to allow to replace just one user to change (example 0 to 75)

Link to comment
Share on other sites

19 minutes ago, kicken said:
update users_table

This looks like what I need. So below is what I made, though all of the colums with the name JOE still shows  zero. I'll add a screen shot
Note: Joe was just an example. In the screen shot below, I'm attempting to update all that has the name "MetalHead" with "75"

ini_set('display_errors', '1');

	$servername = "removed for posting";
	$username = "removed for posting";
	$password = "removed for posting";
	$dbname = "removed for posting";

$sql = "SELECT * FROM nametable";

$sql= "UPDATE nametable SET reqid= '75' WHERE name='MetalHead' ";


The screen shot of the DB

EDIT: No errors are showing on the screen

Edited by PNewCode
Link to comment
Share on other sites

@kicken WOW I can't believe I didn't make the DBconnection hahaha. Okay, so with your answer and adding the DB connection it works. Thanky you so much!


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);

$sql = "UPDATE nametable SET reqid='75' WHERE name='MetalHead'";

if ($conn->query($sql) === TRUE) {
  echo "Record updated successfully";
} else {
  echo "Error updating record: " . $conn->error;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.