Porkie Posted June 15, 2009 Share Posted June 15, 2009 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 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/ Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 Well I can see 2 things 1. not stating the problem/error or what your trying to do, 2. lack of code tags maybe add a username password database name, mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856599 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 i just get a white screen , no error =/ and obviously the details ive taken out, but yeh they are fine , tested. cheers Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856603 Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 mysql_error() $result = mysql_query("SELECT * FROM Bands WHERE bandname='$bandname'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856605 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 Parse error: syntax error, unexpected T_VARIABLE in /home/myuklive/public_html/Test/Tester1.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856612 Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 post your code. Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856617 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 try replacing $result = mysql_query("SELECT * FROM Bands WHERE bandname='$bandname'"); with $sql = "SELECT * FROM Bands WHERE bandname='$bandname'"; $result = mysql_query($sql ,$con) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856618 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 Parse error: syntax error, unexpected T_VARIABLE in /home/myuklive/public_html/Test/Tester1.php on line 14 same error when i edit the file =/ Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856621 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 which is line 14, copy and paste the code from that file between code tags Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856623 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 $result = mysql_query($sql ,$con) or die(mysql_error()); ^^ line 14 Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856624 Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 His missing a ) or a ;, on line 14 or a few before that, I ask him to post his code but he hasn't so.. Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856627 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856629 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 line 13 is missing a ; at the end Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856631 Share on other sites More sharing options...
Porkie Posted June 15, 2009 Author Share Posted June 15, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856635 Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 $sql = "SELECT * FROM Bands WHERE bandname='$bandname'" should be $sql = "SELECT * FROM Bands WHERE bandname='$bandfield' " or $bandfield = $_POST['bandfield']; should be $bandname = $_POST['bandfield']; Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856642 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856644 Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 You know what.. if he doesn't start, saying thank you and clicking solved on his thread.. i'm just going to stop helping him! Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856648 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 i wish someone would help me lol Quote Link to comment https://forums.phpfreaks.com/topic/162295-confused-when-doing-databases/#findComment-856651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.