PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] MySQL checking if string exist and updating or creating

 February 20, 2022     database, mysql, php, phpmyadmin     No comments   

Issue

i am trying to make an simple if exist check for MySQL via php and then i will create an String if not exist; or if an string exist, i will update and add to the value counter = counter + 1

But now i dont now why nothing happend :s

What i am doing wrong --- i had search for the problem but i didnt has find anything..

thanks ahead

heres the code

$rankset = '';
$steamid64 = "76561198070477917";
$localmap = "de_dolls";

mysql_connect("localhost", "######", "###############") or die(mysql_error());  
mysql_select_db("server") or die(mysql_error());

$check1 = mysql_query("SELECT * FROM `darkrp_missingmap` WHERE map = '$localmap'") or die(mysql_error());

while($info1 = mysql_fetch_array( $check1 )) 
{ 
  if(mysql_num_rows($info1) == 0) {
    print "existiert nicht wird erstellt...";
    mysql_query("SELECT server INSERT INTO darkrp_missingmap (map, count) VALUES ('$localmap', '1')");
  } 
  else {
    print "existiert wird aufgestuft...";
    mysql_query("SELECT server UPDATE darkrp_missingmap SET count = count + 1 WHERE map = '$localmap'");
  }
} 

Solution

You can try this, you can ref [this]

$check1 = mysql_query("SELECT * FROM `darkrp_missingmap` WHERE map = '$localmap'") or die(mysql_error());
$nums = mysql_num_rows($check1);

if($nums == 0) {
 // do something
}

Or you can use this sql.

SELECT COUNT(*) AS count FROM `darkrp_missingmap` WHERE map = '$localmap'

And get this query's result count.

$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$nums = $row[0]['count'];


Answered By - lighter
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing