webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 The database must already exist for this work. So yeah, "import into the db to create the tables". I'm not sure what you exactly mean when you say 'import' though. If you mean 'paste in the code as a regular sql query' then fine. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial' at line 1 Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 i got it in. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 Yay! What do you mean by 'I got it in'? You got the table into your database or you got the values of your form into your table? Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 yes. and i did a test run to see if it works and theres an issue with the dbinfo.php file. take a look birdmansplace.myftp.org/test/form.php Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 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? Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 hmmmmm. i checked and even used a config from another .php file and still same thing going on Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 Sorry, I meant the full code for your form.php file. (edit your last post if thats your real username and password to avoid any hacker wannabes) Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 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!!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 Yay! Your form now seems to be processing fine. But is it writing to your database? Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 how would i go about finding that out? Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 Just paste in this basic query into myPHPAdmin: SELECT * FROM `yourtablename` Are you familiar with SQL? You should also have a browse button which will show you the contents of your table without having to enter any code. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 MySQL returned an empty result set (i.e. zero rows). (Query took 0.0003 sec) Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 well that was an easy. form info is showing in db. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 Good. Do you want through how to output the data? Very straightfoward. Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 yes please. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 I'll just be about 10 mins putting the script together. Quote Link to comment Share on other sites More sharing options...
dropfaith Posted December 7, 2008 Share Posted December 7, 2008 <?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); ?> Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted December 7, 2008 Share Posted December 7, 2008 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>"; ?> Quote Link to comment Share on other sites More sharing options...
dropfaith Posted December 7, 2008 Share Posted December 7, 2008 well that will work im sure but clean up the font face stuff with some easy css on it would be alot better code Quote Link to comment Share on other sites More sharing options...
Birdmansplace Posted December 7, 2008 Author Share Posted December 7, 2008 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\test\output.php on line 21 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.