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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.