Page 1 of 2

"Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 10:30 am
by phpnewbie3
Hello everyone,

Though I'm good enough with HTML, CSS, design, graphics, photo-programs, etc, I'm very new to PHP.

I have this problem to solve:

I have a small sports handicapping site, with a few handicappers who have picks on a daily basis.
Until now they sent me their picks every day, and I posted them in the site. This was very time consuming for me.

So I tried to solve things with PHP:
I created a very nice input area, password protected for every one of them, with input through the "POST" function in PHP.
Now the big problem is that I want to get the outputs in a way that they can be viewable by anyone who looks at those output pages. (they will be also password protected).
But if I try it at my PC, everything looks fine like it's working, from other PC-s all the output pages are just blank, nothing can be seen.

I have tried with using the "GET" function, but then the created new URL with every kind of input can not be given each and every day to the people.
The URLs where the outputs can be viewed need to be static ones.

Can someone give me a hint how can be this problem solved?
It may happen that what I was trying to do it's completely impossible using PHP.

Thanks a lot.

PS: Here is a sample input area:
http://profitsportspicks.com/test/input.html

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 10:51 am
by jaoudestudios
I think you need to give us some more information.

If you say it works on your computer but not on others, are they accessing your machine or trying to run it locally?

If your machine is acting like a server, could they view the files from your machine before when you did not use php?

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 11:03 am
by phpnewbie3
jaoudestudios wrote:I think you need to give us some more information.

If you say it works on your computer but not on others, are they accessing your machine or trying to run it locally?

If your machine is acting like a server, could they view the files from your machine before when you did not use php?
No, I have just tried using my other computer (laptop), and I can't see anything I input from the other computer (desktop).

But even if I clear the "Private" data (with "Authenticated sessions" included) from the same PC on which I made the input, after this on the same PC everything is lost from the output pages.
Everything is saved just for the same PC and just until the "Private data" is not cleared....

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 11:21 am
by jaoudestudios
Ah I think I see. So you are just saving the submitted data in php variables (sessions?), you are not saving them to a file or database?

If this is the case, then you will not be able to access the data submitted on one computer from another and yes you are right, if you clear all sessions etc on that pc then all data will be lost.

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 11:37 am
by phpnewbie3
jaoudestudios wrote:Ah I think I see. So you are just saving the submitted data in php variables (sessions?), you are not saving them to a file or database?

If this is the case, then you will not be able to access the data submitted on one computer from another and yes you are right, if you clear all sessions etc on that pc then all data will be lost.
Ok thanks!
Now I guess I need to look for tutorials on how to save the submitted data to a file.

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 11:38 am
by josh
Files are great for documents, images, media programs, data is best suited in a database

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 12:05 pm
by phpnewbie3
jshpro2 wrote:Files are great for documents, images, media programs, data is best suited in a database
Oh well, I need to hire someone. :banghead:
I have no idea about databases, how to setup, etc.....

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 1:41 pm
by jaoudestudios
jshpro2 is right, with a database, you will be able to do so much more. From searches, to statistics etc...

Re: "Blonde" question about making posts using PHP

Posted: Sat Sep 20, 2008 1:43 pm
by jaoudestudios
Its not so bad to learn MySQL, especially for basic stuff, the advanced stuff you can learn as you require them!

What are you running to compile your php? WAMP? this will have MySQL already installed. If not ditch what you are using and install WAMP if you are on windows, or MAMP on a Mac.

Re: "Blonde" question about making posts using PHP

Posted: Sun Sep 21, 2008 7:51 am
by phpnewbie3
After a second thought, and because I realize how much I can accomplish if I learn and I'll know how to establish and work with databases I went on, dedicated all my afternoon and evening yesterday to this, and I made some huge progress, lol. (After all, if I have learned everything I know in the internet applications area from the web - the greatest college in the world for this if you're serious and you like what you do -why could I not learn databases to?)

So now I can ask you very specific questions for help.

