Form help
Moderator: General Moderators
Form help
does anyone have a code or could show me how to make like a form that can add like something on to a page and take off stuff on a page because im making a website for a friend and she wanted it where she doesnt have to log into the cpanel just to add alittle data onto a page so i told her i would make a form so she wouldnt have too could some show me how?
thank you Smackie
thank you Smackie
basically, you could do something with mysql. it's actually the easiest method..
something like this would work :
1) create a table, one with a field value of text
2) then, create a page that would fill this field with data you wanna display. You could even go so far as to post what they have so far, and allow them to either a) edit the current textarea or b) delete it and post a new one. :
3) then, in the display page, have something like :
of course this is very cut and dry. you could setup a number of different methods to go along with this (ie, could make it to where the page is a news page, menaing it keeps track of all entries in the database based on the date, you could add session (and should) checks to verify she has admin rights before information is posted ot hte page, and a number of other methods.
if this is the type of thing you want to do, i'd suggest looking into pre-made scripts (usually found on hotscripts) that does this type of thing, and also checking mysql's online manual for field types and query statements..
hope this helps.
something like this would work :
1) create a table, one with a field value of text
2) then, create a page that would fill this field with data you wanna display. You could even go so far as to post what they have so far, and allow them to either a) edit the current textarea or b) delete it and post a new one. :
Code: Select all
<?php
$sql = mysql_query("select * from mytable") or die(MYSQL_Error());
$row = mysql_fetch_assoc($sql);
$field_data = $row['text_field_name'];
echo '<form method="post" action="mypage.php">';
echo '<textarea name="bob">'.$field_data.'</textarea>';
echo '<input type="submit" name="submit" value="submit changes">';
?>Code: Select all
<?php
$text_area = $_GET['bob'];
mysql_query("INSERT into mytable (text_field_name) VALUES ('".$text_area."')") or die(MySQL_Error());
echo 'Field updated';
?>Code: Select all
<?php
$sql = mysql_query("select * from mytable") or die(MySQL_Error());
$row = mysql_fetch_assoc($sql);
echo '<h3>The current page is to display the following information </h3>';
echo $row['text_field_name'];
?>if this is the type of thing you want to do, i'd suggest looking into pre-made scripts (usually found on hotscripts) that does this type of thing, and also checking mysql's online manual for field types and query statements..
hope this helps.
i have a problem i am trying to make it where it adds more the one field
race.php
mypage2.php
race.php
Code: Select all
<?php
include'config.php';
$sql = mysql_query("select * from race") or die(MYSQL_Error());
$row = mysql_fetch_assoc($sql);
$race = $row['race'];
$outcome = $row['outcome'];
echo '<form method="post" action="mypage2.php">';
echo '<textarea name="race">'.race.'</textarea>';
echo '<textarea name="outcome">'.outcome.'</textarea>';
echo '<input type="submit" name="submit" value="submit changes">';
?>Code: Select all
<?php
include'config.php';
$race = $_GET['race'];
$outcome =$_GET['outcome'];
mysql_query("INSERT into race (race, outcome) VALUES ('".$message.$outcome."')") or die(MySQL_Error());
echo 'Field updated';
?>Column count doesn't match value count at row 1
which page is giving you the error?
secondly, try this instead for your page 2...
edit :
on page one, you need to update this too...
secondly, try this instead for your page 2...
Code: Select all
//other code...
mysql_query("INSERT into race (race, outcome) VALUES ('".$message."','".$outcome."')") or die(MySQL_Error());
//other code...on page one, you need to update this too...
Code: Select all
//other code
echo '<textarea name="race">'.$race.'</textarea>';
echo '<textarea name="outcome">'.$outcome.'</textarea>';
//other codeas i said, might do good to look at mysql manual heh..
first, you are trying to insert $message, but nothing is defined for $message...
Second, you may want to do (instead of INSERT) an UPDATE <clause> where <this is true> for a query...
as i said, may want to look into mysql's online manual, or even take a look at the manual included with your mysql documentation.
i guess i might have confused you just a little, but was just trying to give you an idea of how to do this... i didn't actually post a working method heh.. so you may want to rewrite this script to do what you need how you need it,a nd then post that. cuz my method just merely inserts a new row everytime. it doesn't update the table at all where a variable (in your case race) is needin to be updated...
first, you are trying to insert $message, but nothing is defined for $message...
Second, you may want to do (instead of INSERT) an UPDATE <clause> where <this is true> for a query...
as i said, may want to look into mysql's online manual, or even take a look at the manual included with your mysql documentation.
i guess i might have confused you just a little, but was just trying to give you an idea of how to do this... i didn't actually post a working method heh.. so you may want to rewrite this script to do what you need how you need it,a nd then post that. cuz my method just merely inserts a new row everytime. it doesn't update the table at all where a variable (in your case race) is needin to be updated...
well i think it might be right around this area..
that is screwing up because on the first one i did worked just right and it was mainly what you showed me but it was a one field but this is two fields and i think my problem is around here........
Code: Select all
$race = $row['race'];
$outcome = $row['outcome'];
echo '<form method="post" action="mypage2.php">';
echo '<textarea name="race">'.race.'</textarea>';
echo '<textarea name="outcome">'.outcome.'</textarea>';first, i already posted the correct thing to do with that portion of hte script (look at my message above).
secondly, the reason only one field (for the 3rd time now) is because you are trying to insert $message... but $message is NOT being defined.
Therefore, this query
should actually be this :
secondly, the reason only one field (for the 3rd time now) is because you are trying to insert $message... but $message is NOT being defined.
Therefore, this query
Code: Select all
mysql_query("INSERT into race (race, outcome) VALUES ('".$message.$outcome."')") or die(MySQL_Error());Code: Select all
mysql_query("INSERT into race (race, outcome) VALUES ('".$race."', '".$outcome."')") or die(MySQL_Error());then you should look into these pages available on php's online manual:
Arrays
MySQL Fetch Assoc
For Loops
While Loops
and the MySQL Manual
there is also a MySQL manual located in the distribution on your computer (that is, of course, if you have mysql installed on your machine). It can be reached at //path//to//MySQL/doc/
that should be enough to get you where you need.
Arrays
MySQL Fetch Assoc
For Loops
While Loops
and the MySQL Manual
there is also a MySQL manual located in the distribution on your computer (that is, of course, if you have mysql installed on your machine). It can be reached at //path//to//MySQL/doc/
that should be enough to get you where you need.
Hmm this looks odd to me. Can you use variable names without the $?Smackie wrote:well i think it might be right around this area..
Code: Select all
$race = $row['race']; $outcome = $row['outcome']; echo '<form method="post" action="mypage2.php">'; echo '<textarea name="race">'.race.'</textarea>'; echo '<textarea name="outcome">'.outcome.'</textarea>';
thallish