Computing.Net > Forums > Web Development > Php to enter from text in to mysql

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Php to enter from text in to mysql

Reply to Message Icon

Name: Chris (by Chris Kirk)
Date: August 17, 2009 at 07:32:42 Pacific
OS: 2000 pro
CPU/Ram: -
Product: - / -
Subcategory: PHP
Comment:

Hello,
I need some php code to add text that has been put in a form put in the myql database.
this if the form;
<form action="form.php" method="get">
<select name="id">
<option>SELECT YOUR ID</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Enter you path here:
<input name="path" type="text" id="path">
<input type="submit" value="Submit">
</form>

So far i have got in the form.php file;
<?php

// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'password');
if (!$dbcnx) {
die( '

Unable to connect to the ' .
'database server at this time.</p>' );
}
// Select the db_1 database
if (! @mysql_select_db(db_1') ) {
die( '

Unable to locate the db1 ' .
'database at this time.</p>' );
}
?>


<?php

$id = $_GET['id];
$path = $_GET['path'];


----------------------


What i want is the code that will put the content $path in the colume path on the row where the number in the colume id is equal to $id.
(the table is called table_1)

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: August 17, 2009 at 11:18:57 Pacific
Reply:

mysql_query("update table_1 set path='" . $path .
"' where id='" . $id . "';") or die(mysql_error());

That would *probably* do, but you'd want to clean the text in path and id though to make sure there isn't anything nasty.

You can check the query by using mysql_affected_rows() right afterward; it returns an integer.

One other thing, since you're using $_GET - you might wish to cast it as an integer.

bool settype($varname, "integer")

If the conversion fails, then there might be tainted data; for example, someone entering an uri directly ?path=admin&id=password--

HTH


0

Response Number 2
Name: Chris (by Chris Kirk)
Date: August 18, 2009 at 10:46:36 Pacific
Reply:

Thanks,
That work fine.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Php to enter from text in to mysql

PHP Form saving to mySQL www.computing.net/answers/webdevel/php-form-saving-to-mysql/615.html

Cannot connect to MySQL with PHP www.computing.net/answers/webdevel/cannot-connect-to-mysql-with-php/1668.html

PHP connection to MySQL www.computing.net/answers/webdevel/php-connection-to-mysql/235.html