Web Hosting Talk







View Full Version : really easy problem - sending variable


stickygoblin
06-21-2004, 04:36 AM
hi

ok trying to understand where i'm going wrong but its turning into a bit of a nightmare. its a really simple problem. I am trying to send a variable to my database and create a link and possibly a simple page but i haven't managed to get that far yet. The database is recieving a new record from the page but it isn't recieving the value of county.

page1 : insertcounty.php

<html>
<head></head>

<body>

<form name="test" method="post" action="countyinject.php">

<input type="hidden" name="CountyName" value="<? $County ?>">
<table width="500" border="0" cellspacing="0" cellpadding="0">

<tr>
<td width="30%">County Name:
<input name="County" type="text" id="County" size="12" maxlength="12">
<input type="submit" name="Submit" value="Create County"></td>
</tr>

</table>

<\form>

</body>
</html>


Page2: countyinject.php


<?php

include("config.php");

//vars section
global $sqlhost;
global $sqluser;
global $sqlpass;
global $sqldb;

$id = $_POST["id"];
$County = $_POST["County"];
$Link = $_POST["Link"];

//END Vars Section


//MYSQL DataBase Connection Section
$cnx = mysql_connect($sqlhost,$sqluser,$sqlpass);
mysql_select_db($sqldb) //This statement is required to select the database from the mysql server
or die("Invalid : " . mysql_error());
//END Database Connection Section


echo "$id<br>$County<br>runner<br>$Link<br>";

if($cnx != null)
{
$SQL_query_String = "INSERT INTO county_tbl (County, Link) VALUES ('$County','$Link')";
$cur= mysql_query($SQL_query_String )
or die("Invalid : " . mysql_error());
}

mysql_close( $cnx);

?>
County Setup Complete Please return to county entry page <a href="insertcounty.php">Clicking
Here</a>



i know its a really simple problem and i feel like a bit of a biff not being able to work it out but i've gone round in circles so many times i'm dizzy!!

table name: county_tbl
tabel contents: id, County, Link

Burhan
06-21-2004, 05:06 AM
A few issues :

<input type="hidden" name="CountyName" value="<? $County ?>">

is wrong -- it should be

<input type="hidden" name="CountyName" value="<?= $County ?>">

Also -- <\form> should be </form>

Other than that, I can't see anything glaringly obvious. You could try error_reporting(E_ALL); to catch anything else.

stickygoblin
06-21-2004, 06:36 AM
ok had a really good think about this na dgot to this point, again having a few issues with the page reload as in it won't load the form if you attempt an add country. the code is as follows:

<html>
<head>
<title> The County Admin Area </title>
</head>
<body>
<?php
if (isset($_GET['addcounty'])): // If the user wants to add a joke
{
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Type your county here:<br />
<textarea name="County" rows="10" cols="40" wrap>
</textarea><br />
<input type="submit" name="submitcounty" value="SUBMIT" />
</p>
</form>
<?php
}
else: // Default page display
include("config.php");
// Connect to the database server
$dbcnx = @mysql_connect($sqlhost,$sqluser,$sqlpass);
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}

// Select the jokes database
if (! @mysql_select_db($sqldb) ) {
die( '<p>Unable to locate the RWAS ' .
'database at this time.</p>' );
}

// If a joke has been submitted,
// add it to the database.
if (isset($_POST['submitcounty'])) {
$County = $_POST['County'];
$sql = "INSERT INTO county_tbl SET
County ='$County'";
//JokeDate=CURDATE()";
if (@mysql_query($sql)) {
echo('<p>Your county has been added.</p>');
} else {
echo('<p>Error adding submitted county: ' .
mysql_error() . '</p>');
}
}

echo('<p> Here are all the counties in our database: </p>');

// Request the text of all the jokes
$result = @mysql_query('SELECT County FROM county_tbl');
if (!$result) {
die('<p>Error performing query: ' .
mysql_error() . '</p>');
}

// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo('<p>' . $row['County'] . '</p>');
}

// When clicked, this link will load this page
// with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
'?addcounty=1">Add a county!</a></p>');

endif;

?>
</body>
</html>

stickygoblin
06-21-2004, 07:05 AM
ok fixed it sorry to bother you all - thanks for the help..

the problem was in the ISSET which shouldn't be a GET command but a simple test to see if anything is there, this fixed the form will show.

the next problem was that i wasn't sendint the correct variables to my database, thereford the complete and working code is this:



<?php
if (isset($addcounty)): // If the user wants to add a joke
{
?>

<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your County here:<BR>
<TEXTAREA NAME="County" ROWS=10 COLS=40 WRAP></TEXTAREA>
<BR>
<INPUT TYPE=SUBMIT NAME="submitcounty" VALUE="SUBMIT">
</FORM>

<?php
}
else: // Default page display
include("config.php");
// Connect to the database server
$dbcnx = @mysql_connect($sqlhost,$sqluser,$sqlpass);
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}

// Select the jokes database
if (! @mysql_select_db($sqldb) ) {
die( '<p>Unable to locate the RWAS ' .
'database at this time.</p>' );
}

// If a joke has been submitted,
// add it to the database.
if ("SUBMIT" == $submitcounty) {
//$County = $_POST['County'];
$sql = "INSERT INTO county_tbl SET " .
"County ='$County'";
//JokeDate=CURDATE()";
if (@mysql_query($sql)) {
echo('<p>Your county has been added.</p>');
} else {
echo('<p>Error adding submitted county: ' .
mysql_error() . '</p>');
}
}

echo('<p> Here are all the counties in our database: </p>');

// Request the text of all the jokes
$result = @mysql_query('SELECT County FROM county_tbl');
if (!$result) {
die('<p>Error performing query: ' .
mysql_error() . '</p>');
}

// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo('<p>' . $row['County'] . '</p>');
}

// When clicked, this link will load this page
// with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
'?addcounty=1">Add a county!</a></p>');

endif;

?>