Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to edit/change the value of a specific column value with PHP. For example, let's say that I have thousands of records and I want to change every record's column value to 1. How would I do this in PHP?


$query=" SELECT * FROM url WHERE id='$id'";

while ($i < $num) {
share|improve this question

closed as off topic by Jeff Ferland, Mark Wagner, Shane Madden, womble, John Gardeniers Apr 4 '12 at 5:26

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Follow a PHP/MySQL tutorial. Use an update statement without a where clause. – Jeff Ferland Apr 4 '12 at 1:47
Really didn't help me, I've already looked for one. – Noah Brainey Apr 4 '12 at 1:52
Well, what have you done and where in the process are you stuck? – Jeff Ferland Apr 4 '12 at 1:54
Updated, I'm getting an error. mysql_numrows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\add.php on line 11 – Noah Brainey Apr 4 '12 at 1:55
Noah, please review your previous questions and accept correct answers where appropriate. – Kyle Smith Apr 4 '12 at 2:15

while ($i < $num) {

Don't close your connection before you fetch your results. You need to not have the mysql_close() until you're done with your database connection.

$query="UPDATE url SET someColumn = 1";
$result = mysql_query($query);

$result is a boolean (true / false) on update statements.

Finally, if you're taking user input anywhere, be aware that you've set yourself up for SQL injection. Read up on using mysqli and binding parameters. At this point, it's kind of the fault of PHP that this isn't what the tutorial is, but that's the way of the world.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.