Closed Thread Icon

Topic awaiting preservation: Help for a PHP Newbie (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=24125" title="Pages that link to Topic awaiting preservation: Help for a PHP Newbie (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Help for a PHP Newbie <span class="small">(Page 1 of 1)</span>\

 
I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-21-2004 02:21

I've been playing with PHP for all of maybe a month, mostly being taught by a friend of mine. I've tried reading several PHP/MySQL tutorials, but they only confuse me...

I'm having trouble with a page I'm writing for my site to update the news section, and also for the output page.

Update page - Give it a whirl
uNews.php - php to submit data (not working right, and I'm not sure why

I've been using a trial version of EMS MySQL Manager to add data to the forms for testing the output and adding in old news items.

news.php - to output the data (is working, sort of)

old version - I want news.php to work like this

So, to get to the specifics.
What am I doing wrong posting the new entry?
How do I get data from a single database entry?
Should I add the code for viewing a single entry to the news.php or make a new script, and how would I go about it?

If somebody could explain this to me, that would be best. If you must point me to a tutorial, please something that simplifies things, I'm easily confused.

Any help is, as always, greatly appreciated!





...Of all the things I've lost, I miss my mind the most (ozzy osbourne)


(Edited by I X I on 11-21-2004 02:23)

(Edited by I X I on 11-21-2004 03:42)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-21-2004 03:32

I can't help you much without seeing any source code.

I'm realy good at PHP and I've been in it no more than a few years. I learned from this book by reading it on some trip I was on and when I returned home I hand coded the examples in the book. That gave me a basic understanding of the language and I learned the rest from the PHP online manual. I think I got a good hang of it from the little JavaScript knowledge I had at the time. One thing that helped me, I wanted to make stuff even if I didn't know what's needed to make it.

The more you make (or code), the more expirience you get, the more experience you get, the more advanced your (coding) skills become. Have fun!

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-21-2004 03:40

there are links to the source code up there, uNews.php links to the parent directory where I store the actual file, just right click and save as.

quote:
I X I said:

Update page - Give it a whirl
uNews.php - php to submit data (not working right, and I'm not sure why

news.php - to output the data (is working, sort of)

old version - I want news.php to work like this







Some people say I'm a dreamer, but I'm not the only one (John Lennon)


(Edited by I X I on 11-21-2004 03:44)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-21-2004 06:33

I looked and only saw HTML pages. I don't think I'm overlooking something.

I don't know if you know this:
PHP (as in it's name) is a preprocessor, so no matter what I do, when I try to download the file from the server, the server runs the PHP and outputs HTML (or whatever). I am unable to get any PHP source without you renaming the files to something like 'uNews.php.txt'. That would allow me to see the PHP source.

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-21-2004 08:38

I'm sorry, I didn't know you couldn't save the php from viewing it's parent directory

uNews.php.txt





...Of all the things I've lost, I miss my mind the most (ozzy osbourne)

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 11-21-2004 13:19

The page still seems to be parsed through php. I get an unexpected $ on line 226 when I try to view it.

The easiest way to make php files readable for others is to change the postfixt to .phps (php source), that way the code will be syntax highlighted as well.

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio - Vim Tutorial -

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-21-2004 19:06

one of these ways is bound to work...

uNews.php
uNews.phps
uNews.php.txt
uNews.zip
uNews.rar





...Of all the things I've lost, I miss my mind the most (ozzy osbourne)

ninmonkeys
Nervous Wreck (II) Inmate

From: mn
Insane since: May 2004

posted posted 11-21-2004 21:29

To make it easier to read If you add this to your http.conf, foo.phps will be syntax hilighted php source

code:
#this next line will allow .phps to show hilighted PHP source
AddType application/x-httpd-php-source .phps

I'm not sure, but I think you just gave everyone your username/password to your database

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-21-2004 21:57

If that is your database password, I strongly suggest changing your database password ASAP! You should always at least replace passwords when sharing the source of things like this. I probably should of mentioned this earlier, but I didn't think of it at the time.

Here's what I see:

code:
if($REQUEST_METHOD == "POST"){


Where does that close?

code:
if($valid == false){


I don't see where that closes either.

code:
if(str_replace(" ", "", title) == ""){
$errString .= "<font color=\"#FF0000\"> You must enter a title.</font><br>";
$valid = false;
}
if(str_replace(" ", "", message) == ""){
$errString .= "<font color=\"#FF0000\"> You must enter a message.</font><br>";
$valid = false;
}


I would use:

code:
if(!trim($title)){
$errString .= '<font color="#FF0000"> You must enter a title.</font><br>';
$valid = false;
}
if(!trim($message)){
$errString .= '<font color="#FF0000"> You must enter a message.</font><br>';
$valid = false;
}


Notice:
- Added "$" signs for the variables.
- Use of the trim() function.
- Use of single quotes (on $errString) allow you to use double quotes with out adding backslashes and execute faster because PHP doesn't parse it for things like variables and "\n" characters.

Hope this helps!



(Edited by zavaboy on 11-21-2004 21:59)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-21-2004 23:53

why would anybody want to mess with my free database when they could just go and get their own free database? anyway, yeah I should have thought about that myself.

so which one did you guys check out, so I can free up a few bytes

thanks for the help, and I'm still trying to get it all figured out, but when I do I'll make sure to come back

[edit]
I got the errors to stop bugging me, but I'm still not getting the items into the database, or if I am they're not showing up when I display http://ixi.dacryonic.net/news.php
[/edit]





...Of all the things I've lost, I miss my mind the most (ozzy osbourne)


(Edited by I X I on 11-22-2004 00:10)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-23-2004 03:46

OK, latest version. no errors when parsed, but it's still not working right.

uNews.html - Update form, feel free to add an entry for testing purposes
uNews.phps - changed Username and Password
news.php - The output script





Some people say I'm a dreamer, but I'm not the only one (John Lennon)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-23-2004 17:28

Ok...

code:
$SQL = mysql_connect("sql-01.portlandpremium.co.uk", "IXIFX", "password");
mysql_select_db("IXIFX") or die( "Unable to select database");
$datetime = date("m-d-Y, h:i:s A");
$ins = "INSERT INTO news VALUES ('$datetime', '$title', '$message')";
mysql_db_query("IXIFX", $ins);
mysql_close();


I would use this:

code:
$SQL = mysql_connect("sql-01.portlandpremium.co.uk", "IXIFX", "password");
mysql_select_db("IXIFX") or die( "Unable to select database");
$datetime = date("m-d-Y, h:i:s A");
$ins = "INSERT INTO news VALUES ('$datetime', '$title', '$message')";
if (mysql_query($ins)){
$return = 'Update Complete';
$errString = '';
}else{
$return = 'Update Failed';
$errString = mysql_error();
}
mysql_close();


Replace "Update Complete" at line 201 (206 if you have done the changes above) with "<? echo $return; ?>" and place "<? echo $errString; ?>" where you would like to see the MySQL error (if any). You can now see if MySQL encountered a problem with your query and can see where you have the problem. If a error is returned and you dont know what it means or what to do, go ahead and post it here and I'll see what I can do.

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-23-2004 23:08

Column count doesn't match value count at row 1


...Of all the things I've lost, I miss my mind the most (ozzy osbourne)

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 11-24-2004 00:44

What does your news table look like? It probably has some sort of id field, which you don't do anything with when you try to insert into the table... The insert query should probably look something like:

code:
$ins = "INSERT INTO news (<date>, <title>, <message>) VALUES ('$datetime', '$title', '$message')";


Where <data>, <title>, <message> are the field names in your table.

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio - Vim Tutorial -

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-24-2004 01:01

My table has 4 fields: postid (int, auto-increment, primary); datetime (date); title (text); message (text)

code:
$ins = "INSERT INTO news VALUES ('$datetime', '$title', '$message')";



so I should change this to

code:
$ins = "INSERT INTO news (<datetime>, <title>, <message>)  VALUES ('$datetime', '$title', '$message')";



with or without "<...>" around the field names?


Some people say I'm a dreamer, but I'm not the only one (John Lennon)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-24-2004 01:22

success! thanks everybody, now I have but 1 bug to look into, the date isn't coming up right... I'll try to fix this on my own but if I encounter any problems I'll let you know

thanks again


...Of all the things I've lost, I miss my mind the most (ozzy osbourne)

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 11-24-2004 02:21

Glad we could be of assistance

A little hint for the next part: php->htmlspecialchars()

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio - Vim Tutorial -

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-24-2004 03:05

Nice! I was about to tell you that, but you beat me!

Oh, and test623589 is me... just thought I'd let you know.

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-24-2004 04:23
quote:
I X I said:

How do I get data from a single database entry?



Now that I have the data getting into the database and the news.php file outputting the table correctly.
I'm wanting to do something like news.php?date=2004-11-23 or whatever link you clicked on... any good starting points?


Some people say I'm a dreamer, but I'm not the only one (John Lennon)

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 11-24-2004 10:24

The SQL tutorial over at w3 is a nice play to start to learn SQL, which is the language you use to extract information for the databse. DmS's PHP and MYSQL tutorial covers what you're looking for as well.

_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio - Vim Tutorial -

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-24-2004 11:08

ohhhh my aching head

and I only got to page 5 of DmS's tutorial...

but I have bookmarked and will re-visit when I wake up. thanks for the links veneficuz


...Of all the things I've lost, I miss my mind the most (ozzy osbourne)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 11-30-2004 05:15

for everyone that helped, and those that are interested - I finished

www.ixifx.net/news.php - give it a whirl
www.ixifx.net/update/update.html - go ahead and try, I dare you

I'm going to be getting rid of the testing posts here in a little while. I'm very proud of myself for finally getting it working, and I thank you all for helping me to do so. I've checked to make sure the php outputs valid html, but feel free to double check me everybody makes mistakes. I'm planning on basing a blog script from this some time in the near future.

anyway, just wanted to show off my efforts of the past week, I had alot of time to play with it becuase we were out of school all week for thanksgiving (I know, all week for one day, but I'm not complaining) also the layout has been changed around and can be commented on in layout and color

I'm so proud of me :') (tears of joy)



Some people say I'm a dreamer, but I'm not the only one (John Lennon)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-30-2004 06:10

Just to let you know, my first blog script is at: http://zavaboy.jimbug.org/phptest/blog.php

I made it when I was learning PHP. Most of my PHP skills were obtained from developing that script. Some modified snipits of that script remain in my current script for the news/blog on my site.

Also see other things I made when I was learning PHP at: http://zavaboy.jimbug.org/phptest/

Congrats on completing your script! I enjoyed helping you where I could!

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 12-02-2004 17:34

OK, just wanted to show off, so go and check out www.ixifx.net/news.php?page=topics
just so you know, I went from using 2 files to just one, which is what I'm boasting about, because I did it 1) in about an hour and 2) on my own after reading through a few tut's just to see how to get the variable from the ? in the url (alot easer than I thought it would be ) so, no need really to comment unless you find an error that I missed, just wanted to show off.

thanks again



Some people say I'm a dreamer, but I'm not the only one (John Lennon)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 12-13-2004 08:43

GRRRR

I'm having some issues... www.ixifx.net/test.php
this is supposed to check to ensure the user and pass match a record in the db.

since I know you'll want to see it

code:
<?
//connect to db
$SQL = mysql_connect("sql-01.portlandpremium.co.uk", "IXIFX", "my password");
mysql_select_db("IXIFX") or die( "Unable to select database");
//when you click submit, do this
if($REQUEST_METHOD == "POST"){
//select record for userID
$Login = mysql_db_query("IXIFX","SELECT * FROM testLogin WHERE userID='$SuserID'");
$BB = mysql_fetch_array($Login, MYSQL_ASSOC);
$user = $BB["userID"];
$pass = $BB["password"];
//show what was in the input boxes
echo $SuserID;
echo $Spassword;
//test password
if (Spassword == $pass) {
$errString = 'it worked';
}else{
$errString = 'Could not log in';
}
}
//show all users and passwords
$Data = mysql_db_query("IXIFX","SELECT * FROM testLogin");
while ($AA = mysql_fetch_array($Data)) {
$userID = $AA["userID"];
$password = $AA["password"];
?>
<table width="100%">
<tr>
<td>userID - <? echo $userID ?></td>
<td>password - <? echo $password ?></td>
</tr>
</table>
<?
}
mysql_close();
echo $errString;
?>
//the input form
<form action="test.php" method="post">
<table width="100%">
<tr>
<td align="left">
User ID:
</td>
<td align="left">
<input type="text" name="SuserID" value="" size="12" />
</td>
</tr>
<tr>
<td align="left">
Password:
</td>
<td align="left">
<input type="password" name="Spassword" value="" size="12" />
</td>
<td align="right" colspan="2">
<input type="Reset" value="Clear">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>



I added the comments in only for this post, so they're not in my actual code (just in case I did them wrong).
the problem I'm having is that the user and pass are right but I still get my "Could not log in" errString and it's about to drive me up a wall trying to figure it out.

thanks again for all the help,



Of all the things I've lost, I miss my mind the most (Ozzy Osbourne)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 12-13-2004 22:48

First thing I saw wrong: (Line 16)

code:
if (Spassword == $pass) {


Look at it and tell me if you see anything wrong...

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 12-14-2004 22:48

oh man....

thanks again zavaboy



Of all the things I've lost, I miss my mind the most (Ozzy Osbourne)

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 12-14-2004 23:23

No problem, I'm happy to help in my field of expertise.

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 12-21-2004 04:46

I'm trying to get my site set up in EasyPHP on win98SE, but I'm having trouble with setting up the MySQL database. any help?

[edit]
it appears that I have the db installed correctly, just that I can't get the page variable from the address bar... I get the error:

quote:
Notice: Undefined variable: page in c:\program files\easyphp1-7\www\ixifx.net\news.php on line 71



code:
if($page == "topics"){



page can be "topics" or the variable $date. the code works fine on my website, but not through EasyPHP
[/edit]



You could stand me up at the gates of hell, but I won't back down (Tom Petty)

(Edited by I X I on 12-21-2004 05:23)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-21-2004 06:45

This is set in your php.ini file it's the register globals setting.

I can't remember for sure but I think this should be in either your windows or windows/system directory. Either way just do a search for it, edit the config file and then restart your server.

Make sure you read the documentation on why this has been turned off by default as of the latest builds and how to use the $_ENV $_GET $_POST $_COOKIE, and $_SESSION arrays instead.



.:[ Never resist a perfect moment ]:.

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 12-22-2004 23:01

wow that ini file confused me! but I was playing around with the arrays and got it figured out. thanks bitdamaged

ok, now, I'm having a little glitch that I can't seem to figure out. the page is
http://www.ixifx.net/Nboard.php?page=topics

as of now it's outputting each page's topic, whereas I only want 1instance of each topic

I'm still just playing around with it all... but I'm getting further on my own, there are less things that confuse me which shows me that I'm learning at least a little bit

here's the code from my switch statement

code:
case "topics":
?>
<h2>
Select a topic to view.
</h2>
<h3>
<?
$Data = mysql_db_query("ixifx_net","SELECT * FROM board");
while ($AA = mysql_fetch_array($Data)) {
$topic = $AA["topic"];
echo " <a href=\"Nboard.php?page=$topic\">$topic</a><br>\n";
}
?>
</h3>
<a href="Nboard.php?page=new">Create a new topic.</a>
<?
break;



also, if the user goes to Nboard.php (without a page variable) it brings up the reply form with no other info... I would like to redirect this to the topics page, but I can't even find exactly where it's getting the form from, because I have 3 instances of it in the whole script

but I digress...

any help, as always, is greatly appreciated



You could stand me up at the gates of hell, but I won't back down (Tom Petty)

« BackwardsOnwards »

Show Forum Drop Down Menu