cipher143 Posted August 28, 2013 Share Posted August 28, 2013 i am trying to develop a registration form where the user fill the form and submit it then the status and the id should be displayed.i have used uniq_id function to generate a random id and with the help of this reference id i can retrieve the actual ID and display it back to the user. But unfortunately i am successful with the first registration after the first registration it throws an error that Error: "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 9". my code: <?php include(conn.php); $id = $_GET['id']; $adv = $_GET['adv']; $name = $_GET['name']; $address = $_GET['address']; $pincode = $_GET['pincode']; $email = $_GET['email']; $fax = $_GET['fax']; $mobile = $_GET['mobile']; $amount = $_GET['amount']; $ddchno = $_GET['ddchno']; $bank = $_GET['bank']; $register = mysql_query( "insert into exbadv ( refid,adv,name,address,pincode,email,fax,mobile,amount,ddchno,bank) values ('$id','$adv','$name','$address','$pincode','$email','$fax','$mobile','$amount','$ddchno','$bank')"); $id = $_GET['id']; $result = mysql_query("SELECT id FROM exbadv WHERE refid = '$id'"); echo 'Your Registration id is ';echo mysql_result($result,0); ?> Plz help me out,thank u. Quote Link to comment https://forums.phpfreaks.com/topic/281633-generate-a-registration-id-and-display-it-after-successful-registration/ Share on other sites More sharing options...
Muddy_Funster Posted August 28, 2013 Share Posted August 28, 2013 do a var_dump($result) and see what's actually in there Quote Link to comment https://forums.phpfreaks.com/topic/281633-generate-a-registration-id-and-display-it-after-successful-registration/#findComment-1447131 Share on other sites More sharing options...
cyberRobot Posted August 28, 2013 Share Posted August 28, 2013 Instead of running two queries, you could use mysql_insert_id(): http://php.net/manual/en/function.mysql-insert-id.php Also note that the following line of code appears twice. The second reference isn't necessary. $id = $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/281633-generate-a-registration-id-and-display-it-after-successful-registration/#findComment-1447143 Share on other sites More sharing options...
mac_gyver Posted August 28, 2013 Share Posted August 28, 2013 mysql_result is the only database function that throws a php error when the query ran but didn't match any rows. you need to use what cyberRobot suggested to get the id, but your code has some other problems. 1) you need to validate the inputs, so that you don't run the rest of the code and insert empty rows, just because your page got requested (i.e. by a search engine spider.) you should only run the insert query if you know you have valid data. at least test to make sure the required values are not empty. 2) you need to escape string data and validate/cast numerical data (or user prepared queries) before putting values into the query statement to prevent sql injection and to prevent query errors. 3) you need to test if your insert query ran without any errors and that it actually inserted a row before you can attempt to get the id. i suspect your insert query is failing with an error of some kind and having some error checking logic in your code would tell you if and why your query is failing, and would prevent more errors in the code that follows the query. 4) the mysql_ database library is depreciated in php5.5 and all new code should be written using either the mysqli_ or PDO database library. now is the time to switch so that you don't have to waste time in the future rewriting all your code. Quote Link to comment https://forums.phpfreaks.com/topic/281633-generate-a-registration-id-and-display-it-after-successful-registration/#findComment-1447183 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.