Jump to content

[SOLVED] form help.


Birdmansplace

Recommended Posts

  • Replies 68
  • Created
  • Last Reply

Did you swap out 'yourdatabasename' and 'yourtablename' with your actual database and desired table name?

 

Try manually creating the table through PHP admin using the above code as a reference. 5 fields in total.

 

Let me know where you get stuck.

 

Hmm,  I see.

 

The problem is I'm only familiar with using myPHPAdmin with CPANEL. I don't think I use XAAMP.

 

I've used exactly the same code when testing it for you and it writes back to the database fine without the error you're currently recieving:

http://www.joycepromotions.com/form.php

 

First thing to check would be the details of dbinfo.php. Are you sure your host, username, password and database details are accurate?

 

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\test\dbinfo.php on line 2

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\test\dbinfo.php on line 2

 

Wait a minute. This seems like a minor typo. Have you looked at line 2 of your code?

 

It seems that your styling may have effected the php. You have a backslash somewhere that shouldn't be there.

 

Post your full code.

this is what my dbinfo.php is - real user and passwd

 

<?php
$dbhost = 'localhost';               //usually localhost
$dbuser = 'root';               //your username assigned to your database
$dbpasswd = 'password';     //your password assigned to your user & database
$dbname = 'form';                 //your database name
?>

 

figured it out.  dam wordpad

 

form.php




<?php

if (isset($_POST['submit']))

{ 

     if (strlen($_POST['username']) > 0)
     {$username=TRUE;}
     else {$username=FALSE;
          $message_username="* You forgot to enter the username!";}

     if (strlen($_POST['amount']) > 0)
         {$amount=TRUE;
                                if (is_numeric($_POST['amount']))
                                {$amountnumericcheck=TRUE;}
                                else {$amountnumericcheck=FALSE;
                           $message_amountnumericcheck=" *Please enter numeric values only!";
                                //echo "$message_amountnumericcheck";
                                }
                       }
   else    {$price=FALSE;
       $message_amount=" *You forgot to enter the amount!";}

     if 
        ($username && $amount)
        {                       
                   //YOU NEED TO HAVE AN EXTERNAL PHP FILE WITH YOUR DATABASE CONNECTION DETAILS. LET ME KNOW IF YOU DON'T KNOW HOW             
                   include("dbinfo.php");
                   mysql_connect(localhost,$username,$password);
                   @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database.");

                   
                   $username = mysql_real_escape_string($_POST['username']);
                   $amount = mysql_real_escape_string($_POST['amount']);
                   $ipaddress = getenv('REMOTE_ADDR');
                   $now_datetime = date('Y-m-d h:i:s');
                   

                   $query = "INSERT INTO tablename VALUES ('','$username','$amount','$ipaddress',NOW())";
                   mysql_query($query);

              
                   echo "Thank you $username !";

                   
                   exit();
              }

}

?>



<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">

Username:<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"/>
<?php if ($message_username) echo ''.$message_username.''; ?>
</br>
Amount:<input type="text" name="amount" id="amount" value="<?php if (isset($_POST['amount'])) echo $_POST['amount']; ?>"/>
<?php if ($message_amount) echo ''.$message_amount.''; ?>

</br>
<!---NO NEED FOR USER TO MANUALLY INPUT DATE FIELD, MYSQL WILL CAPTURE THIS FOR YOU AUTOMATICALLY->
<input type="submit" name="submit" id="submit" value="Submit Details">



<br><br>
Form by staff and members of <a href="http://www.phpfreaks.com">phpfreaks</a>

</form>
</body>
</html>


<?php

if (isset($_POST['submit']))

{ 

     if (strlen($_POST['username']) > 0)
     {$username=TRUE;}
     else {$username=FALSE;
          $message_username="* You forgot to enter the username!";}

     if (strlen($_POST['amount']) > 0)
         {$amount=TRUE;
                                if (is_numeric($_POST['amount']))
                                {$amountnumericcheck=TRUE;}
                                else {$amountnumericcheck=FALSE;
                           $message_amountnumericcheck=" *Please enter numeric values only!";
                                //echo "$message_amountnumericcheck";
                                }
                       }
   else    {$price=FALSE;
       $message_amount=" *You forgot to enter the amount!";}

     if 
        ($username && $amount)
        {                       
                   //YOU NEED TO HAVE AN EXTERNAL PHP FILE WITH YOUR DATABASE CONNECTION DETAILS. LET ME KNOW IF YOU DON'T KNOW HOW             
                   include("dbinfo.php");
                   mysql_connect(localhost,$username,$password);
                   @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database.");

                   
                   $username = mysql_real_escape_string($_POST['username']);
                   $amount = mysql_real_escape_string($_POST['amount']);
                   $ipaddress = getenv('REMOTE_ADDR');
                   $now_datetime = date('Y-m-d h:i:s');
                   

                   $query = "INSERT INTO tablename VALUES ('','$username','$amount','$ipaddress',NOW())";
                   mysql_query($query);

              
                   echo "Thank you $username !";

                   
                   exit();
              }

}

?>



<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">

Username:<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"/>
<?php if ($message_username) echo ''.$message_username.''; ?>
</br>
Amount:<input type="text" name="amount" id="amount" value="<?php if (isset($_POST['amount'])) echo $_POST['amount']; ?>"/>
<?php if ($message_amount) echo ''.$message_amount.''; ?>

</br>
<!---NO NEED FOR USER TO MANUALLY INPUT DATE FIELD, MYSQL WILL CAPTURE THIS FOR YOU AUTOMATICALLY->
<input type="submit" name="submit" id="submit" value="Submit Details">



<br><br>
Form by staff and members of <a href="http://www.phpfreaks.com">phpfreaks</a>

</form>
</body>
</html>

 

 

It works know!!!!!!!!!!!!!

Minor error, don't worry.

 

Remember this line in form.php?:

$query = "INSERT INTO tablename VALUES ('','$username','$amount','$ipaddress',NOW())";

 

You need to swap out 'tablename' with your actual table name or it won't write.

 

Let me know if that works.

<?php
// includes
include("address of your connection details goes here");


// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query

				$query = "SELECT * FROM TABLENAME order by NAME-OF-DATE-FIELD-IN-DB";

	$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>	
		THIS STUFF HERE IS BASICLY HTML ECHOED THE RESULTS	<tr>
<td colspan="2"><?php echo $row->Name; ?><?php echo $row->Name; ?>"></td>

			</tr>
<?php
}
}
// if no records present
// display message
else
{
?>

<?php
}

// close database connection
mysql_close($connection);
?>

Alritey. Create a new php file named output.php and paste in the following:

 


<html>
<body>

<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">URN</font></th>
<th><font face="Arial, Helvetica, sans-serif">User Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Amount</font></th>
<th><font face="Arial, Helvetica, sans-serif">IP Address</font></th>
<th><font face="Arial, Helvetica, sans-serif">Date</font></th>
</tr>

<?
include("dbinfo.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tablename ORDER BY date DESC";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

echo $date;

$i=0;
while ($i < $num) {

$urn=mysql_result($result,$i,"urn");
$username=mysql_result($result,$i,"username");
$amount=mysql_result($result,$i,"amount");
$ipaddress=mysql_result($result,$i,"ipaddress");
$date=mysql_result($result,$i,"date");


?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $urn; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $username; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $amount; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $ipaddress; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $date; ?></font></td>


</tr>

<?
$i++;
}

echo "</table>";



?>


 

 

 

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.