我正在尝试实现一个简单的 mysql 插入,它采用用户的名字 ($first_name) 和用户的姓氏 ($last_name) 并将它们插入到我的用户表 (url) 列中。这非常像 Quora 和 Facebook...例如 www.facebook.com/Michael.Jackson.32。
我的 while 循环在下面,我希望我知道错误,但是当我执行代码时,我的服务器继续运行并最终超时。
任何帮助深表感谢。
//Store Vanity URL
$user_id_sql = $db->prepare("SELECT id FROM users WHERE first_name = :first_name AND last_name = :last_name");
$user_id_sql->execute(array(':first_name' => $first_name , ':last_name' => $last_name));
$user_search_results = $user_id_sql->rowCount();
if($user_search_results == "0") {
$vanity = $first_name.'.'.$last_name;
$insert_vanity_url = $db->prepare("INSERT INTO users (url) VALUES (:vanity) WHERE uid = :uid");
$insert_vanity_url->execute(array(':vanity'=>$vanity , ':uid'=>$uid));
}
else {
$var1 = "bad";
$i = "1";
while($var1 == "bad") {
$user_id_sql_two = $db->prepare("SELECT id FROM users WHERE first_name = :first_name AND last_name = :last_name");
$user_id_sql_two->execute(array(':first_name' => $first_name , ':last_name' => $last_name));
$user_search_results_two = $user_id_sql_two->rowCount();
if($user_search_results_two == "0") {
$vanity = $first_name.'.'.$last_name.$i;]
$insert_vanity_url = $db->prepare("INSERT INTO users (url) VALUES (:vanity) WHERE uid = :uid");
$insert_vanity_url->execute(array(':vanity'=>$vanity, ':uid'=>$uid));
$var1 = "good";
}
$i++;
}
}