Jump to content

sending form results to a file to use the file include latter how pls?


Baxt01
Go to solution Solved by Barand,

Recommended Posts

hi I have been trying to get a way of building a site for a online gaming community where they can post player points to a form so that I can make them be displayed in a list on a different page after editing

 

simply the group director gets the edited points from excel and pastes them into my html form then using file include in my page the results display in a page for viewing

this is what I got so far but now I am getting stupid error messages

 

<?php $player_name = $_POST['player_name'];$points = $_POST['points'];
$fp = fopen(”top100stats.txt”,);
fclose($fp);echo “<h1>You data has been saved in a text file!</h1>”;
?>

 

this is the error I get

Parse error: syntax error, unexpected ')' in /home/u159756103/public_html/top100stats.php on line 2

 

any help would be great as I was trying to do this using MySQL however after making my table I could not get php to write thew form data into it hahaha as you can see I am very new to php and mysql

Link to comment
Share on other sites

You would be best to pick up mysql and try to work that out as it's just better for your purposes in a myriad of ways.

 

However at a glance I would suggest the syntax error is the comma u have in Fopen line. Fopen usually requires two params so after that comma u should pass in parameter e.g. 'w' which opens the file ready for writing to it.

Link to comment
Share on other sites

haha yes just simply adding the 'w' after the comma fixed line 2 lol but moved to an new error on line 3

Parse error: syntax error, unexpected '>' in /home/u159756103/public_html/top100stats.php on line 3

 

i agree about your uneasyness with the raw data from a post but i figured that the site i am building is a free site for a low risk group of volenteers also i know nothing of mysql databases although i have managed to create a table using the system's already on my server which are phpmyadmin and mysql databases just when i try to connect to my table to add the records from my web form i get all kinds of issues connecting

Link to comment
Share on other sites

Can u post your code again? Based on the original I can't see why that error would be there.

 

also your script currently won't actually write anything to the file as all it does now is open it for writing and then closes it again .

 

Have you looked at php.net? U can pretty much copy their example herehttp://www.php.net/manual/en/function.fwrite.php

 

Also take a look at the parameters for fopen because some of the modes will overwrite the file each time and some will append to it http://www.php.net/manual/en/function.fopen.php

Link to comment
Share on other sites

I took your advice as above and scraped that stupid code because everytime I fixed a syntax a new one poped up so I re did it from scratch here is my new code:

 

<?php
$fp = fopen('top100stats.txt', 'w);
fwrite($fp, '$player_name');
fwrite($fp, '$points');
fclose($fp);

// the content of 'data.txt' is now 123 and not 23!
?>

 

haha now then spot my error as when the form is submitted it passes to this code and this code passes to the text file which is what I want however instead of passing the form variables $player_name $points that info is lost and I get the coding $player_name $points in my text file in the mean time im sitting a crash course in MySQL lolol

Link to comment
Share on other sites

ok I am back again ha ha so I took on board the advice you guys were all pointing at which was using MySQL database not fopen and sat reading a tutorial until a stupid hour in the morning after I finished work and I made a DB and created a table in there named " top100stats " here is the php I used;

 

<?php
 $con=mysqli_connect("mysql.neq3.com","u1*****103_mike","K*****id11","u1*****103_mike");
 // Check connection
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

 $sql="INSERT INTO top100stats (player_name, points)
 VALUES
 ('$_POST[player_name]','$_POST[points]')";

 if (!mysqli_query($con,$sql))
   {
   die('Error: ' . mysqli_error($con));
   }
 echo "1 record added";

 mysqli_close($con);
 ?>

 

ok now I am pretty impressed with myself at this point as you will see in a sec I actually managed a conection to MySQL,

and now for the BUT in this the part im not understanding is this error message I am reciving when I input to my form and submit it sends the data to a file named " dbconect.php " which then is supposed to add the record into my table ( code for this page above ) the error is;

 

Error: Table 'u1*****103_mike.top100stats' doesn't exist

 

now of course for my security I have used the astrix to hide parts of my user ID in all codes and error messages

I understand the error is telling me that it's looking for a table named with my user name and my table name but why is it doing this to me

oh did I say I don't really know my about MySQL I just read a tutorial over night and then produced this coding lol I love learning and I hope you guys love teaching here thanks in advance :happy-04:

Link to comment
Share on other sites

HAHA that's just too funny Guru only because that's exactly what it was but I worked it out for myself right after I posted on here LOL

just after I posted on here I went back to my domain looked at the same coding I had posted on here and logged into MySQL and started just looking at everything,

once I got into my tables and stuff I checked my structure and a few other options then realised that I was trying to insert into a tabled named " top100stats " the correct path I was needing to use was " top100standings ".............

I think that the reason I am struggling with  MySQL so much is that all tutorials refer to manually typing all the commands however on my domain with neq3.com this is not how its done I have a console everything is done using a wizard system for instance I had to change my table as I had 3 column's id, player_names & points

the id column was supposed to be an auto integer so that the user never had to add data to this column however when I tested this for some reason it was adding zero to the first record then was trying to add zero to the second which is not allowed so was throwing me a new error so I read about this and everyone was saying use AUTO_INCREMEANT but in my console I could not find any option to do this so I decided to do away with that column so all in all THANK YOU all for your help with setting this up even when your help has made me go away and research and learn my own help rather than giving me the answers

Link to comment
Share on other sites

  • Solution

An auto_increment key isn't mandatory so long as you have another column that contains unique values and is a candidate for a primary key. For example, in an employee database you might use the company employee number or national insurance number. Names are not good candidates for a primary key; two people can legitimately have the same name plus it is easy to mistype a name giving two people when there should only be one.

Link to comment
Share on other sites

lol yeh that would be so much easyer for me if I was manually assigning the number value for each record however I am not even the one adding the data to the table I am making this for a voluntary group of iliterates (no offence ) I need it to be an auto generated numbered ID for the primary key

Link to comment
Share on other sites

In which case you need to make it as idiot-proof as possible

 

Create a table of players. This is the only place that will contain the player name so spelling mismatches can't happen. Use this table to create a dropdown selection of player names with the ids as the option values. Thisselected  id goes into the points table.

CREATE TABLE player (
player_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
player_name VARCHAR(100)
);

CREATE TABLE points (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
player_id INT,
points INT
);

+-------------+
| player      |
+-------------+         +-------------+
| player_id   |----+    |  points     |
| player_name |    |    +-------------+
+-------------+    |    | id          |
                   +---<| player_id   |
                        | points      |
                        +-------------+
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.