MySQL-Link resource not valid – PHP

  php

Q(Question):

I get this error:

Warning: mysql_query(): 3 is not a valid MySQL-Link resource in C:\xampp\htdocs\Admin\deleteuser.php on line 19

And my script is:

<?php
include ('sqlcon.php');
mysql_select_db("shop",$conn);
global $conn;
$id = $_POST[id];
echo $id;
include('users.php');
if ($_POST['delete'])
{
echo 'delete';
mysql_query("DELETE FROM test WHERE id=$id",$conn);
}
else if ($_POST['info'])
{
echo 'info';
$last = mysql_query("SELECT lastname FROM test WHERE id=$id",$conn) or die(mysql_error());
echo $last;
}
$thispage = $_SERVER['PHP_SELF'];
$form_page = <<< EOFORMPAGE
<body>
<form method="POST" action="--WEBBOT-SELF--">
<p><input type="text" name="T1" value="$last"size="20"></p>
</form>
</body>
EOFORMPAGE;
echo $form_page;
?>

thanx for help.

A(Answer):

Please see this article written by Atli.

A(Answer):

Article didn’t helped for me… maby somedody can show an example of working code, or fix this?

A(Answer):

Your connection is invalid. The article Markus posted the link to does contain your answer you just didn’t read it.

"1.1. MySQL "link" resources
These tell PHP how to communicate with MySQL.

When you call mysql_connect, PHP opens a connection to the MySQL server. If successful, the connection is opened and the connection details are stored in memory. The "mysql_link" resource is a link to the memory location where those details are stored."

A(Answer):

I have chaged my script abit, now i get another error..

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\Admin\deleteuser.php on line 23

I have changed this:

$last = mysql_query("SELECT lastname FROM test WHERE id=$id",$conn) or die(mysql_error());

to this:

$getinfo = "SELECT lastname FROM test WHERE id=$id";
while ($myrow = mysql_fetch_array($getinfo))
{
$last = $myrow["lastname"];
}

i don’t understand this..

A(Answer):

I suggest you take a look at some MySQL & PHP tutorials.

A(Answer):

Your no longer preforming a query meaning you have no result for mysql to fetch an array from it’s a database not magic can’t really pluck things out of the air.

Agree with Markus but I recommend tutorialspoint.com and w3schools.com I would rate tizag.com third though.

LEAVE A COMMENT