Jump to content

Recommended Posts

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.

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'];

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.