PHP SQL判断字符串是否存在

想写一个PHP的用户系统作为软件后台, 注册时怎么判断帐号是否已经存在? 用的mysql_num_rows 但是只能判断纯英文或纯数字。 求答案

$search = "SELECT * FROM 表名 WHERE user = {$user}";
$res = mysql_query($search);
if($res && mysql_num_rows($res)>0){




'SELECT * FROM 表名 WHERE user = "{$user}"'

Csdn user default icon
如何在一个 SQL Select 中查找行?包括带空格和不带空格的字符串

<div class="post-text" itemprop="text"> <p>我在 PHP 中有一个 SQL Select 查询,在这个查询中,我需要在一个表中查找行,其中一个列类似于带空格和不带空格的字符串。</p> <p>例如,如果我在数据库中的值是 ABC 123,搜索 ABC123 后会显示:</p> <pre><code>$sql = SELECT * from table where col_name LIKE '%ABC123%' ";</code></pre> <p>但是我需要它返回 col name 等于 ABC 123 的行,反之亦然。例如,如果数据库值为123ABC,那搜索123ABC就应该显示:</p> <pre><code>$sql = SELECT * from table where col_name LIKE '%123 ABC%' "; </code></pre> <p>我需要它返回 colname 等于的那一行。</p> </div>


A表里面有个字段aa和id,aa是一个数组字符串 id:1 aa:1 id:2 aa:1,2 id:3 aa:2 id:4 aa:1,2,3 等等 我会只等一个数例如 1 查询A表aa字段中包括1 我用like方法查询会出现错误 请问where后面怎么写才能获得正确的结果 我用的ThinkPHP写的程序

SQL select命令使用带逗号分隔ID的字符串

<div class="post-text" itemprop="text"> <p>I have a string in PHP like:</p> <pre><code>"1234,2345,4567,5676,234,12,78957"..... </code></pre> <p>I want to extract these numbers in varchar(30) format and use them on a command like</p> <pre><code>SELECT * FROM TABLE_NUM WHERE ID LIKE '%NUM'; </code></pre> <p>where NUM will have above mentioned 7 strings. </p> <p>And if possible i would also like to restrict '%' in '%NUM' to 1-5 characters only i.e. the prefix should not be greater than 5 characters. Example NUM = 1234 and ID has (31234,5678956781234) it should only provide first one as result and not the other one.</p> <p>Accordingly I will get a merged result of all matching rows.</p> <p>How can I achieve this ?</p> <p>Thank You!</p> </div>

数据库中两个字段都是 json字符串怎样进行对比,并获取不同

数据库中两个字段都是 json字符串怎样进行对比,并获取不同

laravel 5中的日期格式(或子字符串??)

<div class="post-text" itemprop="text"> <p>I have a laravel 5 application where i need to take the month and the year from the input type month. i have stored these attributes in different columns because i have to search records depending on the year.I'm new to laravel and i'm wondering if there is any substring method with delimiters in laravel. i searched in the documentation but no luck. </p> <p>This is the input where i get the month from:</p> <pre><code>&lt;input name="month-' + meta.row + '" class="form-control month" type="month" /&gt; </code></pre> <p>The value that is posted from the above input is in the following format:</p> <pre><code>2015-06 </code></pre> <p>And this is the migration file</p> <pre><code>Schema::create('reports', function(Blueprint $table) { /*other columns*/ $table-&gt;integer('month',false,false,'2'); $table-&gt;integer('year',false,false,'4'); /*other columns*/ }); </code></pre> <p>Also i am not sure if the above syntax is correct. I tried to put the int fixed size at the end. I'm using sql server with it.</p> <p>Any help would really be appreciated, even if it's just a hint.</p> </div>


<div class="post-text" itemprop="text"> <p>I have a table that keeps <code>date</code> and <code>hour</code> data as string. I added two fields <code>date2</code> and <code>hour2</code> in order to convert and save current string instead of varchar. Date format is <strong><code></code></strong>. I want to convert that string to date format and keep it in corresponding column for each row.</p> <p><img src="" alt="Data table structure"> <img src="" alt="Data table sample data"></p> <p>I have read <a href="">"how to convert a string to date in mysql?"</a> tried to query the following statement:</p> <pre><code>UPDATE `rawdata` SET `date2` = STR_TO_DATE(`date`, '%Y-%m-%d') </code></pre> <p>but I still see <code>NULL</code> values in the <code>date2</code> column. Nothing is updated.</p> </div>


<div class="post-text" itemprop="text"> <p>hello i am trying to search <code>ddw_0_op1</code> with mysql regex serach query</p> <pre><code>SELECT * FROM wp_postmeta WHERE meta_key RLIKE '(?=.*ddw_)(?=.*_op1)' </code></pre> <p>but in results its also displaying results from this field </p> <pre><code>_ddw_0_op1 </code></pre> <p>but i want to display results only from this field <code>ddw_0_op1</code> . how i can achieve that <a href="" rel="nofollow noreferrer"><img src="" alt="enter image description here"></a> in this picture i want results from http links field i hope that makes sense now</p> </div>


<div class="post-text" itemprop="text"> <p>Can someone please tell me what I am missing. the following sql query returns only the first letter of strings it fetched from the my database:</p> <pre><code> $result = mysql_query("SELECT * FROM users) or die("error in the query"); </code></pre> <p>thanks.</p> <h2>Update</h2> <hr> <pre><code>$result = mysql_query("SELECT * FROM properties JOIN users USING(UserId) WHERE Level &lt;&gt; 'Admin' $pages-&gt;limit") or die("could not load all the properties"); $i=0; while($row = mysql_fetch_array($result)) { $fn[$i] = $row ['FN']; $ln[$i] = $row ['LN']; $phone[$i] = $row ['Phone']; $Email[$i] = $row ['Email']; } </code></pre> <p>...the part of the code that giving me head ache since yesterday. <code>$fn</code>, <code>$ln</code>, <code>$email and</code>$phone` all contain only one character. I think the error is on my own page but i just can't see it. anything concerning property contains the rite value</p> </div>

在Laravel 5.4列中应用字符串函数

<div class="post-text" itemprop="text"> <p>I'm using the latest Laravel 5.4</p> <p>I am trying to make a simple query to search users by name. The query written for MySQL looks like this:</p> <pre><code>SELECT * FROM users WHERE upper(name) LIKE '%FOO%'; </code></pre> <p>I'm trying to make it work with Eloquent. Things I've tried but failed:</p> <ol> <li><p><code>User::where('upper(name)', 'LIKE', '%FOO%')-&gt;get()</code></p></li> <li><p><code>DB::table('users')-&gt;where('upper(name)', 'LIKE', '%FOO%')-&gt;get()</code></p></li> </ol> <p>Both fail with the following error:</p> <blockquote> <p>Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'upper(name)' in 'where clause' (SQL: select * from <code>users</code> where <code>upper(name)</code> LIKE %FOO%)'</p> </blockquote> <p>The query seems to fail because Eloquent wraps the <code>upper(email)</code> statement with backticks (" ` ", " ` "). Is there a way to go around this issue or do I have to use a particular eloquent function to get convert a column to uppercase, lowercase, e.t.c?</p> </div>


<div class="post-text" itemprop="text"> <p>I am working on this project where I have this MySQL database with a table named "speechesLCMcoded" with thousands of lines of parsed text. I have four columns that are "key", "parsed", "weight" and "count".</p> <p>The text in the column "parsed" looks like this:</p> <pre><code>{N}table{/N}{V}play{/V}{A}big{/A} </code></pre> <p>I have another table that is named "concreteness" that has two columns, In the column "word" I have a list of words and in the column "score" I have each word's concreteness score. For example it would look like this</p> <pre><code>Word Score table 5 play 3 big 2 </code></pre> <p>I am working on a php script that will calculate for each line of my table "speechesLCMcoded" the total cumulated score of each word and the total number of scored words. </p> <p>In my example, the result would look like this:</p> <pre><code>Key parsed weight count 1 {N}table{/N}{V}play{/V}{A}big{/A} 10 3 </code></pre> <p>I have written a part of the script but I am stuck because of my limited experience with php. I am confused by the fact that there are two "while" loops in my script</p> <p>How would you advise me to do?</p> <pre><code>&lt;?php //Include functions include "functions.php"; ini_set('max_execution_time', 90000); echo 'Time Limit = ' . ini_get('max_execution_time'); //Conecting the database if (!$conn) { die('Not connected : ' . mysql_error());} // make LCM the current db mysql_select_db('senate'); $data = mysql_query("SELECT `key`, `tagged` FROM speecheLCMcoded") or die(mysql_error()); // puts the "data" info into the $info array while($info = mysql_fetch_array( $data) ){ $key=$info['key']; $tagged=$info['tagged']; // Print out the contents of the entry Print "&lt;b&gt;Key:&lt;/b&gt; ".$info['key'] . " &lt;br&gt;"; // Select Word List and their weights $dataweights = mysql_query("SELECT `word`, `weight` FROM concreteness") or die(mysql_error()); // puts the "data" info into the $infoweights array while($infoweights = mysql_fetch_array( $infoweights) ){ $word=$info['word']; $score=$info['score']; // Calulate number of adjectives ob_start(); //Start output buffer print substr_count($tagged,"{"); $adjectives = ob_get_contents(); //Grab output ob_end_clean(); //Discard output buffer // Calulate number of coded items //Saving number of coded words $sql = "UPDATE speechestest SET adjectives='$adjectives', verbs='$verbs', nouns='$nouns' WHERE `key`='$key';" ; $retval = mysql_query( $sql, $conn ); if(! $retval ) {die('Could not update data: ' . mysql_error());} echo "Updated data successfully "; } ?&gt; </code></pre> </div>


public boolean findName(String user) { Cursor cursor = null; try{ String str = "select user from Myphoneinfo where user=?"; SD=db.getReadableDatabase(); cursor = SD.rawQuery(str, new String[]{user}); while (cursor.moveToNext() ) { return true; } }catch(Exception e) { e.printStackTrace(); }finally { if(cursor!=null) { cursor.close(); } SD.close(); } return true; }


<div class="post-text" itemprop="text"> <p>I'm trying to save an array with options into a json datafield of my postgres database. I'm working with Laravel 5.5 and I'm using the extension "dimsav/laravel-translatable" for translations.</p> <p>My model Question looks like this: namespace App;</p> <pre><code>use Illuminate\Database\Eloquent\Model; use Dimsav\Translatable\Translatable; class Question extends Model { use Translatable; public $translatedAttributes = ['options', 'answer']; protected $casts = [ 'options' =&gt; 'array' ]; } </code></pre> <p>The model QuestionTranslation looks like this:</p> <pre><code>namespace App; use Illuminate\Database\Eloquent\Model; class QuestionTranslation extends Model { public $timestamps = false; public $fillable = ['options', 'answer']; </code></pre> <p>}</p> <p>And the store action in the QuestionsController:</p> <pre><code> public function store(Request $request) { $question = new Question(); $options[1] = "test1"; $options[2] = "test2"; $question-&gt;answer = 1; $question-&gt;options = $options; $question-&gt;save(); } </code></pre> <p>When I try to store that data I get the error:</p> <pre><code>Illuminate \ Database \ QueryException Array to string conversion (SQL: insert into "question_translations" ("locale", "answer", "options", "question_id") values (en, 1, test1, 18) returning "id") </code></pre> <p>When I use <code>json_encode</code> to cast $options myself, I can store it without problems. </p> <p>Do you have any idea, why the laravel casting is not working? Maybe because of the translatable extension?</p> </div>


<div class="post-text" itemprop="text"> <p>I have this php script that generate an sql query. However, it needs a semicolon inside the sql statement and because of that, the sql query doesn't work.</p> <pre><code>VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now()) </code></pre> <p>It is included in this function.</p> <pre><code>function insert_configuration6_table($table_name9, $type) { global $wpdb; if (!empty ($wpdb-&gt;charset)) $charset_collate = "DEFAULT CHARACTER SET {$wpdb-&gt;charset}"; if (!empty ($wpdb-&gt;collate)) $charset_collate .= " COLLATE {$wpdb-&gt;collate}"; $sql = "INSERT INTO {$table_name9} (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Installed Modules', 'MODULE_BOXES_INSTALLED', 'bm_shopping_cart.php;bm_categories.php', 'This is automatically updated. No need to edit.', '6', '0', now()),('Installed Template Block Groups', 'TEMPLATE_BLOCK_GROUPS', 'boxes', 'This is automatically updated. No need to edit.', '6', '0', now());"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } </code></pre> <p>I have searched a lot for this however, I can't find a solution that work.</p> <p>How can I make an sql query that includes a semicolon(;) in the values?</p> <p>Thanks.</p> </div>


<div class="post-text" itemprop="text"> <p>I need some pointers with some regex voodoo - I just don't use them enough day to day to be familiar with them.</p> <p>I'm processing a string containing multiple words and need to look for a reference number.</p> <p>The ref number is in the format <strong>LCSYK89HE4W4</strong> . 'LCS' is always constant, the Ref is always 12 chars long. The rest of the ref is made up from random uppercase alphanumeric chars.</p> <p>Examples:</p> <pre><code>LCSJKIIU786T LCS5YU87TFR4 LCSKIJ5R67DE </code></pre> <p>Any pointers would be much appreciated.</p> <p>Thanks Sam</p> </div>


<div class="post-text" itemprop="text"> <p>we have a table <strong>usersandgroups</strong> and it has four rows.I am trying to fetch the row count as per group id but it is <strong>returning 1</strong> for every group id but it has many more point when i remove where clause condition even then it is returning 1...that means it is always <strong>returning 1</strong>.</p> <pre><code>&lt;?php require_once("db_connect.php"); $gp_id = $_POST["GP_ID"]; $query = "SELECT COUNT(*) FROM USER_ANDGROUPS WHERE GP_ID = '$gp_id';"; $res = mysqli_query($con,$query); if(mysqli_num_rows($res)&gt;0) { $row_cnt = $res-&gt;num_rows; echo $row_cnt ; } else { echo "false"; } ?&gt; </code></pre> <p>I am trying to fetch the row count as per group id but it is <strong>returning 1</strong> for every group id but it has many more point when i remove where clause condition even then it is returning 1...that means it is always <strong>returning 1</strong>.</p> </div>


场景如下, 有一张用户表user,主键用户编号user_id ,类型int; 三张业务表 a_record,b_record,c_record,分别都含有外键user_id. 在方法中,别人传给我一串user_id ,字符串的,逗号分割的,如“1001,2001,2003,98”; 我需要去数据库中判断这些user_id串中的用户是否有三种业务中至少一条的记录, (只要这个user_id字符串中的有一个人有其中之一业务记录,我就可以返回true,否则返回false ) 这个sql语句怎么写?


<div class="post-text" itemprop="text"> <p>I have a string , in my sql database that has come from user.</p> <pre><code>$str ='&lt;h2 contenteditable="true"&gt;I am a not a good user &lt;script&gt;alert("hacked") &lt;/script&gt; &lt;/h2&gt;'; </code></pre> <p>if I echo it as it is then it is not good So I use htmlspecialchars(); to escape the special html chracters</p> <pre><code>echo htmlspecialchars($str); </code></pre> <p>This will save me from hacking , but i want to keep other tags (like &lt;h2&gt; ) as it is , i don't want it to change , is their a way if i could only escape specific tag using htmlspecialchars();</p> </div>


<div class="post-text" itemprop="text"> <p>I want to try sorting dates but there are constraints, because those columns are varchar. </p> <p>This existing data</p> <p><img src="" alt="enter image description here"></p> <p>This is the query that I test.</p> <pre><code>SELECT PERIODE, RF, APPROVE_DATE FROM DLY_UPGRADE WHERE (SLP = '368') AND (CONVERT(datetime, APPROVE_DATE, 101) &gt; '01/01/2017') </code></pre> <p>The error message :</p> <p><img src="" alt="enter image description here"></p> </div>


<div class="post-text" itemprop="text"> <p>I have a text for a book pages that may have footnotes at the end of the string like the following example:</p> <pre><code>والخاتِم بكسر التاء اسم فاعل، فكأنه قد جاء آخر الرسل، والخاتَم بفتح التاء اسم آلة، كأنه قد ختمت به الرسالة. __________ (1) - سورة الأحزاب آية : 43. (2) - سورة البقرة آية : 157. (3) - سورة الأنعام آية : 17. (4) - سورة الكهف آية : 19. </code></pre> <p>The line that I mean in the sample and the specific characters in this case are <a href="" rel="nofollow">Kashidas</a> <code>_</code> (It is not dash <code>-</code>), in Latin, it called underscore. What I need to get is matching the four lines or any number of lines under that line.</p> <p>What I have tried let only to match the first line under that line:<code>/_.* *(.*)/gum</code> and this is a <a href="" rel="nofollow">demo</a>. The only way to get them all, is to repeat the pattern portion <code> *(.*)</code> n times equals to the number of lines in the footnotes i.e four times, regarding the example case, and this is not a practical solution like <a href="" rel="nofollow"><strong>this demo</strong></a></p> </div>


今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...



和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...



总结了 150 余个神奇网站,你不来瞅瞅吗?



提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...






私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...


场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...


阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...




本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...




当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...


HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...



面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?





已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)


《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)


都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...










不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...


某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...