Welcome Guest!
Please login
If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:
- Receive Fast Advice
- Learn Programming Languages
- Get Professional Website Reviews
- Quick Troubleshooting Assistance
|
|
Why Won't Connection Work?
This is a discussion on Why Won't Connection Work?, within the MySQL section. This forum and the thread "Why Won't Connection Work?" are both part of the Programming Your Website category.
![]() ![]() |
Oct 17 2008, 11:38 AM
Post
#1
|
|
|
New Squeeze ![]() Posts: 2 Joined: 3-October 08 |
here's the relevant code:
<?php DEFINE ('DB_USER','root'); DEFINE ('DB_PASSWORD',''); DEFINE ('DB_HOST','localhost'); DEFINE ('DB_NAME','citations'); //create the db connection $dbc = mysqli_connect ( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL'); var_dump($dbc); echo "<pre>"; print_r($_POST); echo "</pre>"; ///////////////////////////////////////////////////////////// $permitNum = $_POST['permitNum']; $q = "select count(permitNum) FROM permits"; //just a test query echo $q; //recommended for testing $r = mysqli_query($db, $q); if($r){echo "<h1>query worked</h1>";} //testing $duplicate_pNum = mysqli_fetch_assoc($r); print_r($duplicate_pNum); //testing and here is the relevant output: $dbc exists object(mysqli)#1 (0) { } Array ( [permitNum] => 44444 [licensePlateNum] => 44444444 [ownerFirst] => a [ownerLast] => a [addPermit] => 1 ) select count(permitNum) FROM permits Warning: mysqli_query() expects parameter 1 to be mysqli, null given in E:\xampplite\htdocs\WEB250\module5\lab4.php on line 78 Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in E:\xampplite\htdocs\WEB250\module5\lab4.php on line 80 ////////////////////////////////////////////////// I've looked around, and can't find an answer to this. I implemented some of the recommended tests (dump $dbc, echo query, etc.) but it don't help. someone recommended echoing query cuz they said there was a problem with the query, but I don't think so. There is some problem with the connection identifier. I've attached the whole file, just in case it helps. THANKS, this problem has stopped me in my tracks.
Attached File(s)
|
|
|
Oct 17 2008, 11:44 AM
Post
#2
|
|
![]() Rapid Squeezer ![]() Posts: 239 Joined: 14-February 08 From: NY, USA |
Hey anonymouse,
Looks like you have your parameters backwards in your query. Should be mysqli_query($q, $db); Try it out and see if it works. I would recommend using mysqli_select_db() to select your db if you're not using multiple db connections, and then omit the $db param from the mysqli_query(). Also, make sure you're passing $_POST vars or it will break your query. You should add an if/else to make sure. Hope this helps. Rich -------------------- |
|
|
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
12 | gribble | 557 | 19th February 2008 - 05:49 AM Last post by: welshstew |
|||
![]() |
11 | Jason | 503 | 19th March 2008 - 06:57 PM Last post by: Monie |
|||
![]() |
1 | Jason | 296 | 21st May 2008 - 11:49 AM Last post by: paintingtheweb |
|||
![]() |
1 | Jason | 190 | 26th March 2008 - 08:22 PM Last post by: christopher |
|||
![]() |
1 | LivingDeadBeat | 176 | 27th March 2008 - 03:16 PM Last post by: Rakuli |
|||






Oct 17 2008, 11:38 AM








