richarro1234 Posted February 14, 2009 Share Posted February 14, 2009 Hey there, im trying to make it so that i can echo a message after a succesful SQL query, without having to load a new page. So the query can be run and if it works it will echo a successful msg, but if it fails it will echo a msg (that isnt the mysql error:) Here is the code: $query = mysql_query("DELETE FROM <tablename> WHERE id = '$padid'"); header ("echo: testing?"); die(); thats the sort of thing i would like, how would i go about doin that please? Thanks Rich Quote Link to comment Share on other sites More sharing options...
Michdd Posted February 14, 2009 Share Posted February 14, 2009 $query = mysql_query("DELETE FROM <tablename> WHERE id = '$padid'"); or die(mysql_error()); echo "Success!"; Is that what you want? If there was an error and it wasn't put in it will output the error, but if the query was successful it will go onto the echo and echo "Success" Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted February 14, 2009 Author Share Posted February 14, 2009 yea thats what i want and it works great, thanks. but is there anyway of choosing where it echo's as all the code is at the top of my page and i would like it to echo near the bottom of my page? Thanks Quote Link to comment Share on other sites More sharing options...
Michdd Posted February 14, 2009 Share Posted February 14, 2009 yea thats what i want and it works great, thanks. but is there anyway of choosing where it echo's as all the code is at the top of my page and i would like it to echo near the bottom of my page? Thanks Well, I guess you could just move the echo to wherever you want. Because if there is an error it won't get anywhere past the or die() line. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted February 14, 2009 Author Share Posted February 14, 2009 yea but its for a certain function. Here is the code for that bit: ...some site code above here.... if ($_GET['action'] == 'delete') { $padid = ($_GET['padid']); $query = mysql_query("SELECT * from richspri_social.padposts WHERE id = '$padid'"); while ($pad = mysql_fetch_array($query)) { if (strtoupper($pad['posterid']) != strtoupper($urid)) { header ("Location: $page&error=5"); die(); } $there = "yes"; } if ($there == FALSE) { header ("Location: $page&error=6"); die(); } $query = mysql_query("DELETE FROM richspri_social.padposts WHERE id = '$padid'"); echo "Success!"; } ....rest of the site code.... Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.