Varible help
Moderator: General Moderators
Varible help
On my website I want the users to be able to display information from my database without having to use php but varibles. I have no clue how to do this but im sure you need to set the varibles first and need some help in doing it. The users have the option to edit the code on the site and to display the information they can use tags like [posts] how would i do this?
thanks
thanks
Re: Varible help
You will not be able to make a database connection without some type of server side scripting (PHP,JSP,ASP) Another alternative could be to use Macromedia Flash, but based off of what your saying that solution may not be feasible.ek5932 wrote:I want the users to be able to display information from my database without having to use php but varibles.
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
Okay, the only reason you'd need PHP is to get the info from the database. Before you can use your variables, they must be given values. In order for your variables to be given values, those values need to come from somwhere. BOOM, the database. Assuming you are using MySQL, you can do something like this:
If you need more help, I suggest reading a PHP-MySQL tutorial, or better yet, book.
Good luck!
Code: Select all
<?php
//establish a MySQL connection
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("your_database_name", $db);
//set up a query (request to the database) for your info
$query = "SELECT list_fields_here_or _use_*_for_all_fields FROM yourtable WHERE " //set up a condition, such as $foo='bar'
//execute your request
$result = mysql_query($query, $db);
//now you have the result, but you need to be able to access it through a variable. You also need a loop in case there is more than one result:
while ($row=mysql_fetch_array($result)){
//here you can do whatever you want, my guess would be output the data.
//you can do it like this: (let's say you want a table)
?>
<table>
<tr>
<td><?php echo $row['your_field_name']; ?></td>
</tr>
<?php
//the above will ctreate a table of all the values of one column gotten from the database.
}
?>Good luck!
Try this:
Page 1 form:
Page 2:
Page 1 form:
Code: Select all
<form name="form1" method="post" action="">
<input type="text" name="textfield">
<input type="checkbox" name="checkbox" value="checkbox">
<input type="radio" name="radiobutton" value="radiobutton">
</form>Code: Select all
<?php
echo '<PRE>'; print_r($_POST); echo '</PRE>';
echo $_POST['textfield'].'<BR>';
echo $_POST['checkbox'].'<BR>';
echo $_POST['radiobutton'].'<BR>';
//The variables can also be accessed without the $_POST
echo $textfield.'<BR>';
echo $checkbox.'<BR>';
echo $radiobutton.'<BR>';
?>Only with register_globals turned ON, it's OFF by default.The variables can also be accessed without the $_POST
Grr no one seems to get what I mean. I have seen it on a site before. Basicly what I am trying to do is create a script where the user can edit the content of the page using a text field but instead of allowing them to post the php instead using my own language which just refers to the php. Eg if the user was to insert
<td>Username</td><td>Posts</td>
</tr><tr>
<td>[username]</td><td>[posts]</td>
[username] would be <? echo ("$username"); ?> but the users see it and edit it in my own sort of language.
<td>Username</td><td>Posts</td>
</tr><tr>
<td>[username]</td><td>[posts]</td>
[username] would be <? echo ("$username"); ?> but the users see it and edit it in my own sort of language.