473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How Can I get PHP script to work in a MySQL row?! (Please help ASAP!)

Hi, I've almost set myself up a fully working CMS type thing, all that I'm lacking is a submission form, which I've made. for the pages, I'm using url variables, which are all attached to a column in my table, but for the submission form, I'm hoping to be able to use SQL, see, just say I went to www.site.com?act=page

in a file called vars.php, i have made it so that when you type in www.site.com?act=page, it finds the 'act' column in my table, and then echoes what's in the field under the same row as that act:

--------------------------------------------------------------------------------------------------+
content | title | act |
--------------------------------------------------------------------------------------------------+
Hello all! this is our homepage. Enjoy | Home | home |
--------------------------------------------------------------------------------------------------+

so that's my table, the page detects the $act url variable, and if it matches anything in the act column, it echoes what's in the content column of that row.

So a page of index.php?act=home would say:
Hello all! this is our homepage. Enjoy


Now onto my problem, for my page to make new pages, index.php?act=newpage, I want to have my form, including the php it needs to work in the content field, this is my code:

[PHP]<?php

$do = $_GET['do'];

if ( $do = submit ){
$title = $_POST['title'];
$content = $_POST['content'];
$act = $_POST['act'];

mysql_query("INSERT INTO pagecontent
(title, content, act) VALUES('$title', '$content', '$act' ) ")
or die(mysql_error());
echo 'Your page was successfully, if you&rsquo;d like to have your page put onto the menu, ask an Admin to put it up for you. (Please don&rsquo;t try to do it yourself!);
}

else {
echo '
<form method="post" action="index.php?act=newpage&do=submit">
<table cellspacing="0">
<tr>
<td>Page Title </td>
<td><input name="title" type="text" id="title" /></td>
</tr>
<tr>
<td>Page Content </td>
<td><textarea name="content" cols="50" rows="10" id="content"></textarea></td>
</tr>
<tr>
<td>Page URL </td>
<td>http://www.habbohero.com/?act=
<input name="act" type="text" id="act" size="5" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value=" Create the Page! " /></td>
</tr>
</table></form>';} ?>[/PHP]

Is there any way I could get the php to work when i visit the form?
Aug 24 '08 #1
8 1726
Bump?
Come on, someone help me out?
Aug 25 '08 #2
coolsti
310 100+
I don't know, would this even have a chance of working?

I stopped looking at your code when I noticed that you are mixing both $_POST and $_GET variables. Usually you use only one, not both. $_POST is better in my opinion, as you do not have lots of things tacked on to your URL (which can then easilly be manipulated).

In your case, you are sending do=submit to be read in the $_GET array, but accessed when someone clicks submit on a form. Why not have this action is equal to submit sent as a $_POST variable instead, to be consistent?
Aug 25 '08 #3
I don't know, would this even have a chance of working?

I stopped looking at your code when I noticed that you are mixing both $_POST and $_GET variables. Usually you use only one, not both. $_POST is better in my opinion, as you do not have lots of things tacked on to your URL (which can then easilly be manipulated).

In your case, you are sending do=submit to be read in the $_GET array, but accessed when someone clicks submit on a form. Why not have this action is equal to submit sent as a $_POST variable instead, to be consistent?
All I'm using $_GET to do is get the URL variables, $_GET gets the $do variable from the url, if $do = submit, it submits the form results to the db, otherwise it displays the form (which is why i have the form's action as: index.php?act=newpage&do=submit ... the act is the page itself, my code (in vars.php) matches the url variable act with one from the db, so I want to be able to get the PHP code in my first post into a field of the table, and have it work if I go to index.php?act=newpage



Is it even possible to have PHP code inside a table field and have it run on a page as if it was on the page itself? If so, how?
Aug 25 '08 #4
coolsti
310 100+
There are several good books out and also web links that give good intro explanations to PHP and how it works together with a web server to produce HTML code in a client-server environment. Perhaps a look there first?
Aug 25 '08 #5
There are several good books out and also web links that give good intro explanations to PHP and how it works together with a web server to produce HTML code in a client-server environment. Perhaps a look there first?
I'm perfectly fine with PHP and HTML, all I really need to know is how to have php/html in a table field, and have it execute on a page as if it was on the page itself
Aug 25 '08 #6
coolsti
310 100+
I'm perfectly fine with PHP and HTML, all I really need to know is how to have php/html in a table field, and have it execute on a page as if it was on the page itself
Sorry, then, perhaps I am completely lost in what you are asking for. Maybe it is a language misunderstanding. What do you mean by "in a table field"? Do you mean in a database table? Or in an HTML table, like <table><tr><td>... etc.?

And I think you ought to explain what you mean by "and have it execute on a page as if it was on the page itself". This is confusing. Because, as you know since you are perfectly fine with PHP and HTML, PHP does not execute on the client PC, but on the server that creates the HTML and sends it to the client's page. So I am not sure what you are meaning here.
Aug 25 '08 #7
Sorry, then, perhaps I am completely lost in what you are asking for. Maybe it is a language misunderstanding. What do you mean by "in a table field"? Do you mean in a database table? Or in an HTML table, like <table><tr><td>... etc.?

And I think you ought to explain what you mean by "and have it execute on a page as if it was on the page itself". This is confusing. Because, as you know since you are perfectly fine with PHP and HTML, PHP does not execute on the client PC, but on the server that creates the HTML and sends it to the client's page. So I am not sure what you are meaning here.
what I mean is, have it in a MySQL table, then when I get it from the table (I'm fine with knowing how to do that too), put it in an array with mysql_fetch_array(); and then echo the part of the array I want (in this case, 'content' since that's the name of the MySQL Column i have the code up top in)
and then when I echo/print it, i was hoping it would be executed the same way it would have been if I just had an empty page with the code, not using MySQL
Aug 26 '08 #8
coolsti
310 100+
Ah ok I think I understand now. Let me try. You wish to have the PHP code that is stored in the database as text be executed when the user "activates" it, in this case when they wish to create a new page.

The PHP code that is stored in the database is just text. It can be retrieved by, for example, a PHP script, but in order for it to be executed on the server in order to perform its tasks, it needs to be executed. So your code that is saved in the database has to be written in such a way that it can be fed into a PHP snippet that executes the strings stored in the database as PHP code. This is possible, but may be unsafe (you would be evaluating code that you do not have absolute control of, say if the database was hacked) so you need to do some checks to see that the code is correct.

To do this, see the eval() function in PHP. You would have to write the script that gets stored in the database in such a way that it all can become evalutated with the eval() function, including any HTML that is to be printed directly to the user.

You may want instead to write PHP functions as normal scripts, not in the database, which do the task you wish to have done, and just find some way of calling this when needed.
Aug 26 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Timo-Pekka Oikarinen | last post by:
Is there PHP chat script *without* MySQL? Demands: absolutely FREE (no adware, shareware etc.), No MySQL needed, one permanent public chat, can make your own channels (public/private) like IRC,...
0
by: eric cocozza | last post by:
Hi, I just moved a python program to a new server, and I'm getting path errors. It relys on the pear library and a image processing one. Please respond with cost based on 1/hr of work, and...
0
by: patrick | last post by:
I am a dummy in mysql and start playing with it. My question is when I try to write a simple script: data=`cat data.txt` mysql -ppassword -e 'use db_1;update table_1 set Value = '$data' where...
0
by: rigo | last post by:
I have an .asp scrip to retrieve information from a Sybase database, running it on NT server (IIS4) work fine. When I am runing the same script on server 2003 (IIS6) work fine when the rows to...
0
by: wesley | last post by:
Hi All, can a mysql trigger call a php script? If so, how? I basically want a php script to be called everytime a field in the mysql table receives a certain value Thanks Wes
3
by: dburdick | last post by:
I was referred to this forum as this may be a php specific problem. Some kind of configuration problem maybe. I have some php files that connect to a mysql database and are run as cron jobs. ...
3
by: MrHelpMe | last post by:
Hello experts and thanks so much for having a look at this. I have the following peice of code that I am stumped on. <table width="90%" cellpadding=0 align="center"> <tr> <td...
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
10
by: Ohmster | last post by:
I am trying to use this cool script that some MIT guy wrote and it just does not work, I get a stream of errors when I try to run it. It is supposed to visit a URL and snag all of the pictures on...
1
by: amit2781 | last post by:
Hi, Can you please tell me how to run the sql script on mysql prompt? I tried the command but not succesfull. C:\MySQl\bin:> mysql --u=root --p=amit < mysql.sql C:\MySQl\bin:>source <...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.