Jump to content

Please tell me why I cant get this connection to work It's driving me nuts!!!!


PHP_Idiot

Recommended Posts

The below is the entire code for a page on my site, it should record info via a form then post the saved data back to the database.

The form works, the results record the connection is made but nothing uploads to the DB.

I've spent all day trying to work it out and got no where, I've had friends look at it and they can't see the problem either.

 

Please help!

 

<!DOCTYPE HTML PUBLIC "-//SoftQuad//DTD HoTMetaL PRO 5.0::19981022::extensions to HTML 4.0//EN" "hmpro5.dtd"> 
<html>
<head>
<?php
//set variables from form fields
$Day = $_POST['Day'];
$Month = $_POST['Month'];
$Year = $_POST['Year'];
$Venue = $_POST['Venue'];
$PlayerNo = $_POST['PlayerNo'];
$beensubmited = $_POST['beensubmited'];
$table = "Player";
$table2 = "Results";

for ($PN = 1; $PN <= $_POST['PlayerNo']; $PN++) 
{
	${"MembershipNo$PN"} = $_POST["MembershipNo$PN"];
}

/* Data for SQL-server */ 
$host= "localhost";     /* Address of database server */ 
$user= "XXXX";          /* FTP-username */ 
$password= "XXXX";         /* FTP-Password */ 
$database= "XXXX";         /* name of database */ 


/* Accessing SQL-Server and querying table */ 
MYSQL_CONNECT($host, $user, $password) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");

//mySQL queries
$query = MYSQL_QUERY("SELECT * FROM $table"); 
$query2 = "INSERT into $table2 values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '$Position')";

