10/10/2018, 11:03
giúp tớ với, cái này giải quyết the nào?
tớ có 1 form như thế này:
<form name="form1" method="get">
<p style="margin:18px ">Phone
<label><input type="text" name="txtsearchphone" id="txtsearchphone"maxlength="12" style="border:solid 1px #a3aaad;padding:3px 3px;"></label>
<label><a href="javascript:void(0)"onClick="getContent('get_ data_search',','include.php?p=searchphone&phonenu mber='+encodeURI(document.getElementById('txtsearc hphone').value));"><img src="images/button_search.png" border="0" align="top"/></a></label>
<label id="get_data_search"></label>
</p>
</form>
----------------------------------
và đây là cái function để thực hiện:
function search_phone_result($phone_number)
{
$sql = "SELECT * from cc_callerid Where cid =".$phone_number."";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
if($row > 0)
{
?>
<label>
<?
header("Location: index.php?p=info-customer");
?>
</label>
<?php
}else {
?>
<label><input type="image" src="images/button_register.png" align="top" ><br>No existing account! </label>
<?
}
}
---------------------------------------
vấn đề của tớ là khi chạy tới dòng :
if($row > 0) thì nó ko thể gọi duoc cái header("Location: index.php?p=info-customer");
làm sao để nó có thể thực hiện việc chuyển sang trang này khi nó chạy tới dòng if($row >0).
bạn nào có cách giải quyết chỉ giúp tớ nhé.
thanks.
<form name="form1" method="get">
<p style="margin:18px ">Phone
<label><input type="text" name="txtsearchphone" id="txtsearchphone"maxlength="12" style="border:solid 1px #a3aaad;padding:3px 3px;"></label>
<label><a href="javascript:void(0)"onClick="getContent('get_ data_search',','include.php?p=searchphone&phonenu mber='+encodeURI(document.getElementById('txtsearc hphone').value));"><img src="images/button_search.png" border="0" align="top"/></a></label>
<label id="get_data_search"></label>
</p>
</form>
----------------------------------
và đây là cái function để thực hiện:
function search_phone_result($phone_number)
{
$sql = "SELECT * from cc_callerid Where cid =".$phone_number."";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
if($row > 0)
{
?>
<label>
<?
header("Location: index.php?p=info-customer");
?>
</label>
<?php
}else {
?>
<label><input type="image" src="images/button_register.png" align="top" ><br>No existing account! </label>
<?
}
}
---------------------------------------
vấn đề của tớ là khi chạy tới dòng :
if($row > 0) thì nó ko thể gọi duoc cái header("Location: index.php?p=info-customer");
làm sao để nó có thể thực hiện việc chuyển sang trang này khi nó chạy tới dòng if($row >0).
bạn nào có cách giải quyết chỉ giúp tớ nhé.
thanks.
Bài liên quan
//đổi
if($row > 0)
//thành
if (count($row) > 0)
$nr = mysql_num_row($sql);
if ($nr > 0){
header();
}else{
echo '...';
}
1. Query trả về kết quả có = 0 (ko có record nào) nên nó thực hiện câu sau.
2. Báo lỗi Header
3. Không báo lỗi Header, thử thay câu lệnh Header bằng 1 câu lệnh khác. Ví dụ: echo 'OK'; xem nó có xuất ra dòng OK hay ko?
toàn bộ cái
function search_phone_result($phone_number){
$sql = "SELECT * from cc_callerid Where cid =".$phone_number."";
$res = mysql_query($sql);
$num = mysql_num_rows($res);
if($num > 0)
{
echo 'aaa';
//header("Location: index.php?p=info-customer");
?>
<a href="index.php?p=info-customer">click here .</a>
<?php
}else {
?>
<label><a href="javascript:void(0)" ><img src="images/button_register.png" border="0" align="top"/></a><br>No existing account! Make sure the phone is correct before registering new customer.</label>
<?
}
}
này đều thực hiện ngon lành,trừ cái dòng header là ko làm viec thoi ban à.
header('Location: http://localhost/site/index.php?p=info-customer');
Hơn nữa hàm header mà bỏ vào function thì không ổn tí nào.
hay ajax thì chỉ có trả về kết quả chứ ko có chuyễn di nhỉ.(ko biet minh nói sai hay đúng.)
[=========> Bổ sung bài viết <=========]
@thuyduongcd:
tớ ko hiểu rõ bạn nói.tại sao header lai ko thể dùng theo cách cua mình ? chỉ là gọi trang thôi mà.
còn cái echo là mình muon kiem tra xem nó có thực sự duyệt vào cái $num>0 hay la ko thôi.