Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 01-28-2003, 01:21 PM   #1 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default MySQL & PHP Question...

Ok, on my quest of learning PHP and MySQL, i want to make a simple database project. Here's what I want to do:

Create a page where users just use a simple inputbox and drop down list to answer to questions 'name' and 'something (i haven't decided hahah)' and i just want to be able to store it to the database, and then on a sperate page i want to be able to call and print the database. I am good at this part, calling and printing the database. But I just want to know how I would go about taking the user input and storing it . This would be a much appreciated reply with instructions or a website or something like that

Thanks

~Shan
__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-28-2003, 01:27 PM   #2 (permalink)
the flaming hermit
 
Join Date: Jul 2002
Posts: 951
Send a message via ICQ to þÄ®âÐÖx Send a message via Yahoo to þÄ®âÐÖx
Default

You might wanna try this PHP/MySQL tutorial.. it looks pretty simple

http://www.freewebmasterhelp.com/tutorials/phpmysql/1
þÄ®âÐÖx is offline   Reply With Quote
Old 01-28-2003, 01:51 PM   #3 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default

****, looks good. Why couldn't i find that site ? hahaha
__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-28-2003, 02:23 PM   #4 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default

Ok, techies: Riddle me this.

Here's the form,
PHP Code:
<form action="os.php" method="post">
Submit this form

<pre>Your Name:<input type="text" name="name">

Your Os:<select name="os">
        <
option value="Windows 95">Windows 95</option>
        <
option value="Windows 98">Windows 98</option>
        <
option value="Windows ME">Windows ME</option>
        <
option value="Windows 2K">Windows 2K</option>
        <
option value="Windows XP">Windows XP</option>
        <
option value="RedHat Linux">RedHat Linux</option>
        <
option value="Mandrake Linux">Mandrake Linux</option>
        <
option value="Suse Linux">SuSe Linux</option>
        <
option value="Other Linux">Other Linux</option>
        <
option value="Unix">Unix</option>
        <
option value="Sun OS">Sun OS</option>
        <
option value="Other">Other</option>
    </
select>
</
pre>
<
input type="Submit" value="Submit"><input type="Reset" value="Reset"></form
Here's the PHP script from addrec.php
PHP Code:
<?php
        mysql_connect
("localhost""shan""****")
        or die(
"Could not connect, the server may be down, or bad host, user, or password");
    
mysql_select_db("tests") or die("Could not select database");
    
$query "INSERT INTO os VALUES ('', '$os')";
    
$result mysql_query($query) or die("Query failed, please hit back and try again!");
print (
"[b]<u>Database updated you can view it now,  [/b]</u>");
    
mysql_query($query);
mysql_close();
?>
[url="osdb.php"]the database is here[/url]
But when I go to view the database the only thing stored is the Auto Incriment ID. It's up to 6 with six test posts, but the name and os doesn't appear anywhere in the database, any solutions?

EDIT: Actually what it's doing is creating 2 more rows (blank rows) every time you submit. So say there are 8 rows, you enter your name and choose your OS. Well on row 9 should reside the name and OS, but it is blank, along with an added row, 10, which is also blank?
Thanks for all of your help!!!!

~Shan
__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-29-2003, 01:22 AM   #5 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default

argh, I've modified the script to this now,
PHP Code:
<?php

    mysql_connect
("localhost""shan""******") or die("Could not connect to database server");
    
mysql_select_db("tests") or die("Could not locate database");
        
        
$query "INSERT INTO os VALUES ('','os')";

        
$result mysql_query($query) or die("Failure to write to database");
    print(
"[b]<U>Database has been updated</u>[/b] ");

mysql_close();
?>
you may view the database here

Well, now I only get 1 blank line, i guess I'm making progress? ahhahaha
__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-29-2003, 12:34 PM   #6 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default

Hey Shan, I found this on the php website, could this be your problem?
Quote:
Note: The default value for the PHP directive register_globals changed from on to off in PHP 4.2.0.

__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-29-2003, 12:36 PM   #7 (permalink)
the flaming hermit
 
Join Date: Jul 2002
Posts: 951
Send a message via ICQ to þÄ®âÐÖx Send a message via Yahoo to þÄ®âÐÖx
Default

Hahaha, yeah that progress is called "learning"... unfortunately I can't be much help to you as I haven't really looked at MySQL much yet.

Good luck though!
þÄ®âÐÖx is offline   Reply With Quote
Old 01-29-2003, 12:36 PM   #8 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,368
Send a message via AIM to shan
Default

OH WOW, it's about time i figure this out. Thanks for all you help Shan!!!

lmfao!! hahhahhaha

I'm bored at work, hahaha and I didn't sleep well last night, so I'm a little odd today. It's kinda funny I actually found this while on an ASP site researching some stuff for work. I'm so happy.
__________________

C:\\ Is the root of all evil




phiber@sysdum.com
spam this account, it's fun.
shan is offline   Reply With Quote
Old 01-31-2003, 11:53 PM   #9 (permalink)
Junior Techie
 
Join Date: Oct 2002
Posts: 90
Default

OK let me fix up your script a bit..........some of your messaging techniques are quite odd, especially because your script prints "Database updated" before the database is even queried, so if it fails, you look like an idiot. Here's my revisions:
PHP Code:
<?php
$link 
mysql_connect("localhost""shan""******") or die("Could not connect to database server");
mysql_select_db("tests") or die("Could not locate database");

$query "INSERT INTO os VALUES ('0','os')";
$result mysql_query($query) or die(mysql_error($link));
if(
$result)
{
     print(
"[b]<U>Database has been updated</u>[/b] ");
}

mysql_close($link);
?>
OK here's what I added-First it's good to referrence your connection as a variable, that way you can just write the variable as an argument to functions. Second, if you are auto incrementing, you have to out '0' in as your id value, and it will auto-increment then. Lastly, I made your script only write out the "Database updated" message when the query is successful. Hope this helps
ikellen is offline   Reply With Quote
Old 03-23-2003, 10:38 AM   #10 (permalink)
Newb Techie
 
Join Date: Mar 2003
Posts: 5
Default

You can find powerful scripts in
www.hotscripts.com
There are various sample to follow.
wilfredwaterloo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:57 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0