I'm going a little crazy here trying to figure this out.
Any help would be greatly appreciated.
MySQL version: 5.0

I'm trying to make a very ugly php page used to basic queries.
I have a similar page working that creates new records in the specified table, so I know my connection to the DB is fine (used the same info)

<?php
	$id = $_POST['clientid'];
	$fname = $_POST['clientfname'];
	$lname = $_POST['clientlname'];
	

	$dbc = mysql_connect('ip', 'login', 'password', 'dbname')
		or die('Error connecting to MySql server.');
		
	$query = "SELECT * FROM CLIENT WHERE id = '$id'";	
				
	$result = mysql_query($dbc, $query)
		or die('Error querying database.');
		
	
	$rownum = mysql_num_rows($result);
	
	$i=0;
	while ($i <= $rownum) {
		
	$rid = mysql_result($result, $i, "id");
	$rfname = mysql_result($result, $i, "fname");
	$rlname = mysql_result($result, $i, "lname");
	$rmphone = mysql_result($result, $i, "mphone");
	$rhphone = mysql_result($result, $i, "hphone");
	$raddress = mysql_result($result, $i, "address");
	$remail = mysql_result($result, $i, "email");
	$rtech_level = mysql_result($result, $i, "tech_level");
	
	echo "$rid <br />";
	echo "$rfname '  ' $rlname <br />";
	echo "$rmphone <br />";
	echo "$rhphone <br />";
	echo "$raddress <br />";
	echo "$remail <br />";
	echo "$rtech_level <br />";
		
	$i++;
	}
	
	mysql_close($dbc);
?>

I have gotten so many error codes I want to shoot myself.
Most of them are roughly:

mysql_query or mysql_num_rows or mysql_result: supplied argument is not a valid MySQL-Link resource

I would assume the issue is not getting a connection and therefor not know wtf any of these commands mean, but I have a connection on my other script, so yeah.. Confused.

I have tried putting an "i" in front of mysql on all my functions, same errors. I have slapped an "@" in front of the functions causing errors, but that simply returned a blank white page (suppressing the errors).

Thanks for any help I get!!

May I see the error message that is popping up?
Let's look error message by error message while going through the script.
For what you have now, what is the exact error message that is popping up?

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/27/7825027/html/query/pullclient.php on line 21
Error querying database.

Is the exact error I am getting with the code listed above.

Try this:

<?php
	$id = $_POST['clientid'];
	$fname = $_POST['clientfname'];
	$lname = $_POST['clientlname'];
	

	$dbc = mysql_connect('ip', 'login', 'password', 'dbname')
		or die('Error connecting to MySql server.');
		
	$query = "SELECT * FROM CLIENT WHERE id = '$id'";	
				
	$result = mysql_query($dbc, $query)
		or die('Error querying database.');
		
	$rownum = mysql_num_rows($result);
		
	if ($rownum > 0)
	{
		$i = 0
		while (mysqli_fetch_row($rownum))
		{
			$rid = mysql_result($result, $i, "id");
			$rfname = mysql_result($result, $i, "fname");
			$rlname = mysql_result($result, $i, "lname");
			$rmphone = mysql_result($result, $i, "mphone");
			$rhphone = mysql_result($result, $i, "hphone");
			$raddress = mysql_result($result, $i, "address");
			$remail = mysql_result($result, $i, "email");
			$rtech_level = mysql_result($result, $i, "tech_level");
			
			echo $rid."<br />";
			echo $rfname." ".$rlname."<br />";
			echo $rmphone."<br />";
			echo $rhphone."<br />";
			echo $raddress."<br />";
			echo "$remail."<br />";
			echo $rtech_level."<br />";
				
			$i++;	
		}
	}
	
	
	mysql_close($dbc);
?>

That loop doesn't make any sense. There is no comparison...

I've tried using a persistent connection instead of a non-persistent one. Now everything seems to be fine but I am receiving my default die error code, but no MySQL error now.....