I made table in database, everything is OK with that, learned how to use PHPmyAdmin. (Easy and nice stuff!)
Works fine, gets all the data I need from the input area, plus those who input the data can check how exactly things will look on the output page, and if they made a mistake they can correct the mistake and input again (because from that intermediary output page the data goes to the database and from there goes to the final output page, which need to look exactly in the same way like the intermediary one).

I'm working now on the final output page of the sports-picks.

Should have been done without any problem after how I progressed, but then anything I try I got this message when trying to view my page:

"Parse error: syntax error, unexpected T_ECHO, expecting ']' in /home/(...my username...)/public_html/test/view.php on line 72"

Now this is a total nonsense, because like you can see below, line 72 is in an area (this is for the 3-rd pick a handicapper can have, they can have maximum 5 in any day) which is totally identical with the same areas (lines) from the previous 2 picks. And if that code is validated what in the world is with this line?
I tried to make some crazy changes, but nothing works, and anyways everything looks 1000% correct! So I almost banged my head on the wall yesterday because of this "line 72".

Here is the code:
-----------------------------------------------------------------------------------------------------

<?php
$con = mysql_connect("localhost","... my username...","... my password......");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("... the name of the database ....", $con);

$result = mysql_query("SELECT * FROM Picks");

while($row = mysql_fetch_array($result))
{

echo $row['Day'] . ",
" . $row['Month'] . "
" . $row['Number']; echo "</font></b>***</font></div><br>";

echo " <table align='center' border='1' bordercolor='#c0c0c0' cellpadding='0' cellspacing='0' width='528' bgcolor='#ffffff'><tr><td>
<table align='center' border='0' cellpadding='0' cellspacing='0' width='96%' bgcolor='#ffffff'>
<tr><td><div class='descr'><p align='center'><br><font color='#004200'>";

echo $row['Competition'] . " " . $row['Sport'] . " " . $row['Country'] . " " . $row['Time']; echo "</font><br><font color='#660000'>";
echo $row['Team1'] . " " . $row['vs'] . " " . $row['Team2']; echo "<br>";
echo $row['Type']; echo "</font>&nbsp;<b>"; echo $row['Pick'] . " " . $row['Spread'] . " " . $row['Odds'] . " " . $row['Units'];
echo "</b></font><br><br>";

echo "<font color='#004200'>";
echo $row['Competition1'] . " " . $row['Sport1'] . " " . $row['Country1'] . " " . $row['Time1']; echo "</font><br><font color='#660000'>";
echo $row['Team3'] . " " . $row['vs1'] . " " . $row['Team4']; echo "<br>";

echo $row['Type1']; echo "</font>&nbsp;<b>"; echo $row['Pick1'] . " " . $row['Spread1'] . " " . $row['Odds1'] . " " . $row['Units1'];
echo "</b></font><br><br>";

echo "<font color='#004200'>";
echo $row['Competition2'] . " " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2]; echo "</font><br><font color='#660000'>";
echo $row['Team5'] . " " . $row['vs2'] . " " . $row['Team6']; echo "<br>";
echo $row['Type2']; echo "</font>&nbsp;<b>"; echo $row['Pick2'] . " " . $row['Spread2'] . " " . $row['Odds2'] . " " . $row['Units2'];
echo "</b></font><br><br>";

echo "<font color='#004200'>";
echo $row['Competition3'] . " " . $row['Sport3'] . " " . $row['Country3'] . " " . $row['Time3]; echo "</font><br><font color='#660000'>";
echo $row['Team7'] . " " . $row['vs3'] . " " . $row['Team8']; echo "<br>";
echo $row['Type3']; echo "</font>&nbsp;<b>"; echo $row['Pick3'] . " " . $row['Spread3'] . " " . $row['Odds3'] . " " . $row['Units3'];
echo "</b></font><br><br>";

echo $row['Competition4'] . " " . $row['Sport4'] . " " . $row['Country4'] . " " . $row['Time4']; echo "</font><br><font color='#660000'>";
echo $row['Team9'] . " " . $row['vs4'] . " " . $row['Team10']; echo "<br>";
echo $row['Type4']; echo "</font>&nbsp;<b>"; echo $row['Pick4'] . " " . $row['Spread4'] . " " . $row['Odds4'] . " " .
$row['Units4'];
echo "</b></font><br><br>";

}
mysql_close($con);
?>

