dh526 Posted May 26, 2009 Share Posted May 26, 2009 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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/ Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 Can anyone help with this?? I don't really know what the null pointer error means an even google isn't that much help !! arrggg :S any help would be much appreciated Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842351 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi $rs3=odbc_exec($conn, $sq2); $rs1=odbc_num_rows($rs); Shouldn't that be $rs3 as a parameter to odbc_num_rows? All the best Keith Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842361 Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842391 Share on other sites More sharing options...
corbin Posted May 26, 2009 Share Posted May 26, 2009 $conn=odbc_pconnect('db09','',''); Fairly certain 'db09' is not a valid ODBC connection string. You need to format a string correctly, depending on what kind of SQL server you're using. Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842406 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi $rs3=odbc_exec($conn, $sql2); Fairly certain 'db09' is not a valid ODBC connection string. Would be fine if set up as an odbc dsn. All the best Keith Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842409 Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 '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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842451 Share on other sites More sharing options...
corbin Posted May 26, 2009 Share Posted May 26, 2009 Ahhh yeah, was thinking that for some reason PHP required full ODBC strings ;p. Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842457 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842462 Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842475 Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 Actually the error goes like this : /[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ProductID=1/. What syntax am I missing???? Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842480 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 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 https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842482 Share on other sites More sharing options...
dh526 Posted May 26, 2009 Author Share Posted May 26, 2009 It does execute twice and its fine I was being a plonker and had value=1/> so it thought the / was part of the value. Annoying error Thanks guys Link to comment https://forums.phpfreaks.com/topic/159701-solved-microsoftodbc-microsoft-access-driverinvalid-use-of-null-pointer/#findComment-842487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.