<?php
	$id = $_POST['clientid'];
	$fname = $_POST['clientfname'];
	$lname = $_POST['clientlname'];
	

	mysql_pconnect('ip', 'username', 'password')
		or die('Error connecting to MySql server.');
		
	$query = "SELECT * FROM CLIENT WHERE id = '$id'";	
				
	$result = mysql_query($query)
		or die('Error querying database.');
		
	
	$rownum = mysql_num_rows($result);
	
		$i=0;
		while ($i <= $rownum) {
		
			$rid = mysql_result($result, $i, "id");
			$rfname = mysql_result($result, $i, "fname");
			$rlname = mysql_result($result, $i, "lname");
			$rmphone = mysql_result($result, $i, "mphone");
			$rhphone = mysql_result($result, $i, "hphone");
			$raddress = mysql_result($result, $i, "address");
			$remail = mysql_result($result, $i, "email");
			$rtech_level = mysql_result($result, $i, "tech_level");
	
			echo "$rid <br />";
			echo "$rfname '  ' $rlname <br />";
			echo "$rmphone <br />";
			echo "$rhphone <br />";
			echo "$raddress <br />";
			echo "$remail <br />";
			echo "$rtech_level <br />";
		
			$i++;
		}
	
?>

So the error I am getting now is: Error querying database.

Echo out your query as follows

echo $query = "SELECT * FROM CLIENT WHERE id = '$id'";

Copy that query and place it in the SQL section of phpMyAdmin. Execute it and see what is the result....

Have you checked your fieldnames jeordy? I think your last problem would is found there. Everything's seems to be fine but I can't really say for sure, but I think your fieldnames in your table is the problem. make it sure it is correct. double check.

Thanks for all you guys' help.

The issue was sort of with the connection.

It was connecting but not actually selecting a database.

So I used dbname.CLIENT in the query instead of just CLIENT and now it works flawlessly.

Now my only problem is figuring out how to format it nicely in php instead of spitting it out all in one spaceless string of text.

=P

You can use table to format your result as follows.

<?php
    $id = $_POST['clientid'];
    $fname = $_POST['clientfname'];
    $lname = $_POST['clientlname'];
     
     
    mysql_pconnect('ip', 'username', 'password')
    or die('Error connecting to MySql server.');
     
    $query = "SELECT * FROM CLIENT WHERE id = '$id'"; ?> </td>
     
    $result = mysql_query($query)
    or die('Error querying database.');
     
     
    $rownum = mysql_num_rows($result);
     
    $i=0;
?>
<table cellpadding="5" border="1" width="100%">
<?php
    while ($i <= $rownum) 
	{
		$rid = mysql_result($result, $i, "id");
		$rfname = mysql_result($result, $i, "fname");
		$rlname = mysql_result($result, $i, "lname");
		$rmphone = mysql_result($result, $i, "mphone");
		$rhphone = mysql_result($result, $i, "hphone");
		$raddress = mysql_result($result, $i, "address");
		$remail = mysql_result($result, $i, "email");
		$rtech_level = mysql_result($result, $i, "tech_level");
?>     

	<tr>
        <td><?php echo "$rid"; ?> </td>
        <td><?php echo "$rfname ' ' $rlname"; ?> </td>
        <td><?php echo "$rmphone"; ?> </td>
        <td><?php echo "$rhphone"; ?> </td>
        <td><?php echo "$raddress"; ?> </td>
        <td><?php echo "$remail"; ?> </td>
        <td><?php echo "$rtech_level"; ?> </td>
   	</tr>
<?php    
    	$i++;
    }
?>
</table>

Have you tried using mysql_fetch_array() instead of your while() loop? It may make things a bit easier for formatting.

Like this:

$query = "SELECT * FROM CLIENT WHERE id = '$id'";

$result = mysql_query($query)
        or die('Error querying database.');


while ($values = mysql_fetch_array($result)) {

    $rid = $values["id"];
    $rfname = $values["fname"];
    $rlname = $values["lname"];
    $rmphone = $values["mphone"];
    $rhphone = $values["hphone"];
    $raddress = $values["address"];
    $remail = $values["email"];
    $rtech_level = $values["tech_level"];

    echo "$rid <br />";
    echo "$rfname '  ' $rlname <br />";
    echo "$rmphone <br />";
    echo "$rhphone <br />";
    echo "$raddress <br />";
    echo "$remail <br />";
    echo "$rtech_level <br />";
}

Also, in the loop you have, you're starting $i at 0, which is correct, but mysql_num_rows() will return '2' if you have two rows that you're grabbing. So your while() loop is going to try to go while $i is less than 2 and stop when $i is equal to 2 (which would be one more row than can be grabbed, since $i starts at 0. So, you might want to change

while ($i <= $rownum) {

to

while ($i < $rownum) {

Just a thought : )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.