FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Problem in creating a dynamic form





flintstonian
Hi folks,

I wrote the following code to get some data from a database and make a form:
Code:

$result = mysql_query("SELECT title FROM myTable where id = ".$_GET['artid'].";");

$entryform = "<form>";
$entryform .= "<table>";
$entryform .= "<tr><td>Article Title:</td><td><input type = text name = artid value =".$row['title']."></td></tr>";
$entryform .= "<table>";
$entryform .= "</form>";


Then I use $entryform to make my form in the page. This is the problem:

if $row['title'] = 'Tommy had a cat', the value in the text box is just 'Tommy'.

What am i doing wrong? How to correct this?
You'd have seen by now that I'm a nu-b, so any help and suggestions will be very much appreciated.
ncwdavid
Im not sure why you want to create a form by getting the code from the database but anyways. That mysql query doesn't look right I dunno why though. I think too many "" of those. Use '$variable name'. But please explain exactly what its for and all the code and stuff.
flintstonian
Well, don't laugh, but I'm trying to make a small CMS.

This is the overall picture:

There is a left panel has a list of article titles as hyperlinks. When I click on one of the links, i go to xyz.php?id=2, then use the id to open the correct record. Then I load the id, article title and article text in a form (this is the code i posted). I make changes, and then save it back. Everything seems to work...in a rickety fashion. The article loads correctly, but in the title, only the first word is seen in the text box.

I dunno if all this is dumb - u see, i'm learning by trial and error Razz
flintstonian
Sorry, It was just a dumb mistake. I just missed putting in two apostrophes. It's working now. stupid, ain't i? Thanx for the reply.

Anyway, now that I've bothered you, how about some suggestions abt my code? am i doing too bad or is it ok to write code like this? you said, way too many "'"'". what's the proper way to do it?

u see, as i said, i'm just starting out, and i'm just testing the waters by trial and error.
ncwdavid
Well if your just starting writing a CMS even if its just a small one will be hard work. Just try and make a simple user registration script first then work your way onto bigger things because I would say making the CMS you will just google some code to do something then just copy and paste it into your code and you will not learn anything from that trust me ive done it before and it didnt help.
flintstonian
ncwdavid wrote:
.... you will just google some code to do something then just copy and paste it into your code and you will not learn anything from that trust me ive done it before and it didnt help.


me too Razz I tried googled code once, and found it'd be better to do things the hard way if I'm to really understand what I'm doing. So I've started writing my own code and making lotsa mistakes - anyway its fun. The thing I'm trying to make isn't all that important, so its just a way of learning for me.
kv
Code:

$result = mysql_query("SELECT title FROM myTable where id = ".$_GET['artid']);

//You need to fetch the data from result before using it
$row = mysql_fetch_array($result) or die(mysql_error());

$entryform = "<form>";
$entryform .= "<table>";
$entryform .= "<tr><td>Article Title:</td><td><input type = text name = artid value =".$row['title']."></td></tr>";
$entryform .= "<table>";
$entryform .= "</form>";
Vovochka
flintstonian wrote:
Code:

$result = mysql_query("SELECT title FROM myTable where id = ".$_GET['artid'].";");
It's not safe to write like you do. SQL injection is possible.
Try this code:
Code:
$result = mysql_query('SELECT title FROM myTable WHERE id='.intval($_GET['artid']));
Related topics
America's Army
No backups anymore?
need php help save command
HTML
Ok I seem to be full of questions lately...
creating guestbooks (form) with php & mysql
DreamWeaver or Visual Studio
problem creating on-the-fly jpeg thumbnails
ImageMagick - How to add text?
[PHP] Problem with Dynamic Sig's Font Color
Back slash appears in form output
Problem creating new table and inserting
changing form entry values before submit
Dynamic Signatures get page content?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.