PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 8th, 2004, 11:39 PM
SteveS235 SteveS235 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 SteveS235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
A PHP that adds user input into SQL

Well, hopefully you folks here can help me out, as I am just learning my way through PHP.

My current site is a directory type site, where users can submit info using a reular HTML form which emails the info to me. I then take those emails and update the code by hand then uplaod to the server. Well, spare time is getting shorter each day, so I want to automate this process using SQL.

I want the users to be able to submit the info, which will automatically be placed into SQL, then have certain info called and displayed throughout the site.

I found some code for a PHP form, but I get a parse error, Can somone here take a look to see if I'm even close to what I want to do?

PHP Code:
<?php
        
if ( isset( $name ) && isset( $type ) && isset ( $description ) ) {
            
// check user input here!
            
$dberror "";
            
$ret add_to_database$name$type$description );
            if ( ! 
$ret )
                print 
"Error: $dberror<BR>";
            else
                print 
"Thank You!";
        } else {
            
write_form();
        }
        
        function 
add_to_database$name$type$description, &$dberror ) {
            
$user "xxxxxx";
            
$pass "xxxxxx";
            
$db "xxxxxx";
            
$link mysql_pconnect"mysql03.powweb.com"$user$pass );
            if ( ! 
$link ) {
                
$dberror "Couldn't connect to MySQL server";
                return 
false;
            }
            if ( ! 
mysql_select_db$db$link ) ) {
                
$dberror mysql_error();
                return 
false;
            }
            
$query "INSERT INTO domains ( name, type, description )
                    values( '$name', '$type', $description' ) ) {
            if ( ! mysql_query( $query, $link ) ) {
                $dberror = mysql_error();
                return false;
            }
            return true;
        }
        
        function write_form() {
            global $PHP_SELF;
            print "
<form method="POST\">\n";
            print 
"<input type=\"text\" name=\"name\"> ";
            print 
"Your name or your band's name:<P>\n";
            print 
"<select name=\"type\"\n";                                         
            print 
"\t<option value=\"Gigs - Guitar\"> Gigs - Guitar\n"
            print 
"\t<option value=\"Gigs - Bass\"> Gigs - Bass\n";
            print 
"\t<option value=\"Gigs - Drums\"> Gigs - Drums\n";
            print 
"\t<option value=\"Gigs - Vocals\"> Gigs - Vocals\n";
            print 
"\t<option value=\"Gigs - Keyboards\"> Gigs - Keyboards\n";
            print 
"\t<option value=\"Gigs - Horns\"> Gigs - Horns\n";
            print 
"\t<option value=\"Gigs - Multiple\"> Gigs - Multiple Positions\n";
            print 
"\t<option value=\"Management Wanted\"> Management Wanted\n";
            print 
"\t<option value=\"Gigs - Guitar\"> Gigs - Guitar\n";
            print 
"</select>\n";
            print 
"<input type=\"text\" name=\"description\"> ";
            print 
"Enter a brief description, including your email and website:<P>\n";
            print 
"<input type=\"submit\" value=\"submit!\">\n</form>\n";
        }
        
?>


The parse error seems to be with the POST statement, but I have no idea what needs to be fixed.

Please be gentle as I know literally nothing about PHP.

Also, is there a way to do this without having to have the username and password in the code itself?

Thanks in advance.


EDIT: there is a \ right after the = sign in the POST statement, but it doesn't show in the code above. Could that be what it is? Maybe the browser can't read it the way I have it?

Reply With Quote
  #2  
Old January 9th, 2004, 01:03 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Here's your error... in the write_form() function:

print "<form method="POST\">\n";

you need to put a backslash before the one quote, in order to tell PHP to escape the quote...

So the line should read:
print "<form method=\"POST\">\n";

this way, when the line is parsed, the HTML will read as expected: <form method="POST">

For future reference, it helps to give us the exact error, and perhaps the block of code that you think the error is coming from... saves people from having to read every single line...

Best of luck learning PHP!

Reply With Quote
  #3  
Old January 9th, 2004, 01:15 AM
SteveS235 SteveS235 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 SteveS235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The backslash is there. When I pasted the code in the above post, it didn't show.

The error I'm getting is this:

Parse error: parse error in /www/m/musicians/htdocs/test.php on line 157

Line 157 is the print "<form method=\"POST\">\n"; line.

Is there another way to write that line?

Reply With Quote
  #4  
Old January 9th, 2004, 01:34 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Now that I look at it, is there a reason that block of code is interpretted by php?

With PHP you can always escape PHP and write normal HTML...

Example:
PHP Code:
function function write_form() {
?>
<form method="POST">
<input type="text" name="name"> Your name or your band's name:<P>
<select name="type"
    <option value="Gigs - Guitar"> Gigs - Guitar
    <option value="Gigs - Bass"> Gigs - Bass
    <option value="Gigs - Drums"> Gigs - Drums
    <option value="Gigs - Vocals"> Gigs - Vocals
    <option value="Gigs - Keyboards"> Gigs - Keyboards
    <option value="Gigs - Horns"> Gigs - Horns
    <option value="Gigs - Multiple"> Gigs - Multiple Positions
    <option value="Management Wanted"> Management Wanted
    <option value="Gigs - Guitar"> Gigs - Guitar
</select>
<input type="text" name="description"> Enter a brief description, including your email and website:<P>
<input type="submit" value="submit!">
</form>
<?
// end write_form 


*edit* It didn't show up as I expected on my screen, but notice the ?> and <? surrounding the HTML... that's important... =) *edit*

This is cheating, I know... honestly, this line print "<form method=\"POST\">\n"; should work...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > A PHP that adds user input into SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT