duanhui4160 2013-04-11 03:58
浏览 27
已采纳

表格信息不发布

I was wondering if i can have someone look over my statements to see where i might be screwing up. I've tested what information is being posted by echoing it and everything seems to be going through correctly, but I can't get it to physically create the appropriate records. I also do not get any errors and it goes back to the header location like the form did post.

//First we make sure there are enough licenses left to add the user
$limit = "select * from organization_seats WHERE orgid=$orgid";
$orglimit = mysql_query($limit);
$licenses = $orglimit['limit'];

$count = "select count(*) from organization_users WHERE organizationid=$orgid";

if ((!$licenses < $count)) {

     echo 'You have reached the number of maximum licenses for your Organization.';

 } else {

//If we have licenses left, proceed to add new user
//Populate the user table
$sql = "insert into user (firstname, lastname, title, address1, address2, country, city, state, zip, phone, mobile, birthday, username, email, password) values ('$fname','$lname','$title','$address1','$address2','$country', '$city', '$state', '$zip', '$phone', '$mobile', '$bday', '$username', '$email', '$password')";

$exec = mysql_query($sql);

//Add the user to the organization
$userid = mysql_insert_id(); //call the last ID entered into the user table first

$sql2 = "insert into organization_users(organizationid, userid, active) values ('$orgid', '$userid', $)";
$exec = mysql_query($sql2); 

//recall the userid
$sql3 = "select * from user where username = $username";
$exec = mysql_query($sql3);
$newuserid = $newuserselect['id'];  

 //Add the user to the department
$sql4 = "insert into organization_dep_users(orgid, depid, userid) values ('$orgid', '$department', '$newuserid')";
$exec = mysql_query($sql4);

if ($exec === TRUE) {

    header( 'Location: index.php' ) ;

} else {
    echo mysql_error();
 }
}

btw, i do have mysql_real_escape_string attached to all my variables.

  • 写回答

2条回答 默认 最新

  • dsj2014 2013-04-11 04:12
    关注

    1) $sql2 has an error - you are passing $ instead of an actual variable.

    2) After $sql3 you are assigning $newuserid from a non-existent resource. I assume you are missing $newuserselect = mysql_fetch_assoc($exec); just before it.

    3) You really need to add error checking on your queries. If the first query fails the second query will be run with an erroneous $userid, or maybe FALSE if no previous query created an id. Other problems can arise later in your code without error checking too.

    4) As suggested above it is advisable to transition to pdo or mysqli.

    5) Just noticed - your first select query is also trying to misuse the resource - you should be doing

    $orglimit = mysql_query($limit);
    $orgrow = mysql_fetch_assoc($orglimit);
    $licenses = $orgrow['limit'];
    

    6) And.... your $count won't work, you assign the query string to $count but never actually execute the query to get the number. So when you do if ((!$licenses < $count)) you are actually comparing a number to a string, not a number to a number.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算