Database and tables.... and mysql in general....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Faith
Forum Newbie
Posts: 7
Joined: Sun Mar 14, 2004 10:30 pm

Database and tables.... and mysql in general....

Post by Faith »

Ok, i have a database set up, i have a table set up, i've routed the script, but now i can't get the information on the form to save to the table in the database... how do i get it to do that? am i forgetting something in my script? ok i'm kinda embarressed :oops: i'm very nieve when it comes to Mysql and PHP. I'm almost certain i'm forgetting something but i can't be sure... the page where my script is on is http://game.equestracing.net/phpstuff2/display.php
I hope someone can help me cuz i have NO clue what i'm doing....
Also, i was getting syntax errors earlier so i added a database route... i'm pretty sure that's what i added, and the ummm errors when away... so yeah... :?: :?: :?: i'm so lost!!!!!!!!!!!!
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Can you show some of the actual php code?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

best thing to do is find a script on hotscripts.com that sends data from a form, and posts it to a mysql database.. you can usually see what they are doing, and t hen just copy the code and rewrite it however you need.

however, you are still gonna need a basic understanding of how to use function calls within php to mysql.. and to the $_POST form data..

here is a quick easy/short little example to do what you are wanting though :

page_1.htm

Code: Select all

<html><head><title>bob</title></head>
<body>
<form method="POST" action="go.php">
Enter a name : <input type="text" name="full_name">
<br>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
go.php

Code: Select all

<?php

if(!isset($_POST['full_name']))
{
   echo 'You must enter a name before we can proceed... Please Try again.';
   exit;
}
$name = $_POST['full_name'];

mysql_connect('localhost','username','password') or die(MySQL_Error());
mysql_select_db('my_db_name') or die(MySQL_Error());

$sql = "INSERT into mytable (name) values ('".$name."')";
$result = mysql_query($sql) or die(MySQL_Error());

echo $name.' successfully added to Table.';
mysql_close;
?>

of course this may not work as you need it to, but you get the idea... just kinda wrote it up real quick for ya.

anyways, here are some links of interest you need to definately check out :

http://www.hotscripts.com - Great source for pre-written scripts of all kinds
http://www.evilwalrus.com - Same as Hot Scripts
http://www.php.net/mysql - Starting block to understanding all the possible mysql functions used in php
http://www.google.com - Your and My #1 stop for questions... type in a question, press search, generate results. can't go wrong :P

hope this helps.

edit : may also want to check out the MySQL Manual as well... When you downloaded mysql, it includes a Manual in the directory in which you installed it. Otherwise, just check out MySQL's website. They have an online manual there as well.
Post Reply