-----------------------------------------------------------------------------------

Line 72 is in bold red, and the 2 lines which are identical with this line (only the row name is different) are in bold blue.

What do you think can be the problem?

My other question is something I have not found the solution for how to do it:

What is the code if I want for a person who inputs a a new data in the input area than just that new data to be kept in the table, and with this input to automatically erase the previous entry? (this is needed because if they make a mistake, they need to go back and correct it. Plus I need only 1 entry at any time in any handicapper's table and separate database to be shown on the final output pages - the entry valid just for that day, because anyways they keep their records in our forum).

Thanks again!

Re: "Blonde" question about making posts using PHP

Posted: Sun Sep 21, 2008 10:30 am
by jaoudestudios
I think your error on line 72 (red) could be due to the data. Do you have any quotes coming out of the database which could be breaking the php?

If you want them to edit an existing entry in the database instead of using INSERT use UPDATE.

In the future when you have all of it working I would recommend using CSS instead of <font...> etc.

Re: "Blonde" question about making posts using PHP

Posted: Sun Sep 21, 2008 1:06 pm
by phpnewbie3
jaoudestudios wrote:I think your error on line 72 (red) could be due to the data. Do you have any quotes coming out of the database which could be breaking the php?

If you want them to edit an existing entry in the database instead of using INSERT use UPDATE.

In the future when you have all of it working I would recommend using CSS instead of <font...> etc.
Thanks for the info using the "INSERT".

I do not have any quotes coming out from the database, neither parenthesis.
The only characters which are not letters can be just " : ", " + " and " - ", but none of these are one line 72 either... :banghead:

Re: "Blonde" question about making posts using PHP

Posted: Sun Sep 21, 2008 4:50 pm
by phpnewbie3
phpnewbie3 wrote:
jaoudestudios wrote: Thanks for the info using the "INSERT".
I can't use "UPDATE" instead of "INSERT". (I tried even like "update").

No data is sent to the database, I get this message:

Error: 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 'INTO Picks (Day, Month, Number, Competition, Sport, Country, Time, Team1, vs, T' at line 1


So none of my problems are solved... :x

Re: "Blonde" question about making posts using PHP

Posted: Sun Sep 21, 2008 6:31 pm
by phpnewbie3
Oh, I found the problem with the "UPDATE", I was using the wrong syntax, thought I just need to change "INSERT" with "UPDATE", buy now I know what I need to do.

Only problem 1 is unsolved, but that's a headache...

Re: "Blonde" question about making posts using PHP

Posted: Mon Sep 22, 2008 3:33 am
by Stryks
Umm ... is problem 1 the unexpected echo issue?
phpnewbie3 wrote:echo "<font color='#004200'>";
echo $row['Competition2'] . " " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2]; echo "</font><br><font color='#660000'>";
echo $row['Team5'] . " " . $row['vs2'] . " " . $row['Team6']; echo "<br>";
echo $row['Type2']; echo "</font>&nbsp;<b>"; echo $row['Pick2'] . " " . $row['Spread2'] . " " . $row['Odds2'] . " " . $row['Units2'];
echo "</b></font><br><br>";
When you get errors such as that, always start your search on the previous line. You miss just one semi-colon or quotation mark and all of a sudden your pretty two lines become one to PHP.

You'll see the line above is missing something.

Code: Select all

echo $row['Competition2'] . " " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2]; echo "</font><br><font color='#660000'>";
// should be
echo $row['Competition2'] . " " . $row['Sport2'] . " " . $row['Country2'] . " " . $row['Time2']; echo "</font><br><font color='#660000'>";
 
That should solve it ... assuming that is the problem you're referring to.

:D