//Javascript stuff
print("<SCRIPT type=\"text/javascript\">
function showFN(ID, FNnum, LNnum) {      ");

while($row  =  mysql_fetch_row($query))  {

print("
	if (ID =='$row[0]') {document.getElementById(FNnum).value='$row[1]';	document.getElementById(LNnum).value='$row[3]'; }
	else		"); //php end print	
}   //php end while

print("{document.getElementById(FNnum).value='ID Not In Database';}	}
</SCRIPT>");
?>


<title>GB Poker Club - Admin Area</title>
</head>
<body>
<h1>Tournament Details</h1>



<?php
//top form copies over venue details BEFORE SUBMITTING
if($beensubmited ==""){
echo '<table border="1" cellspacing="0" bgcolor="lightgrey" bordercolor="darkgrey">';
echo '<caption align="left"><h3>Venue Details</h3></caption>';
echo "<tr><th>Venue</th><th>Date</th><th>Number of Players</th></tr>";
echo "<tr><td align='center' valign='center'>";
  echo "$Venue";
  echo "</td><td align='center' valign='center'>";
  echo "$Day / $Month / $Year";
  echo "</td><td align='center' valign='center'>";
  echo "$PlayerNo";
  echo "</td></tr></table>";
  echo '<br>';

//create Points array per player
$pointsArray = array( 
   1 => 500, 
   2 => 350, 
   3 => 250,
   4 => 200,
   5 => 150,
   6 => 100,
   7 => 75,
   8 => 50,
  ); 

//creates hidden form!
print("<form name=\"userform\" method=\"POST\" action=\"createform3.php\">
<table border=\"1\" cellspacing=\"0\" bgcolor=\"lightgrey\" bordercolor=\"darkgrey\" align=\"left\">
<caption align=\"left\"><h3>Venue Results</h3></caption>
<tr><th>Position</th>
<th>Points</th><th>Membership Number</th><th>First Name</th><th>Last Name</th></tr>
<input name=\"Venue\" type=\"hidden\" value=\"$Venue\">
<input name=\"Date\" type=\"hidden\" value=\"$Year-$Month-$Day\">
<input name=\"Date\" type=\"hidden\" value=\"$Year-$Month-$Day\">
<input name=\"PlayerNo\" type=\"hidden\" value=\"$PlayerNo\">
<input name=\"beensubmited\" type=\"hidden\" value=\"Y\">");

//Creates counter to name individual cells
for ( $counter = 1; $counter <= $PlayerNo; $counter += 1) {
$points = isset($pointsArray[$counter]) ? $pointsArray[$counter] : 25; ;

//produces querys form
print("<tr><td align=\"center\" valign=\"center\"> $counter</td><td align=\"center\" valign=\"center\">
$points</td><td align=\"center\" valign=\"center\">
<input name=\"Position$counter\" type=\"hidden\" value=\"$counter\">
<input name=\"MembershipNo$counter\" type=\"text\" size=\"7\" maxlength=\"7\" tabindex=\"$counter\"onChange=\"showFN(this.value, 'FirstName$counter', 'LastName$counter');\">
</td><td align=\"center\" valign=\"center\">
<input name=\"FirstName$counter\" type=\"text\" size=\"15\" maxlength=\"7\" READONLY=\"READONLY\">
</td><td align=\"center\" valign=\"center\">
<input name=\"LastName$counter\" type=\"text\" size=\"15\" maxlength=\"7\" READONLY=\"READONLY\">
</td></tr>");
}
//submit Button
print("</table><br>
<input type=SUBMIT name=action value=\"Done!\">
</form>");

} // end beensubmited blank

// Adds form data to DB AFTER SUBMITTING
if($beensubmited =="Y"){

foreach($_POST as $k=>$v) $$k=$v;
{
	//mysql_db_query ($database, $query2, $link);
	$result = mysql_query($query2)
	or die ("couldn't do it!");
	print("$query2");
}
}
?>
<!-- Script Size:  0.53 KB -->
</body>
</html>

Link to comment
Share on other sites

$con = mysql_connectT($host, $user, $password) or die ( "<H3>Server unreachable</H3>");

$db = mysql_connect($database) or die ( "<H3>Database non existent</H3>");

 

you need to be able to assign your resources to...

 

Ok I assigned them to variables as you suggested and included them at the end in this statement:

foreach($_POST as $k=>$v) $$k=$v;
{
	$result = mysql_query($con, $db, $query2)
	or die ("couldn't do it!");
	print("$query2");
}

But all I get is the results of the Print("query2"); but nothing is uploaded!

 

Any other ideas?

(pretty please)

Link to comment
Share on other sites

mate not being funny but have you rtm???

 

A fair point... I had before but it made no sense, so I revisited it. This time it made more sense anmd I came up with:

if($beensubmited =="Y")
{

// Connect
$link = mysql_connect($host, $user, $password)
	OR die(mysql_error());
if (!$link) {
	die('Could not connect: ' . mysql_error());
			}
echo 'Connected successfully';


// Query
$query3 = "INSERT into $table2 values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '$Position')";
$result = mysql_query($query3);
}

 

Now I get a nice little message saying Connected successfully, but still nothing is being loaded into the DB!?

I've tried honestly, in fact i've been at this for nearly 12hours now!!! I'm new to php and this is driving me freaking nuts, I'm prepared to beg for help if it makes any difference?

 

Link to comment
Share on other sites

Can you post the whole code, and also the database schema.

 

I see problems lol.

 

I'd love to...the page code is below, as for DB schema...eh! how do I do that?

 

Heres the code, but I've tried so many things to get it working I think I broke it again!!

<!DOCTYPE HTML PUBLIC "-//SoftQuad//DTD HoTMetaL PRO 5.0::19981022::extensions to HTML 4.0//EN" "hmpro5.dtd"> 
<html>
<head>
<?php
//set variables from form fields
$Day = $_POST['Day'];
$Month = $_POST['Month'];
$Year = $_POST['Year'];
$Venue = $_POST['Venue'];
$PlayerNo = $_POST['PlayerNo'];
$beensubmited = $_POST['beensubmited'];
$table = "Player";
$table2 = "Results";
$Date = $_POST['Date'];

for ($PN = 1; $PN <= $_POST['PlayerNo']; $PN++) 
{
	${"MembershipNo$PN"} = $_POST["MembershipNo$PN"];
}

/* Data for SQL-server */ 
$host= "localhost";     /* Address of database server */ 
$user= "benn";          /* FTP-username */ 
$password= "86gh44bn";         /* FTP-Password */ 
$database= "gbpokerclub_benn";         /* name of database */ 


/* Accessing SQL-Server and querying table */ 
$con = MYSQL_CONNECT($host, $user, $password) or die ( "<H3>Server unreachable</H3>");
$db = MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");

//mySQL queries
$query = MYSQL_QUERY("SELECT * FROM $table"); 
$query2 = "INSERT into $table2 values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '$Position')";

//Javascript stuff
print("<SCRIPT type=\"text/javascript\">
function showFN(ID, FNnum, LNnum) {      ");

while($row  =  mysql_fetch_row($query))  {

print("
	if (ID =='$row[0]') {document.getElementById(FNnum).value='$row[1]';	document.getElementById(LNnum).value='$row[3]'; }
	else		"); //php end print	
}   //php end while

print("{document.getElementById(FNnum).value='ID Not In Database';}	}
</SCRIPT>");
?>


<title>GB Poker Club - Admin Area</title>
</head>
<body>
<h1>Tournament Details</h1>



<?php
//top form copies over venue details BEFORE SUBMITTING
if($beensubmited ==""){
echo '<table border="1" cellspacing="0" bgcolor="lightgrey" bordercolor="darkgrey">';
echo '<caption align="left"><h3>Venue Details</h3></caption>';
echo "<tr><th>Venue</th><th>Date</th><th>Number of Players</th></tr>";
echo "<tr><td align='center' valign='center'>";
  echo "$Venue";
  echo "</td><td align='center' valign='center'>";
  echo "$Day / $Month / $Year";
  echo "</td><td align='center' valign='center'>";
  echo "$PlayerNo";
  echo "</td></tr></table>";
  echo '<br>';

//create Points array per player
$pointsArray = array( 
   1 => 500, 
   2 => 350, 
   3 => 250,
   4 => 200,
   5 => 150,
   6 => 100,
   7 => 75,
   8 => 50,
  ); 

//creates hidden form!
print("<form name=\"userform\" method=\"POST\" action=\"createform4.php\">
<table border=\"1\" cellspacing=\"0\" bgcolor=\"lightgrey\" bordercolor=\"darkgrey\" align=\"left\">
<caption align=\"left\"><h3>Venue Results</h3></caption>
<tr><th>Position</th>
<th>Points</th><th>Membership Number</th><th>First Name</th><th>Last Name</th></tr>
<input name=\"Venue\" type=\"hidden\" value=\"$Venue\">
<input name=\"Date\" type=\"hidden\" value=\"$Year-$Month-$Day\">
<input name=\"Date\" type=\"hidden\" value=\"$Year-$Month-$Day\">
<input name=\"PlayerNo\" type=\"hidden\" value=\"$PlayerNo\">
<input name=\"beensubmited\" type=\"hidden\" value=\"Y\">");

//Creates counter to name individual cells
for ( $counter = 1; $counter <= $PlayerNo; $counter += 1) {
$points = isset($pointsArray[$counter]) ? $pointsArray[$counter] : 25; ;

//produces querys form
print("<tr><td align=\"center\" valign=\"center\"> $counter</td><td align=\"center\" valign=\"center\">
$points</td><td align=\"center\" valign=\"center\">
<input name=\"Position$counter\" value=\"$counter\" type=\"text\" size=\"15\" maxlength=\"7\" READONLY=\"READONLY\">
<input name=\"MembershipNo$counter\" type=\"text\" size=\"7\" maxlength=\"7\" tabindex=\"$counter\"onChange=\"showFN(this.value, 'FirstName$counter', 'LastName$counter');\">
</td><td align=\"center\" valign=\"center\">
<input name=\"FirstName$counter\" type=\"text\" size=\"15\" maxlength=\"7\" READONLY=\"READONLY\">
</td><td align=\"center\" valign=\"center\">
<input name=\"LastName$counter\" type=\"text\" size=\"15\" maxlength=\"7\" READONLY=\"READONLY\">
</td></tr>");
}
//submit Button
print("</table><br>
<input type=SUBMIT name=action value=\"Done!\">
</form>");

} // end beensubmited blank

// Adds form data to DB AFTER SUBMITTING

if($beensubmited =="Y"){

$Venue = $_POST['Venue'];
$Date = $_POST['Date'];
$PlayerNo = $_POST['PlayerNo'];
$PlayerNo = $_POST['PlayerNo'];

//MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
//MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");


foreach($_POST as $k=>$v) $$k=$v;


for ($PN = 1; $PN <= $_POST['PlayerNo']; $PN++) {

${"MembershipNo$PN"} = $_POST["MembershipNo$PN"];

$result2 = "INSERT into $table2 values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '$Position')";

//mysql_db_query ($database, $result2, $link);

print("$result2");
								/*if($beensubmited =="Y")
									{
								$Venue = $_POST['Venue'];
								$Date = $_POST['Date'];
								$PlayerNo = $_POST['PlayerNo'];
								$PlayerNo = $_POST['PlayerNo'];


									// Connect
									$link = mysql_connect($host, $user, $password)
										OR die(mysql_error());
									if (!$link) {
										die('Could not connect: ' . mysql_error());
												}
									echo 'Connected successfully';

								foreach($_POST as $k=>$v) $$k=$v;
								for ($PN = 1; $PN <= $_POST['PlayerNo']; $PN++) 
									{
									 ${"MembershipNo$PN"} = $_POST["MembershipNo$PN"];

									// Query
									$query3 = "INSERT into $table2 values (`ResultID`, `VenueID`, `MembershipNo`, `Date`, `Position`) VALUES('NULL', '$Venue', '${"MembershipNo$PN"}', '$Date', '$Position')";
									$result = mysql_query($query3);
									}
										print("$query2");
									}
								 //end been submitted YES
}
}
?>
<!-- Script Size:  0.53 KB -->
</body>
</html>

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.