Jump to content

Resolve my PHP Problem


saran.tvmalai

Recommended Posts

<?php

session_start();

 

if (!$_SESSION["user_name"])

        {

        // User not logged in, redirect to login page

        Header("Location: login.php");

        }

 

// Member only content

// ...

$con = mysql_connect('localhost','root','');

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("login", $con);

 

 

$result = mysql_query("select * from reference,users where reference.username=users.user_name AND reference.refid = '".$_POST['refid']."'");

 

 

 

while($row = mysql_fetch_array($result))

  {

  echo $row['refid'];?><br><?

  echo $row['origin'];

  echo $row['dest'];

  echo $row['date'];

  echo $row['exdate'];

  echo $row['user_name'];

  }

 

 

// ...

// ...

 

// Display Member information

//  echo "<p>User ID: " . $_SESSION["valid_id"];

//echo "<p>Username: " . $_SESSION["valid_user"];

//echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

 

// Display logout link

echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";

?>

 

 

for the above code i got error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

 

 

solve my problem

 

Link to comment
https://forums.phpfreaks.com/topic/212649-resolve-my-php-problem/
Share on other sites

That error usually indicates there is a problem with your query. Change this

$result = mysql_query("select * from reference,users where reference.username=users.user_name AND reference.refid = '".$_POST['refid']."'");

To

$query = "select * from reference,users where reference.username=users.user_name AND reference.refid = '".$_POST['refid']."'";
$result = mysql_query($query) or trigger_error('MySQL encountered a problem<br />Error: '  . mysql_error() . '<br />Query: ' . $query);

 

Run the code and post the error here

What have you done yourself to resolve your problem?

 

What I do, is to work through each point in the program which is causing an error. So for example if an SQL statement is causing an error, I put a literal into the statement and run it in a SQL query browser (independent and outside of the program). Once that is working then I make sure that the statement in the program is working. That usually gets me past the bug.

 

check the database is open correctly and the statement is working.

i got this below error again

 

 

 

Notice: MySQL encountered a problem

Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin1_general_ci,IMPLICIT) for operation '='

Query: select * from reference,users where reference.username=users.user_name AND reference.refid = '12345' in

Only strings should be wrapped in quotes. Change this

$queyr = "select * from reference,users where reference.username=users.user_name AND reference.refid = '".$_POST['refid']."'";

to

$query = "select * from reference,users where reference.username=users.user_name AND reference.refid = ". intval($_POST['refid']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.