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.

keul
  • 7,673
  • 20
  • 45
Jeany
  • 37
  • 1
  • 7
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, string given](http://stackoverflow.com/questions/4901728/mysql-fetch-array-expects-parameter-1-to-be-resource-string-given) – Matheno Apr 13 '15 at 15:18
  • I am not using oop, I'm embedding html in my php, for a website. @MHakvoort – Jeany Apr 13 '15 at 15:19
  • try to print it `$confirmation` before your while loop – A l w a y s S u n n y Apr 13 '15 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. – Jeany Apr 13 '15 at 15:22

1 Answers1

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 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 – Jeany Apr 13 '15 at 19:40
  • Yes, that's the line I'm talking about. – Barmar Apr 13 '15 at 19:42
  • That was the error, duplicate variable name, because the original $result was within the while loop of the query $result execution... Thank you! @Barmar – Jeany Apr 14 '15 at 12:19
  • Thank you for confirming the obvious. – Barmar Apr 14 '15 at 12:21