473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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?ac t=page

in a file called vars.php, i have made it so that when you type in www.site.com?ac t=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=h ome would say:
Hello all! this is our homepage. Enjoy


Now onto my problem, for my page to make new pages, index.php?act=n ewpage, 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("IN SERT 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.p hp?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.c om/?act=
<input name="act" type="text" id="act" size="5" /></td>
</tr>
<tr>
<td colspan="2"><in put 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 1747
AlexthePirate
5 New Member
Bump?
Come on, someone help me out?
Aug 25 '08 #2
coolsti
310 Contributor
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
AlexthePirate
5 New Member
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=n ewpage&do=submi t ... 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=n ewpage



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 Contributor
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
AlexthePirate
5 New Member
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 Contributor
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 misunderstandin g. 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
AlexthePirate
5 New Member
Sorry, then, perhaps I am completely lost in what you are asking for. Maybe it is a language misunderstandin g. 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_arr ay(); 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 Contributor
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
9457
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, several admins (one superadmin, me ;-D ), bad word filter, user nick ban/ip ban/kick (temporary/permanent), small file sharing and @time script ( http://www.swatch.com/internettime/home.php ) to upper right corner. Environment: Windows 2000 Pro...
0
1115
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 please accept paypal, or other simple form of payment. Thanks!
0
1347
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 Field_1 = "some_value" and Field_2 = "some_other_value";' when run the script, I got error: ERROR 1049: Unknown database '12345 where Field_1 = "some_value" and
0
1117
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 retrieve are less than 700, when retrieving large amount of data I got the following error message using IE "Action canceled Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable." and "Document...
0
5927
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
2584
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. The scripts work fine when run via the command line as root, but when run via the cron they cause a mysql connection error. Call to undefined function: mysql_pconnect()
3
1314
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 align="left"><font face="arial,helvetica" size=4 Color = "8CB811"><b><%= Trim(objRS("Category")) %></b></font></td> </tr> <%
3
2152
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 Record (i) is shown and modified, the change will come to Record (i+1). Can anyone provide suggestion? thanks.
10
4373
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 the site. Here is the script: http://web.mit.edu/pgbovine/www/image-harvester/image-harvester.py Here is my output when I try to run it on my Fedora 6 machine: $ image-harvester.py http://public.fotki.com/DaGennelman/
1
5498
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 < MySQL51amit_CL_Inst_1.txt
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.