I'm having some trouble with a form I'm putting together. I'm pretty new to PHP. Any help would be greatly appreciated.
The "month," "date," "year," and "state" fields are in a drop-down menu on the form and as part of a set in my database. The form itself is at <!-- m --><a class="postlink" href="http://readings.wordriot.org/form.html">http://readings.wordriot.org/form.html</a><!-- m -->.
Below is the script that the form posts to with all my password/login info blocked out, but with everything else unchanged.
<?
//MySQL Variables. Edit where necessary
$host = "____";
$login_name = "_____";
$password = "______";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");
//Select the database
mysql_select_db("_______");
//connected to DB
$comments = $_POST['comments'];
$event_title = $_POST['event_title'];
$venue = $_POST['venue'];
$description = $_POST['description'];
$month = $_POST['month'];
$date = $_POST['date'];
$year = $_POST['year'];
$time = $_POST['time'];
$street = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$website = $_POST['website'];
//Now lets do a query to add the info
$sql = "
INSERT INTO web_readings SET
comments = '$comments',
event_title = '$event_title',
venue = '$venue',
description = '$description',
month = '$month',
date = '$date',
year = '$year',
time = '$time',
street = '$street',
city = '$city',
state = '$state',
contact_name = '$contact_name',
contact_email = '$contact_email',
website = '$website'
";
//run the query
$query = mysql_query($sql);
//if statement to check if query was a success
if ($query) {
echo("Info added");
} else {
echo("Could not add info");
}
//Close connection with MySQL
MySQL_close()
?>not sure what you want. but that script is for creating a table in the db. if you post to it then it will do that a lot of times which you do not want.
so if you want to post a form then you need to look in _POST in the php manual, <!-- w --><a class="postlink" href="http://www.php.net/manualsince">www.php.net/manualsince</a><!-- w --> when does "insert into" create a table?
it seems ok to me, what the problem of the script?serves me right for just glancing at it. looked like a phpmyamdin create table. i also tried this as a script based on another forum post by scoutt, but i couldn't get it to work for me.
<?
//MySQL Variables. Edit where necessary
$host = "127.0.0.1";
$login_name = "______";
$password = "_____";
//Connecting to MYSQL
$db = mysql_connect("$host","$login_name","$password");
// Selects the database
mysql_select_db('wordriot_org_-_bbs', $db);
// Inserts the record
mysql_query ("INSERT INTO web_readings ('id','comments', 'event_title', 'venue', 'description', 'month', 'date', 'year', 'time', 'street', 'city', 'state', 'contact_name', 'contact_email', 'date', 'year', 'website') VALUES ('','{$_POST['$comments']}', '{$_POST['$event_title']}', '{$_POST['$venue']}', '{$_POST['$description']}', '{$_POST['$month']}', '{$_POST['$date']}', '{$_POST['$year']}', '{$_POST['$time']}', '{$_POST['$street']}', '{$_POST['$city']}', '{$_POST['$state']}', '{$_POST['$contact_name']}', '{$_POST['$contact_email']}', '{$_POST['$website']}')");
print ("Data entered successfully");
?>
Any suggestions would be greatly appreciated.$query = mysql_query($sql) or exit(mysql_error());
it will print out any error return by mysql!thanks! now i got it -- i had misnamed a field
The "month," "date," "year," and "state" fields are in a drop-down menu on the form and as part of a set in my database. The form itself is at <!-- m --><a class="postlink" href="http://readings.wordriot.org/form.html">http://readings.wordriot.org/form.html</a><!-- m -->.
Below is the script that the form posts to with all my password/login info blocked out, but with everything else unchanged.
<?
//MySQL Variables. Edit where necessary
$host = "____";
$login_name = "_____";
$password = "______";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");
//Select the database
mysql_select_db("_______");
//connected to DB
$comments = $_POST['comments'];
$event_title = $_POST['event_title'];
$venue = $_POST['venue'];
$description = $_POST['description'];
$month = $_POST['month'];
$date = $_POST['date'];
$year = $_POST['year'];
$time = $_POST['time'];
$street = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$website = $_POST['website'];
//Now lets do a query to add the info
$sql = "
INSERT INTO web_readings SET
comments = '$comments',
event_title = '$event_title',
venue = '$venue',
description = '$description',
month = '$month',
date = '$date',
year = '$year',
time = '$time',
street = '$street',
city = '$city',
state = '$state',
contact_name = '$contact_name',
contact_email = '$contact_email',
website = '$website'
";
//run the query
$query = mysql_query($sql);
//if statement to check if query was a success
if ($query) {
echo("Info added");
} else {
echo("Could not add info");
}
//Close connection with MySQL
MySQL_close()
?>not sure what you want. but that script is for creating a table in the db. if you post to it then it will do that a lot of times which you do not want.
so if you want to post a form then you need to look in _POST in the php manual, <!-- w --><a class="postlink" href="http://www.php.net/manualsince">www.php.net/manualsince</a><!-- w --> when does "insert into" create a table?
it seems ok to me, what the problem of the script?serves me right for just glancing at it. looked like a phpmyamdin create table. i also tried this as a script based on another forum post by scoutt, but i couldn't get it to work for me.
<?
//MySQL Variables. Edit where necessary
$host = "127.0.0.1";
$login_name = "______";
$password = "_____";
//Connecting to MYSQL
$db = mysql_connect("$host","$login_name","$password");
// Selects the database
mysql_select_db('wordriot_org_-_bbs', $db);
// Inserts the record
mysql_query ("INSERT INTO web_readings ('id','comments', 'event_title', 'venue', 'description', 'month', 'date', 'year', 'time', 'street', 'city', 'state', 'contact_name', 'contact_email', 'date', 'year', 'website') VALUES ('','{$_POST['$comments']}', '{$_POST['$event_title']}', '{$_POST['$venue']}', '{$_POST['$description']}', '{$_POST['$month']}', '{$_POST['$date']}', '{$_POST['$year']}', '{$_POST['$time']}', '{$_POST['$street']}', '{$_POST['$city']}', '{$_POST['$state']}', '{$_POST['$contact_name']}', '{$_POST['$contact_email']}', '{$_POST['$website']}')");
print ("Data entered successfully");
?>
Any suggestions would be greatly appreciated.$query = mysql_query($sql) or exit(mysql_error());
it will print out any error return by mysql!thanks! now i got it -- i had misnamed a field