j3rmain3 Posted September 26, 2006 Share Posted September 26, 2006 I am trying to do something so simple but its not working and i have been staring at it for sooooooooooo long.I created a form in php and want to display the data in another php site. This is the coding i have used. [size=8pt][b]php form[/b][/size][code]<html><head><title>Player Form</title><h3>Player Form</h3></head><body><?phpif (!isset($_POST['submit'])) {?><form action="<?=$_SERVER['PHP_SELF']?>" method="post">Player First Name: <input type="text" name='f_name'><p>Player Last Name: <input type="text" name='l_name'><p>Team: <input type="text" name='team'><p>Position: <input type="text" name='position'><p>Points: <input type="text" size=2 name='points'> <b> /5</b><p><input type="submit" name="submit" value="submit results"></form><?php} else {$host = "localhost";$user = "root";$pass = "mysql";$db = "player_of_year";$f_name = empty($_POST['f_name']) ? die ("ERROR: Enter In First Name") : mysql_escape_string($_POST['f_name']);$l_name = empty($_POST['l_name']) ? die ("ERROR: Enter In Last Name") : mysql_escape_string($_POST['l_name']);$team = empty($_POST['team']) ? die ("ERROR: Enter In The Team") :mysql_escape_string($_POST['team']);$position = empty($_POST['position']) ? die ("ERROR: Enter In Position") :mysql_escape_string($_POST['position']);$points = empty($_POST['points']) ? die ("ERROR: Enter In Your Rating") :mysql_escape_string($_POST['points']);$connection = mysql_connect($host,$user,$pass) or die ("Unable To Connect");mysql_select_db($db) or die ("Unable to select database!");$query = "INSERT INTO players ('f_name', 'l_name', 'team', 'position', 'points') values ('$f_name','$l_name','$team','$position','$points')";echo "Your Rating Has Been Recorded";echo "<p>";echo "<a href=http://localhost/playertable.php><b>View Table<b>";}?></body></html>[/code][size=8pt][b]php table[/b][/size][code]<html><head><title>Player Of The Year</title><h3>Player Of The Year</h3></head><body><?php$host = "localhost";$user = "root";$pass = "mysql";$db = "player_of_year";$connection = mysql_connect($host,$user,$pass) or die ("Unable to Connect!");mysql_select_db($db) or die ("Unable to select database!");$query = "SELECT * FROM players";$result = mysql_query($query) or die ("ERROR in query: $query.".mysql_error());if (mysql_num_rows($result) > 0) {echo "<table cellpadding=10 border=1>";echo "<tr>";echo "<td><p align=center><b>First Name</td></b>";echo "<td><p align=center><b>Second Name</td></b>";echo "<td><p align=center><b>Team</td></b>";echo "<td><p align=center><b>Position</td></b>";echo "<td><p align-center><b>Points</td></b>";echo "</tr>";while ($row=mysql_fetch_row($result)) {echo "<tr>";echo "<td><p align=center>".$row[1]."</td>";echo "<td><p align=center>". $row[2]."</td>";echo "<td><p align=center>".$row[3]."</td>";echo "<td><p align=center>".$row[4]."</td>";echo "<td><p align=center>".$row[5]."</td>";echo "</tr>";}echo "</table>";} else {echo "No rows found!";}mysql_free_result($result);mysql_close($connection);?><p><a href=http://localhost/playerform.php><b>Return To From</b></body></html>[/code]If anyone can see why this would work can you please inform me because i have had enough of staring at it and not finding whats wrong with it.ThanksJ3rmain3 Quote Link to comment Share on other sites More sharing options...
craygo Posted September 26, 2006 Share Posted September 26, 2006 Well first thing is you did not run your query. You made your statement but did not run the query.[code]<?php$query = "INSERT INTO players ('f_name', 'l_name', 'team', 'position', 'points') values ('$f_name','$l_name','$team','$position','$points')"; $result = mysql_query($query) or die (mysql_error());if(!result){echo "Could not run query";} else {echo "Your Rating Has Been Recorded";echo "<p>";echo "<a href=http://localhost/playertable.php><b>View Table<b>";}?>[/code]Ray Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted September 26, 2006 Author Share Posted September 26, 2006 Cheers Ray,Its working nowI knew it would be something simple.Your a legend !!J3rmain3 Quote Link to comment 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.