Empty set (PHP and MYSQL in Wampserver)?
Posted by: SwedishBerzerker (---.02-40-73746f5.cust.bredbandsbolaget.se)
Date: May 01, 2011 02:36PM

DON'T MIND THIS POST - PLEASE READ MY LATEST INSTEAD



I'm sorry if this isn't the place to ask about PHP and MySQL syntax, but this is kind of specific to Wampserver (I copied the retrieval code from a page, and it didn't work on Wampserver). I'm using Wampserver to create a website in HTML/PHP. I use localhost to test it, and after having submitted the form with all the information, and it has put this information into the table, all I get is "Resouce id # 4" after clicking on "Se all data". It's in Swedish, but I hope you'll be able to make it out anyway. Basically, you first et the links at the bottom, then, by clicking on one of them, you get to the form at the top. Submit, and you're back to the first page. When clicking the second link, "Resource id # 4" is displayed.

So here's my code:

<html>
<head>
<title> --- </title>
</head>
<body>


<?php if(isset($_GET["addprod"])) { ?>

<form action="DBH13 PHP.php" method="post">
<p>Skriv in produktens titel (max 20 tecken): <br />
<textarea name="ProduktTitel" rows="1" cols="20" wrap></textarea><br />
<p>Skriv in produktens pris (',' mellan kronor och ören) (max '9999,99'): <br />
<textarea name="ProduktPris" rows="1" cols="6" wrap></textarea><br />
<p>Skriv in produktens status ('0' för ny, '1' för begagnad): <br />
<textarea name="ProduktStatus" rows="1" cols="1" wrap></textarea><br />
<p>Skriv in produktens ASIN (max tio tecken): <br />
<textarea name="ProduktASIN" rows="1" cols="10" wrap></textarea><br />
<p>Skriv in produktens typ ('CD' eller 'DVD') (max tre tecken): <br />
<textarea name="ProduktTyp" rows="1" cols="3" wrap></textarea><br />
<p>Skriv in produktens produktionsår (t.ex. '2001') (max fyra siffror): <br />
<textarea name="ProduktÅr" rows="1" cols="4" wrap></textarea><br />
<p>Skriv in bandnamnet (max 20 tecken): <br />
<textarea name="ProduktBandNamn" rows="1" cols="20" wrap></textarea><br />
<p>Skriv in bandets genre (behövs inte om bandet redan finns i databasen) (max 20 tecken): <br />
<textarea name="ProduktBandGenre" rows="1" cols="20" wrap></textarea><br />
<p>Skriv in albumets skivbolag (max 30 tecken): <br />
<textarea name="ProduktBolagNamn" rows="1" cols="30" wrap></textarea><br />
<input type="submit" name="submitprodukt" value="Lagg till" /></p>
</form>


// THE FOLLOWING IS SUPPOSED TO FIRST LOOK IF THE DATA ALREADY EXISTS IN THE TABLE, THEN INSERT.

<?php
if (isset($_POST['submitprodukt'])) {

$BandIDquery = "SELECT BandID FROM Band WHERE BandNamn LIKE '$_POST[ProduktBandNamn]'";
if (@mysql_query($BandIDquery)) {
$BandID = @mysql_query($BandIDquery);
}
else {
echo("<P>Bandet finns inte sedan tidigare. Lagger till nytt band.</P>" );
$ProdNyttBandNamnquery = "INSERT INTO Band SET BandNamn = '$_POST[ProduktBandNamn]', GenreNamn = '$_POST[ProduktBandGenre]'";
if (@mysql_query($ProdNyttBandNamnquery)) {
echo("<P>Bandet ar tillagt.</P>" );
$BandID = @mysql_query($BandIDquery);
}
else {
echo("<P>MYSQL Error: " . mysql_error() . "</P>" ) ;
}
}
}
}



// THE FOLLOWING IS SUPPOSED TO RETRIEVE THE DATA IN THE TABLE

else if(isset($_GET["retdata"])) {
$dbkon = @mysql_connect("localhost", "C:\DBH13\DBH13 MYSQL-kod.mysql", " " ) ;
if (!$dbkon) {
echo( "<p>Kunde inte ansluta till servern för tillfället.</p> " );
exit();
}
else if (! @mysql_select_db("test" ) ) {
echo( "<p>Kunde inte hitta databasen..</p > " ) ;
exit();
}

$result = @mysql_query("SELECT * FROM Ex"winking smiley;
if($result){
echo($result);
}
else{
echo("<p>Error performing query: " . mysql_error() . "</p>"winking smiley;
exit();
}

else {

$dbkon = @mysql_connect("localhost", "C:\DBH13\DBH13 MYSQL-kod.mysql", " " ) ;
if (!$dbkon) {
echo( "<p>Kunde inte ansluta till servern för tillfället.</p>" );
exit();
}
else if (! @mysql_select_db("test" ) ) {
echo( "<p>Kunde inte hitta databasen..</p >" );
exit();
}


//THE FOLLOWING IS THE FIRST THE USER WILL SEE: TWO LINKS, THE FIRST TO THE FORM AT THE TOP, THE SECOND TO THE ELSE IF-STATEMENT ABOVE.

echo("<p><a href='http://localhost/Projekt/DBH13%20PHP.php?addprod=1'>Lägg till en produkt</a></p> " ) ;
echo("<p><a href='http://localhost/Projekt/DBH13%20PHP.php?retdata=1'>Se all data</a></p>" ) ;
}


?>


</body>
</html>



The retrieval statement is in the last else-statement. I don't know if it's the retrieval or the input of data that isn't correct. Currently, all I get is "Resource id # 4" when retrieving data.

I'd really appreciate if someone could help me here, I have no experience with Wampserver and I'm a total beginner at PHP. I do have some experience in Java however.

Thanks a ton in advance!



Edited 4 time(s). Last edit at 05/01/2011 10:05PM by SwedishBerzerker.

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: yfastud (Moderator)
Date: May 01, 2011 05:02PM

Since this forums is for Wampserver, not coding, recommend you should join some coding forums for help with scripting winking smiley

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: SwedishBerzerker (---.02-40-73746f5.cust.bredbandsbolaget.se)
Date: May 01, 2011 08:39PM

I just thought this problem was specific to Wampserver, that's all. I have solved this through another forum now anyway, but thanks!

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: SwedishBerzerker (---.02-40-73746f5.cust.bredbandsbolaget.se)
Date: May 01, 2011 10:09PM

New question, this time it's about Wampserver. My code seems to be correct, but when I try to retrieve information, nothing is returned. I believe this is casued by the fact that I never really created any database. So I'm wondering:

How do I create the database and its tables? Should I do that in the PHP script?

Do I need to even touch the MySQL console when working with the database through PHP?

Where exactly is the database? What values should I use in the "@mysql_connect("localhost", "root", ""winking smiley;"-thing?


And I only use localhost to try the PHP script, never phpMyAdmin or any of that.

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: yfastud (Moderator)
Date: May 02, 2011 05:32AM

You should setup Backup right after setup Wamp successful, so you can go back if something wrong later
To setup Backup, follow this
[blog.jlbn.net]

To setup Password, follow this
[blog.jlbn.net]

To setup Website w/ Wamp, follow this
[blog.jlbn.net]

To setup Database Account, follow this
[blog.jlbn.net]

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: Grand (---.zp.velton.ua)
Date: May 26, 2011 11:54AM

Don't waste your time, as for me better to use form builder

Options: ReplyQuote
Re: Empty set (PHP and MYSQL in Wampserver)?
Posted by: SwedishBerzerker (---.02-40-73746f5.cust.bredbandsbolaget.se)
Date: May 26, 2011 08:48PM

Grand Wrote:
-------------------------------------------------------
> Don't waste your time, as for me better to
> use form builder


This wasn't just a form, it was an entire website designed to edit and create posts in MySQL through PHP. But I solved this problem a long time ago smiling smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.