Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9049909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:31:20+00:00 2026-06-16T12:31:20+00:00

Thanks for checking out my question. I am trying to only update a value

  • 0

Thanks for checking out my question. I am trying to only update a value in my database if that field is null (so existing users won’t be overwritten if someone tries to signup for a spot that is all ready taken and an error message will be output). I have listed below 2 of the most recent scripts I have tried. The first script works for updating the database if the select statement is not there but will overwrite users if entered for the same day and time. Thanks everybody!

$sql = ("SELECT `player1` FROM `users` where id = '$id' and Times = '$time'"); 


$result = $conn->query($sql);

if ($result->fetch_assoc === NULL) {
$update_player = ("UPDATE users SET player1 = '$name' where id = '$id' AND Times =   '$time'")

if($update_player){
echo "Date for $name inserted successfully!";
}
}

else {
  echo 'That spot is all ready taken!';
}

//2nd script 

$query=mysql_query("UPDATE users SET 
player1 = isNULL (player1, $name) 
where id = '$id' AND Times = '$time'" );

if($query){

 echo "Data for $name inserted successfully!";
}

else {
 echo 'That spot is all ready taken!';
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:31:21+00:00Added an answer on June 16, 2026 at 12:31 pm

    The following code should do the trick:

    $query=mysql_query("UPDATE users SET 
    player1='$name' 
    where id = '$id' AND Times = '$time' AND player1 IS NULL" );
    
    if(mysql_affected_rows() == 1){
      echo "Data for $name inserted successfully!";
    }
    else {
      echo 'That spot is all ready taken!';
    }
    

    Note that you should use pdo or mysqli functions instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for checking out this Question. I think I've just about scratched through my
Hello and thanks for checking out my question. <meta property=og:image content=http://www.myurl.com/images/test.png/> I have an
I'm trying to update the records whereby I found out that I will be
thanks for checking this question out. This is my first question here so any
Greetings everyone and thank you for checking out my post. I am trying to
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
I'm trying out the cocos2d-iphone javascript bindings so I can more easily port my
I was checking out the Google Maps Data API and I was wondering if
I am trying to write code that allows a select list to be populated
I'm finally getting around to checking out the latest EF release and I'm running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.