www.webdeveloper.com
Results 1 to 4 of 4

Thread: Database error question

  1. #1
    Join Date
    Oct 2010
    Posts
    11

    Question Database error question

    Hey guys.. I've been setting up a database for a contact page and I have everything working for it except the following error on my update contact page.. can anyone help me figure it out?? The error lines are the ones where I have my mysql_result's.

    Errors:

    No Records Found

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 103

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 104

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 105

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 106

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 107

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 108

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 109

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 110

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/jonnyp22/public_html/a5/update_contact.php on line 111

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Update Contact</title>
    <script  type="text/javascript">
    function Validateform(){
    	var email=document.form1.email;
    	var firstname=document.form1.firstname;
    	var lastname=document.form1.lastname;
    	var state=document.form1.state;
    	
    	var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/;	
    	
    	if ((email.value==null)||(email.value=="")){
    		alert("Please enter email address");
    		email.focus();
    		return false;
    	}
    	if (reEmail.test(email.value)==false){
    	  	alert ("Please enter valid email address");
       		email.focus();
       		return false;
       	}
    		if ((firstname.value=="")||(firstname.value==null)) {
    		alert("Please enter first name");
    		firstname.focus();
    		return false;
    	}
    	
    	if ((lastname.value=="")||(lastname.value==null)) {
    		alert("Please enter last name");
    		lastname.focus();
    		return false;
    	}	
    	if (state.selectedIndex==0) {
    		alert("Select state");
    		state.focus();
    		return false;
    	}
    	return true;
     }
    
    </script>
    
    <style type="text/css">
    .style1 {
    	text-align: center;
    	color: #F8B57E;
    	font-size: x-large;
    }
    .style2 {
    	text-align: center;
    }
    .style3 {
    	text-align: right;
    	color: #F8B57E;
    }
    .style4 {
    	text-align: left;
    }
    .style6 {
    	text-align: center;
    	color: #F8B57E;
    	font-size: medium;
    }
    .style7 {
    	color: #FFFFFF;
    }
    </style>
    </head>
    
    <body style="color: #FFFFFF; background-color: #102541">
    
    <div class="style2">
    
    <p class="style1"><strong>Update Contact</strong></p>
    	<p class="style6">* Indicates a Required Field</p>
    
    <?php
    
    include("dl.php");
    
    // If the form has not been submitted then show it
    
    if(!$_POST['Submit'])
    {
    
    	$email=$_GET['email'];
    	
    	$query="SELECT * FROM person WHERE Email = '$email'";
    	$result=mysql_query($query) or die('Error: ' . mysql_error());
    
    	$num=mysql_numrows($result);
    
    	mysql_close();
    
    	if ($num == 0) {
    		echo "<b><center>No Records Found</center></b>";
    	}
    
    	$lastname=mysql_result($result,0,"Last_Name");
    	$email=mysql_result($result,0,"Email");
    	$firstname=mysql_result($result,0,"First_Name");
    	$address1=mysql_result($result,0,"address1");
    	$address2=mysql_result($result,0,"address2");
    	$city=mysql_result($result,0,"city");
    	$state=mysql_result($result,0,"state");
    	$zip=mysql_result($result,0,"zip");
    	$phone=mysql_result($result,0,"phone");
    
    ?>
    
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <table style="width: 100%">
    	<tr>
    		<td style="width: 219px; height: 26px" valign="top" class="style3">E-mail Address:</td>
    		<td style="height: 26px" class="style4">
    		<input name="email" style="width: 363px" type="text" value="<? echo $email; ?>" readonly="readonly" />
    		</td>
    	</tr>
    	<tr><td class="style3">First Name:</td><td class="style4"><input type="text" name="firstname" id="firstname" size="30" width="250px" value="<? echo $firstname; ?>"/></td></tr>
        <tr>
    		<td class="style3" >Last Name:</td><td class="style4" ><input name="lastname" id="lastname" type="text"  size="30" width="250px" value="<? echo $lastname; ?>"/></td>
    	</tr>
        <tr><td class="style3">Phone:</td><td class="style4"><input type="text" name="phone" id="phone" size="15" width="250px" value="<? echo $phone; ?>"/></td></tr>
        <tr>
          <td class="style3">Address Line 1:</td><td class="style4"><input type="text" name="address1" id="address1" size="50" width="250px" value="<? echo $address1; ?>" /></td></tr>
        <tr>
          <td class="style3">Address Line 2:</td><td class="style4"><input type="text" name="address2" id="address2" size="50" width="250px" value="<? echo $address2; ?>"/></td></tr>
        <tr><td class="style3">City:</td><td class="style4"><input type="text" name="city" id="city" size="50"  width="250px" value="<? echo $city; ?>"/></td></tr>
        <tr><td class="style3">State:</td><td class="style4"><select name="state" id="state">
        	
    					<option <? if ($state=="NJ") echo selected ;?> >NJ</option>
    					<option <? if ($state=="NY") echo selected ;?> >NY</option>
    					
    				</select></td></tr>
        <tr><td class="style3">Zip:</td><td class="style4"><input type="text" name="zip" id="zip" size="5" value="<? echo $zip; ?>"/></td></tr>
    </table>
    <p class="style2"><input name="Submit" type="submit" value="Update" />&nbsp;<a href="show_contacts.php"><span class="style7">Show Contacts</span></a>
    <br />
    </p>
    </form>
    
    <?php
    
    }
    else
    {
    
    // The form has been submitted so process it
    
    $email=$_POST['email'];
    $lastname=$_POST['lastname'];
    $firstname=$_POST['firstname'];
    $phone=$_POST['phone'];
    $address1=$_POST['address1'];
    $address2=$_POST['address2'];
    $city=$_POST['city'];
    $state=$_POST['state'];
    $zip=$_POST['zip'];
    
    $query="UPDATE person SET Last_Name='$lastname',FIRST_Name='$firstname',Phone='$phone', Address1='$address1', Address2='$address2', city='$city', state='$state',zip='$zip' WHERE Email='$email'";
    
    if (!mysql_query($query,$con))
      {
      	die('Error: ' . mysql_error());
      }
    else {
    	echo "<center><b> Contact info $lastname updated successfully </b><a href='show_contacts.php'>show contacts</a></center>";
    }
    
    mysql_close();
    
    }
    ?>
    </div>
    </body>
    
    </html>

  2. #2
    Join Date
    Sep 2010
    Posts
    160
    You should post this on the PHP forum instead, I think it is an PHP issue.

    Archie

  3. #3
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    The first line says the most important part: No records found; then, "unable to jump to row 0". For some reason, it's finding an empty table.

    ^_^

  4. #4
    Join Date
    Oct 2005
    Location
    Cambridgeshire, UK
    Posts
    191
    Try changing your code to the following:

    PHP Code:
    $email=$_GET['email'];
        
    $query="SELECT * FROM `person` WHERE `Email` = '$email'";
    $result=mysql_query($query) or die('Error: ' mysql_error());

    $num=mysql_num_rows($result); // NOTE: Spelling correction here

    mysql_close();

    if (
    $num == 0) {
        echo 
    "<b><center>No Records Found</center></b>";
    }else{
        
    $lastname=mysql_result($result,0,"Last_Name");
        
    $email=mysql_result($result,0,"Email");
        
    $firstname=mysql_result($result,0,"First_Name");
        
    $address1=mysql_result($result,0,"address1");
        
    $address2=mysql_result($result,0,"address2");
        
    $city=mysql_result($result,0,"city");
        
    $state=mysql_result($result,0,"state");
        
    $zip=mysql_result($result,0,"zip");
        
    $phone=mysql_result($result,0,"phone");

    Also, is it just the first row that you want to obtain? If so maybe you could consider the following:

    PHP Code:
    $email=$_GET['email'];
        
    $query="SELECT * FROM `person` WHERE `Email` = '$email' LIMIT 1";
    $result=mysql_query($query) or die('Error: ' mysql_error());

    if (
    $row mysql_fetch_array($result)) {
        
    $lastname $row['Last_Name'];
        
    $email $row['Email'];
        
    $firstname $row['First_Name'];
        
    $address1 $row['address1'];
        
    $address2 $row['address2'];
        
    $city $row['city'];
        
    $state $row['state'];
        
    $zip $row['zip'];
        
    $phone $row['phone'];
    }else{
        echo 
    "<b><center>No Records Found</center></b>";

    Would be a lot quicker / more efficient

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles