0
$con = mysql_connect("localhost","root","");    
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("vinzq", $con);
session_start();
$confirmation = $_SESSION['confirm'];

$result = mysql_query("SELECT * FROM reservation WHERE confirmation = '$confirmation'");

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

    $arrival = $row['arrival'];
    $departure = $row['departure'];
    $adults = $row['adults'];
    $child = $row['child']; 
    $nroom = $row['no_room'];
    $result = $row['result'];
    $name = $row['firstname'];
    $last = $row['lastname'];
    $city = $row['city'];
    $zip = $row['zip'];
    $country = $row['country'];
    $password = $row['password'];
    $email = $row['email'];
    $cnumber = $row['contact'];
    $stat= 'Active';
}

I have my codes here written in php. At the bottom after this code snippet, I have used html to display out the different variables. The values of the variables are correct, however the error that

mysql_fetch_array() expects parameter 1 to be resource, string given,

still pops up even tho it's functional. The error seems to belong to the while statement line.

4
  • possible duplicate of mysql_fetch_array() expects parameter 1 to be resource, string given Commented Apr 13, 2015 at 15:18
  • I am not using oop, I'm embedding html in my php, for a website. @MHakvoort Commented Apr 13, 2015 at 15:19
  • try to print it $confirmation before your while loop Commented Apr 13, 2015 at 15:20
  • I have printed $confirmation out, and it is the same as the session variable being stored. @BeingSunny I think it is correct also, because the data it prints out like all the $arrival, $departure etc are all correct. I can get what I want, but it just shows that error over there. Commented Apr 13, 2015 at 15:22

1 Answer 1

1

The problem is this line inside the while loop:

$result = $row['result'];

The first time through the loop, $result contains the result of mysql_query(). The second time, it contains the value of this field from the first row of results, so mysql_fetch_array($result) tries to use this string instead of the original query result.

Use different names for these two variables.

Sign up to request clarification or add additional context in comments.

4 Comments

I don't have a line that reads: $result = $row['result']; are you talking about the data nested within the while loop? Like $arrival = $row['arrival'];? Sorry haven't been touching php for some time @Barmar
Yes, that's the line I'm talking about.
That was the error, duplicate variable name, because the original $result was within the while loop of the query $result execution... Thank you! @Barmar
Thank you for confirming the obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.