Soo… I’m a newb and need some help.
I know this is a lot of information, so thank you for your time =]
I’m trying to do a basic website in which I accept information via fields and then insert them into my database. I’ve got it to the point in which I can create a database via html and display data already in the database.
I have been using this tutorial to get me to where I’m at now:
http://www.freewebmasterhelp.com/tutorials/phpmysql/
Here is the code I’m using for the form section.:
[code]
Date: //Title:
Location:
Other:
[/code]
From what I understand this (when submit is clicked) passes the information via a url to my newsInsert.php page. As I get a url that looks like this when i click it: (filled out with 01 01 0001 Test Test Test)
http://infinitysocial.net/newsInsert.php?day=01&month=01&year=0001&title=Test&location=Test&other=Test
So essentially I need help getting that information from there into some java script so I can use the variables in my php to put it in my database.
Here is what I’ve done so far on my newsInsert.php page.
[code][/code]
[php]<?
//the below section contains password information to log into my datbase =/ just fyi
include(“NewsDB.AiNFO.php”);
$date=$_POST[‘date’];
$title=$_POST[‘title’];
$location=$_POST[‘location’];
$other=$_POST[‘other’];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query = “INSERT INTO news VALUES (’’,’$date’,’$title’,’$location’,’$other’)”;
mysql_query($query);
mysql_close();
?>[/php]
I don’t know how to associate the javascript variables with variables inside my php. And I don’t know if my parameters the way they are set up with the forum actually are getting the data or not.
And finally I’m confused by some of the php code:
[php]$query = “INSERT INTO news VALUES (’’,’$date’,’$title’,’$location’,’$other’)”;
mysql_query($query);[/php]
^How does this get into my database? I see that it uses variable $query to put in all the other variables into one… and then we call that variable $query with mysql_query()? sooo… it’s saying to run mysql_query() which is php to say to run something as SQL i assume? and the INSERT INTO news Values will put that data () into my database? Sound about right? The reason i ask is cause I was trying to use sample code prior to this to put in information into my news DB and it wasn’t going in. Is there something missing in the php section?
I figure I better include this in case it becomes important for an answer or anyone else trying to learn from this question. This is the php i used to set up my table in my news DB:
[php]<?php
//Creates a “news” Table in News Database if its not there, with the fields.
include(“NewsDB.AiNFO.php”);
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query=“CREATE TABLE news (id int(100) NOT NULL auto_increment,date varchar(10) NOT NULL,title varchar(255) NOT NULL,location varchar(255) NOT NULL,other varchar(255) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))”;
mysql_query($query);
mysql_close();
?>[/php]