dongxuying7583 2014-01-18 16:15
浏览 18

MySQL如果可用数据转到页面并显示结果如果没有可用返回检查号

I need a small logic which i can't able to get here

i need to get MySQL data from db and echo on .php file before that i need to check whether data is available or not if available goto one.php file to show results if data not available retunt back to previos page i used below code but no use please help

<?php

$connection = mysql_connect('localhost','asd_asd','13wda121asSS') or die ("Couldn't connect to server."); 
$db = mysql_select_db('asdasd_asds', $connection) or die ("Couldn't select database."); 

$warno=$_POST['search'];

$data = 'SELECT * FROM `cases` WHERE `warno` = "'.$warno.'"';

if (mysql_num_rows($result)==0) { header('Location: http://asdas.in/wcdsa.php')
} 
else
    {
    //We have no results and can't find the warranty, return a different page saying no warranty results exist
     header('Location: http://asdsd.in/wcasd.php'); //redirect
}

?>

here i need

$data = 'SELECT * FROM cases WHERE warno = "'.$warno.'"'; $result = mysql_query($data,$connection); //execute query 

i need to execute query in other page like results.php where i will show the results

if data not exist in database show "NO DATA FOUND" in same page where query executed itself please help on this

  • 写回答

1条回答 默认 最新

  • douying6206 2014-01-18 16:18
    关注

    You did not execute your query. You need to execute query first. your $result is undefined.

    try this:

    <?php
    
    $connection = mysql_connect('localhost','asd_asd','13wda121asSS') or die ("Couldn't connect to server."); 
    mysql_select_db('asdasd_asds', $connection) or die ("Couldn't select database."); 
    
    $warno=$_POST['search'];
    
    $data = 'SELECT * FROM `cases` WHERE `warno` = "'.$warno.'"';
    $result = mysql_query($data,$connection); //execute query
    if (mysql_num_rows($result)==0) { header('Location: http://asdas.in/wcdsa.php')
    } 
    else
        {
        //We have no results and can't find the warranty, return a different page saying no warranty results exist
         header('Location: http://asdsd.in/wcasd.php'); //redirect
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)