나는 이걸로 정말 고민 중입니다 ...수표 | 드롭 | 만들기 | ODBC를위한 PHP로 테이블 삽입
나는이 일이 약 90 %의 효과를 얻습니다. 제가 겪고있는 것은 테이블이 아직 존재하는지 확인하는 것입니다. 또는 아닙니다 ...
2 개의 페이지가 있습니다. 첫 번째 페이지는 $_POST
을 주요 기능 페이지로 보냅니다. 그것은 하나의 입력입니다.
시나리오 : 하나의 입력이 submit.php로 제출되어 temp db에 삽입 된 다음이 페이지에서 완료 될 때까지 더 많은 입력을 삽입 할 수 있습니다. 여기서 멈출 것입니다.
필요한 경우 테이블이 처음부터 존재하지 않는지 확인하십시오. 해당되는 경우 삭제하십시오. 표를 작성한 다음 행 수를 삽입하고 갱신하십시오. 여기
는 내가 지금까지 무엇을 가지고 :
#17 - $FirstSub = $_SESSION['version']; //True if this is the first time page has loaded
if(isset($conn)){ // Check connection
//create table string
$createTemp = "CREATE TABLE temp_Ticket_Tracker(
PickT_Num int NOT NULL UNIQUE,
us_name varchar(20) NOT NULL,
ticket_status varchar(10) NOT NULL,
time_stamp varchar(20) NOT NULL,
PRIMARY KEY(PickT_Num)
)";
//Insert String
$insert = "INSERT INTO temp_Ticket_Tracker VALUES ('". $_POST['PickNum'] ."','{$_SESSION['User']}','GREEN','{$TimeStamp}')";
//row count string
$query = "Select COUNT(*) as TicketNum FROM temp_Ticket_Tracker";
//Duplicate tester string
$tested = "SELECT PickT_Num FROM temp_Ticket_Tracker WHERE '". $_POST['PickNum'] ."' = PickT_Num";
//Drop's table
$drop = "DROP TABLE temp_Ticket_Tracker";
//Here is where it starts to screw up -
#35 - $firstTest = odbc_exec($conn,$query); //execution string
$NumRows = odbc_fetch_array($firstTest); //Sets array
$countingRows = $NumRows['TicketNum'];
//This is "Supposed" to ask is this the first time you've been here and does the table exist? Answer (Yes, Yes)
if($FirstSub === 'true' && $countingRows >= 1){
odbc_exec($conn,$drop);
odbc_exec($conn,$createTemp);
odbc_exec($conn,$insert);
$_SESSION['version'] = 'false';
$int = odbc_exec($conn,$query);
$intNum = odbc_fetch_array($int);
$TicCount = $intNum['TicketNum'];
odbc_close($conn);
//Again asks if first time and does the table exist? Answer should be(Yes, NO)
}else if($FirstSub === 'true' && !$firstTest){
odbc_exec($conn,$createTemp);
odbc_exec($conn,$insert);
$_SESSION['version'] = 'false';
$int = odbc_exec($conn,$query);
$intNum = odbc_fetch_array($int);
$TicCount = $intNum['TicketNum'];
odbc_close($conn);
//Asks if this is first time and assums Table is created
}else if($FirstSub === 'false'){
$is = odbc_exec($conn,$tested);
$test = odbc_fetch_array($is);
//Check to make sure duplicate has not been entered
if($test == NULL){
odbc_exec($conn,$insert);
$int = odbc_exec($conn,$query);
$intNum = odbc_fetch_array($int);
$TicCount = $intNum['TicketNum'];
odbc_close($conn);
//Passes error if duplicate is used
}else{
echo '<script type="text/javascript">',
'window.onload = function() {',
'document.getElementById("error").innerHTML = "You have already scanned this ticket!";};',
'</script>';
$int = odbc_exec($conn,$query);
$intNum = odbc_fetch_array($int);
$TicCount = $intNum['TicketNum'];
}
}else{
echo '<p> OOPS! looks like we may have a problem!</p>';
$_SESSION['version']='true';
}
}else{echo "Try again...";}
모든 것이 완벽하게 작동합니다! 전체 테이블 (화면 꺼짐)를 제출하고 임시 테이블이 삭제 될 때 ...
입력
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'temp_Ticket_Tracker'., SQL state S0002 in SQLExecDirect in C:\Program Files (x86)\EasyPHP5.3.0\www\idea\ticket\greenFunction.php on line 35
Warning: odbc_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP5.3.0\www\idea\ticket\greenFunction.php on line 36 (Line numbers look like #n -)
감사합니다. 코드를 위로 업데이트하겠습니다. –