douman9420 2017-08-17 19:58
浏览 76

在插入表之前检查另一个表的值

I have two mysql tables. One of those tables(dwg) the user will be able to fill out and it will insert a row, but I need it to check the other table(form) and make sure one of the fields does not exist.

I have a query that says:

$projnum=$_REQUEST['project'];
$check = $con->query("SELECT Project FROM form WHERE Project ='$projnum'");
if($check->num_rows==0){
    $sql = "INSERT INTO dwg (DWG, Date, Client, ProjNum, Project, Assigned, 
                             Location, Subdivision, STR)
    Values ('$dwg', '$date' , '$client' , '$projnum' , '$description' ,'$assigned' , 
            '$location' , '$sub' , '$str')";
}
else {
      return an echoed link
}

The problem is 'project' will have a dash(-)then 2 numbers after it.
If I fill out the form without the dash and last to numbers, it accepts it when it shouldn't, and if I add the dash and last 2 numbers it returns invalid.

Is there a way to check the whole number? Getting rid of the dash is not a possibility.

Edit for clarity: So on table: form, I have a 'project' called: 8008-17 When the person fills out the form I created to add a row to the table: dwg and they type in 8008, it should return the echo. If they type in 8008-17 it should accept it and insert the row. Right now it accepts the 8008 but not the 8008-17

If the $check returns 0 rows then it should insert the information, else it returns the echo.

Hope this helps explain the issue.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line