Jump to content

PHP and MySQL - data retrieval/input


Recommended Posts

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, the set is empty, simply siplaying an empty page 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, nothing 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 " );

if (!$result) {

echo("<p>Error performing query: " . mysql_error() . "</p> " ) ;

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.

 

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!

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.