Jump to content

[SOLVED] [Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer


dh526

Recommended Posts

Hi everyone and thank you for looking :)

 

This is the error message I get when sending information between the 2 pages below.

 

[Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer

 

I also pass the variable across and it gives the output of product: 1 so this works properly :S

 

basket.php which sends either 0 or 1 to basket.php. $_username is stored in a cookie.

 

<?php

if ($set==1)
{ echo "<br><br><h2>6 months subscription</h2><br><img src='magazine.png', width='100%'/><br><br><form method='POST' action='basket.php'><table><tr><td> Price : </td> <td> £20 <input type='hidden' name='product' value='1'/></td> </tr><tr><td> Description : </td> <td> 6 issues of tech! magazine delivered to your door </td></tr><tr><td>                                                                                                               <input type='submit' value='Buy 6 months subscription Now'></td></tr></table></form><img src='line1.png' width='100%'><br><br><br><br><h2>12 months subscription </h2><br><img src='magazine.png', width='100%'/><br><br><form method='POST' action='basket.php'><table><tr><td> Price : </td> <td> £30 <input type='hidden' name='product' value='2'/></td></tr><tr><td> Description : </td> <td> 12 issues of tech! magazine delivered to your door </td></tr><tr><td> <input type='submit' value='Buy 12 months subscription Now'></td></tr></table></form><br><img src='line1.png' width='100%'><br><br>";
}
else
{ echo "You need to be signed in to view this page : please <a href='login1.php'>login</a> or <a href='register1.php'>register</a>";
}	
?>	

 

This is basket.php which should display the product that has been bought.

<?php 


				$conn=odbc_pconnect('db09','','');

				// -------------- TEST 


				$sql2="SELECT ProductID, myname, Cost, Description FROM tblProducts WHERE ProductID='$product'";


$rs3=odbc_exec($conn, $sq2);
$rs1=odbc_num_rows($rs);

function best_odbc_num_rows($r1)  {

ob_start(); // block printing table with results

(int)$number=odbc_result_all($r1); 

ob_clean(); // block printing table with results

return $number;

}
$rs4=best_odbc_num_rows($rs3);

echo $rs4;

				// end of test



				if (odbc_error())
         {
               echo odbc_errormsg($conn);
         }
         
         
$product = $_POST['product'];
echo "product : ";
echo $product;

$sqladd="SELECT AddressID, HouseNumber, Street, Town, Postcode FROM tblAddress WHERE username='$username'";
$sqlcard="SELECT cardid, username, myname, type, mynum, exp, sec FROM tblCard WHERE username='$username'";
$sqlcust="SELECT username, Password, Surname, Forename, DOB, [Email Address] FROM tblCustomer WHERE username='$username'";
$sqlprod="SELECT ProductID, myname, Cost, Description FROM tblProducts WHERE ProductID='$product'";

$rsadd=odbc_exec($conn, $sqladd);
$rscard=odbc_exec($conn, $sqlcard);
$rscust=odbc_exec($conn, $sqlcust);
$rsprod=odbc_exec($conn, $sqlprod);

if (odbc_fetch_row($rscard))
{
$cardid=odbc_result($rsadd,"cardid");
$type=odbc_result($rscard,"type");
$mynum=odbc_result($rscard,"mynum");

}

if (odbc_fetch_row($rsadd))
{
$housenumber=odbc_result($rsadd,"HouseNumber");
$street=odbc_result($rsadd,"Street");
$town=odbc_result($rsadd,"Town");
$postcode=odbc_result($rsadd,"Postcode");
$addid=odbc_result($rsadd,"AddressID");
}



if (odbc_fetch_row($rscust))
{
$forename=odbc_result($rscust,"Forename");
$surname=odbc_result($rscust,"Surname");
}

if (odbc_fetch_row($rsprod))
{
$name=odbc_result($rsprod,"myname");
$cost=odbc_result($rsprod,"Cost");
$description=odbc_result($rsprod,"Description");
$prodid=odbc_result($rsprod,"ProductID");

}

if ($set==1)
{
echo "<h1>Order details</h1><br><br><form Action='buy.php' Method='POST'> Name: $forename $surname <br> Delivery Address: $housenumber $street, $town, $postcode -- <a href='address.php'>add/edit address details</a><br> <br> card used: $type ( $mynum ) -- <a href='card.php'>add/edit card details</a> <br> <br> <h3>item bought</h3><br> Name:$name <br> Cost: $cost <br> Description:$description <br><br><input type='hidden' value=$username name='username1'> <input type='hidden' value=$cardid name='cardid'><input type='hidden' value=$addid name='addid'> <input type='hidden' value=$email name='email'> <input type='submit' value='confirm order'> </form>";
}
else
{ echo "You need to be signed in to view this page : please <a href='login1.php'>login</a> or <a href='register1.php'>register</a>";
}	
?>	

 

 

Link to comment
Share on other sites

You are right, and yes it should, but It has no effect on the output... i still get the "[Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer " output from "echo odbc_errormsg($conn);" and I don't know why..??

 

Does anyone know why that error is occuring?

 

Thanks for looking :)

Link to comment
Share on other sites

'db09' is set up as a DSN :) and that works fine on many other forms...

 

I think the issue is with passing the $product (either 1 or 2) to the tblProducts table. This does however return 1 (as there is 1 record) with the best_num_rows() function mind, so surely I can search with the value sent from the other page ($product) and search tblProducts. I think i have an error in these bits...:

$product = $_POST['product'];
echo "product : ";
echo $product;

$sqlprod="SELECT ProductID, myname, Cost, Description FROM tblProducts WHERE ProductID=$product";

$rsprod=odbc_exec($conn, $sqlprod);

 

if (odbc_fetch_row($rsprod))
{
$prodid=odbc_result($rsprod,"ProductID");
$myname=odbc_result($rsprod,"myname");
$cost=odbc_result($rsprod,"Cost");
$description=odbc_result($rsprod,"Description");


echo $myname;
echo $cost;
echo $description;
echo $prodid;

}

 

when i echo out the variables I get nothing :(

 

 

Link to comment
Share on other sites

Hi

 

Well you haven't set $product to anything before setting up the SQL string at the top. You set $product later on before the second attempt at that SQL, but that is after you are getting the error message.

 

Also if ProductID is a numeric field M$ Abcess is not going to appreciate having quotes around it.

 

All the best

 

Keith

Link to comment
Share on other sites

Arrrggg, had it working for a moment, and now its gone :S was to do with the value='1' instead of =1 :S amateurish error :(

 

Anyway, now I am getting this error ... :

 

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ProductID='.

 

at the moment my query looks like this:

$sqlprod="SELECT ProductID, myname, Cost, Description FROM tblProducts WHERE ProductID=$product";

 

however if I change it to ='$product' I get a type mismatch... Arrrgggg

 

I.HATE.MICROSOFT.

 

 

 

Link to comment
Share on other sites

Hi

 

You have "SELECT ProductID, myname, Cost, Description FROM tblProducts WHERE ProductID='$product'" twice. Both are executed but the first is before $product is set up and I would expect it to fail. Is it that one or the other that is failing?

 

All the best

 

Keith

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.