Try to connect to mySQL with php...nothing

I'm using Dreamweaver and php to connect to mysql on a server, but

Page 1 of 1

8 Replies - 1687 Views - Last Post: 15 August 2008 - 06:07 PM Rate Topic: -----

#1 foxkj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-August 08

Try to connect to mySQL with php...nothing

Posted 14 August 2008 - 01:47 PM

I am a beginning to programing, but am trying to create a cart-like funtion.
The page is on www.designwizardembroidery.com/dakota

If you enter 3D0108 in the box on the right and then click submit, nothing will show up in the new page.

The code for that php page is the following:


<?php
	$number=$_POST['DakotaNumber'];
	$connection=mysqli_connect ("p50mysql73.secureserver.net", "name", "password") or
		die ("I cannot connect to the database.");
	$database = "DakotaCatalog";
mysqli_select_db ($connection, $database) or die ("The Database is currently down. We apologize.");
	$nameQuery = "SELECT Name FROM DakotaDesigns WHERE Number = '$number'";
	$result = mysqli_query ($connection, $nameQuery) or
		die ("couldn't find the name or number");
mysqli_query($nameQuery);
echo $result;
mysqli_close();
?>





The $number variable gets the post from the previous page from the button.
The connection I've gone over multiple times to make sure it is right.
What is supposed to come back is under $nameQuery - the name of the design that corresponds with that number.

Question:
1) if it can't find the name should the "couldn't find the name or number" come out on the screen?
And if it can find the name, should it then echo $result?

I just want to make sure that this is getting the info from the catalog.

Thanks so much for anyone's help!

This post has been edited by foxkj: 15 August 2008 - 10:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Try to connect to mySQL with php...nothing

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Try to connect to mySQL with php...nothing

Posted 14 August 2008 - 02:10 PM

i'm not sure about mysqli, but in mysql, you can't just echo a query... you need to do a mysql_fetch_array, and then echo the corresponding column name/number
Was This Post Helpful? 0
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Try to connect to mySQL with php...nothing

Posted 14 August 2008 - 03:09 PM

View PostJBrace1990, on 14 Aug, 2008 - 04:10 PM, said:

i'm not sure about mysqli, but in mysql, you can't just echo a query... you need to do a mysql_fetch_array, and then echo the corresponding column name/number

That's right - same deal here. The mysqli_query() function returns a result set. You need to fetch each of the rows from that set to get the actual data. For example:
$result = mysqli_query ($connection, $nameQuery) or
        die ("couldn't find the name or number");
while ($row = mysqli_fetch_assoc($result)) {
    print_r($row);
}
# Note: you need to pass mysqli_close() the connection variable
mysqli_close($connection);


Was This Post Helpful? 0
  • +
  • -

#4 foxkj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-August 08

Re: Try to connect to mySQL with php...nothing

Posted 14 August 2008 - 03:22 PM

Thanks for the mysqli_close() info, its good to know.


I added the code, though, and still nothing changed.
I think I'm understanding the code right:

while ($row = mysqli_fetch_assoc($result)) {		
		print_r($row);	
		}


this means that "while the variable "row" is equal to the product of the query made in the "result" variable, then it should print (same as echo, but with variables) the variable "row"."

Is that right?
Do I need to put the "while" in there? I also tried writing

$row = mysqli_fetch_assoc($result)
print_r($row);



but that didn't work either.

Thank you so much for your help!
Was This Post Helpful? 0
  • +
  • -

#5 Moonbat  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 424
  • Joined: 30-June 08

Re: Try to connect to mySQL with php...nothing

Posted 14 August 2008 - 06:40 PM

View Postfoxkj, on 14 Aug, 2008 - 01:47 PM, said:

The code for that php page is the following:


<?php
	$number=$_POST['DakotaNumber'];
	$connection=mysqli_connect ("p50mysql73.secureserver.net", "DakotaCatalog", "D1kot1C1t1log") or
		
?>



Is that your actual username and password? I would change that as soon as possible.
Was This Post Helpful? 0
  • +
  • -

#6 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: Try to connect to mySQL with php...nothing

Posted 15 August 2008 - 01:04 AM

Eeek!!

Yeah I would star those bad boys asap, and change your password asap as anyone bored and immature enough will have taken those details down and got ready to have a party in your databases pants :o

Have you tried
 while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {  
	 echo $row['Name'];
 }  


Was This Post Helpful? 0
  • +
  • -

#7 foxkj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-August 08

Re: Try to connect to mySQL with php...nothing

Posted 15 August 2008 - 10:23 AM

No:) thats not the password...I just wanted it to look real so that you knew that I was putting in the right thing. But I changed it on my post anyways.

So I tried the new one, but still nothing shows up.

I really just need a way to move the number that is put in on the first page:
www.designwizardembroidery.com/design.html

Into the form for buying through the paypal button:

<form target="paypal" action="this is filled in right" method="post">
  <input type="hidden" name="cmd" value="_cart" />
  <input type="hidden" name="add" value="1" />
  <input type="hidden" name="bn" value="webassist.dreamweaver.4_5_0" />
  <input type="hidden" name="business" value="my email" />
[b]  <input type="hidden" name="item_name" value="$name" />
  <input type="hidden" name="item_number" value= "$itemNumber" />[/b]
  <input type="hidden" name="amount" value="100" />
  <input type="hidden" name="currency_code" value="USD" />
  <input type="hidden" name="receiver_email" value="my email" />
  <input type="hidden" name="mrb" value="R-3WH47588B4505740X" />
  <input type="hidden" name="pal" value="ANNSXSLJLYR2A" />
  <input type="hidden" name="no_shipping" value="0" />
  <input type="hidden" name="no_note" value="0" />
  <input type="image" name="submit" src="http://images.paypal.com/images/x-click-but22.gif" border="0" alt="Make payments with PayPal - it's fast, free and secure!" />
</form>




This is in html. I need to take the name from the database and put it in the form so that it ends up in the paypal cart.

Is this even possible?


Thanks so much!
Was This Post Helpful? 0
  • +
  • -

#8 foxkj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 14-August 08

Re: Try to connect to mySQL with php...nothing

Posted 15 August 2008 - 11:52 AM

So I think I found the first problem in my script...
I don't think I'm actually taking the user imput from the first page and putting it into a variable on the second page....still searching the internet on that issue.

Here's that code:
<form id="Dakota number" name="Dakota number" method="post" action="addtocart.php">
	
		<label>Dakota Design Number 
		<input name="DakotaNumber" type="text" id="DakotaNumber" size="6" maxlength="6" minlength="6"/>
		</label>
				  <p>
					<label>
					<input name="Add to cart" type="submit" id="addtocart_btn" value="Submit" />
					
					</label>
		  </p>
	  </form>





I do use the method "post" but is that all I need?

my next page (addtocart.php) calls the imput by this code:


$number=$_GET['DakotaNumber'];





Again, thanks for any insights.
Was This Post Helpful? 0
  • +
  • -

#9 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Try to connect to mySQL with php...nothing

Posted 15 August 2008 - 06:07 PM

you can't mix post and get... if you're posting "DakotaNumber", you can't use $_GET to get it, you need to change it to $_POST
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1