Jump to content

confused when doing databases ..


Porkie

Recommended Posts

hey where am i going wrong here? im new to databases and are confused on what ive done wrong ?

 

Tester 2.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<form id="form1" name="form1" method="post" action="Tester1.php">

  <label>

  <input name="bandfield" type="text" id="bandfield" />

  </label>

  <label>

  <input type="submit" name="Submit" value="Submit" />

  </label>

</form>

 

 

</body>

</html>

 

Tester 1.php

<?php

 

$bandfield = $_POST['bandfield'];

 

$con = mysql_connect("localhost","","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("", $con);

 

$result = mysql_query("SELECT * FROM Bands

WHERE bandname='$bandname'");

 

while($row = mysql_fetch_array($result))

  {

  echo $row['bandname'] . " " . $row['genre'];

  echo "<br />";

  }

?>

 

Very confused here help is much appreciated :D

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/
Share on other sites

That is the code

 

Tester1.php

<?php

 

$bandfield = $_POST['bandfield'];

 

$con = mysql_connect("localhost","myuklive_forum","615455");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("myuklive_Bands", $con);

 

$sql = "SELECT * FROM Bands WHERE bandname='$bandname'"

$result = mysql_query($sql ,$con) or die(mysql_error());

 

while($row = mysql_fetch_array($result))

  {

  echo $row['bandname'] . " " . $row['genre'];

  echo "<br />";

  }

?>

 

Tester2.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<form id="form1" name="form1" method="post" action="Tester1.php">

  <label>

  <input name="bandfield" type="text" id="bandfield" />

  </label>

  <label>

  <input type="submit" name="Submit" value="Submit" />

  </label>

</form>

 

 

</body>

</html>

thanks yeh dont get an error anymore however results dont show up from the database?

 

just a blank white screen when typing in what im after ,

 

does the Tester2 Form send the "bandfield" across to the Tester2 form or have i done summit or need to put something into make it work?

 

cheers

Also you input tags inside labels

 

should be more like

 

<form id="form1" name="form1" method="post" action="Tester1.php">
  <label>PUT A LABEL HERE</label>
  <input name="bandfield" type="text" id="bandfield" />
  <input type="submit" name="Submit" value="Submit" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.