$result = mysql_query($query); 2nd parameter?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 10
Joined: Wed May 30, 2012 12:20 am

Sun Sep 30, 2012 11:14 pm

I am starting a basic PHP system that can display information from a mysql database to fully understand PHP.

I found a basic tutorial on YouTube to create one... I have gotten the code to connect to the localized server by creating a record, but nothing displays in the browser... I can see a record being added when I view the database in PHPmyadmin.

When my code is rendered in the browser the form to add a record (obviously) loads, but nothing no data that should be within the while loop.

I get an error message "
Warning: mysql_result() expects at least 2 parameters, 1 given in [pathname]
Invalid query:"

searched and tried to find an answer. php.net manual is dry and gives me this: mysql_result ( resource $result , int $row [, mixed $field = 0 ] )

I have added another parameter:
$result = mysql_result($query,'*'); and then I get the error:

"Warning: mysql_result() expects parameter 1 to be resource, string given in [pathname]
Invalid query:"

To review what a resource is I find a stackoverflow answer that proves why I decided to try my second attempt.

while($row = mysql_fetch_array($password)) { <-------- $password as resource
$password = $row['password']; <-------- $password as string

THEN, someone had a simular example like my code on another forum, and an individual wrote that the logic was awful and to rewrite it......

I am just making a simple CRUD php template to interact with a database... I am not the best programer, does anyone know how to use 2 parameters using mysql_query(1p,2p);?

It is getting a little overwhelming when I try to find an answer to this problem and I see people responding, "use mysqli_query... wow, I just want to grasp mysql, then I could move on to mysqli.

Here is the code I am getting the errors with:

Code: Select all

	include "./includes/connection.php";
	$query = "SELECT * FROM people";
	$result = mysql_result($query,'*');
	if(!$result) {
		die('Invalid query: ' . mysql_error());
	while($person = mysql_fetch_array($result)) {
		echo "<h3>" . $person['Name'] . "</h3>";
		echo "<p>" . $person['Description'] . "</p>";
		<h1>Create a user</h1>
        <form action="create.php" method="post">
        Name:<input type="text" name="inputName" value="" /><br />    
        Description:<input type="text" name="inputDesc" value="" /><br />
        <input type="submit" name="submit" />

New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Mon Oct 01, 2012 1:43 am

Try :

Code: Select all

   $result = mysql_query("SELECT * FROM people");

New php-forum User
New php-forum User
Posts: 10
Joined: Wed May 30, 2012 12:20 am

Mon Oct 01, 2012 5:49 pm

Thank You!! :) It works! well displaying the information! I cannot thank you enough, I was stressing over this just thinking about it.

I committed out:

//$query = "SELECT * FROM people

then used the code above and poof! It worked!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: hyper and 2 guests