开发者

work with mysql_query

开发者 https://www.devze.com 2023-03-20 01:28 出处:网络
I have 2 query in php and I want to put and execute query1 before query2 , query1 is a select query and query2 is a delete query.when I put query2 before query1 in php code both queries work properly

I have 2 query in php and I want to put and execute query1 before query2 , query1 is a select query and query2 is a delete query.when I put query2 before query1 in php code both queries work properly but when I put query1 before query2 only query1 works,and query2 not works.

query1:

$result = mysql_query( 'CALL view_polls('.$blogId.');' );

query2:

 $rlt=mysql_query('CALL delete_poll('.$I.');');

All code :

$blogId=1;  
    $r=$_GET['rowNumber'];

$result = mysql_query( 'CALL view_polls('.$blogId.');' );

$row=mysql_fetch_array($result);
for($i=0;$i<$r;$i++)
    $row=mysql_fetch_array($result);
//echo $row['id'];
$I=$row['id'];
$rlt=mysql_query('CALL delete_poll(.'$I.');');  `

my procedures are simple select and delete procedure.

view_poll proc :

DELIMITER $$

DROP PROCEDURE IF EXISTS `prj`.`view_polls` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `view_polls`(IN b_id INT)
BEGIN
select id,title,showPoll,ans1,ans2,ans3,ans4,a开发者_JAVA百科ns5,ans6 from poll
where blog_id=b_id;
END $$

DELIMITER ;

delete_poll proc :

DELIMITER $$

DROP PROCEDURE IF EXISTS `prj`.`delete_poll` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_poll`(IN I int)
BEGIN
   delete from poll
   where id=I;
END $$

DELIMITER ;


I don´t know where $r comes from, but the most likely problem is that you have reached the end of the first result set so $row is false and $I is not an ID.


I don't have enough information to solve your problem. Can you post the code for SQL view_polls and delete_poll? Also two more things I want to point out:

1) Be sure to use mysql_real_escape_string on $blogId to prevent SQL injection attacks. 2) It seems like you are treating $row as an associative array. You don't need to use mysql_fetch_array, instead you can use mysql_fetch_assoc which doesn't also return the numerical indexes the first does.

Maybe it's possible that there is a problem in view_poll() and it will only work correctly when there are no polls to view (which happens when you call delete_poll())

0

精彩评论

暂无评论...
验证码 换一张
取 消