Forum Moderators: coopster

Message Too Old, No Replies

Edit MySQL using PHP

I need help including a textbox

         

tcdearling

7:43 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



I know that I need to include a textbox and everything, but dont know how. In my database I would like to be able to edit it from my website that has a textbox and a button that allows it to change a field in the database and replace it with the text in the box.

If anybody has any ideas, or knows how to do it please reply to this message or Mail me.

CTHouston

8:18 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



make your textbox like so, or however you want to do it:

<form action="foobar.php" method="post">
<p>Enter Mysql query here</p>
<textarea name="query" rows="5" cols="60"></textarea>
<input type="submit" value="submit">
</form>

and then in your foobar.php:

<?php
....
$query=$_POST['query'];
mysql_query($query);
....
?>

is that what you're after, does it help at all?

Timotheos

9:04 pm on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld tcdearling,

Just a caveat on CTHouston's post. Don't let anybody else use a form like that our else you might not have a database anymore ;-) MySQL statements can be very powerful so you have to be careful who can execute them on your site.

If this is for users then you'll probably just want to pass some info, make sure it's good and then put it into an SQL statement. There lot's of good stuff in the library here to get you going. This one [webmasterworld.com] is a good start.

If you're looking for a way to administer your database with a web GUI you'll want to check out phpMyAdmin [phpmyadmin.net] or something similar.

Tim

tcdearling

10:05 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Thanks for replying guys, I do use phpMyAdmin, its just i want to link to it in a web page, and have a textbox that changes a field in the database.

I hope that helps you determine what I want?

tcdearling

10:14 am on Nov 12, 2005 (gmt 0)

10+ Year Member



I am using this code at the moment (see below). I have not included the databases information due to security reasons, but I have an parse eror on line 15 which is:

UPDATE `members` SET `status` = 'banned' WHERE `name` = $change;

<form action="$change" method="post">
<p>Enter Mysql query here</p>
<textarea name="query" rows="5" cols="60"></textarea>
<input type="submit" value="submit">
</form>

<?php

// connect to database
$username = "username";
$password = "password";
$hostname = "host";
$database = mysql_connect($hostname, $username, $password)or die("Unable to connect to Database");

UPDATE `members` SET `status` = 'banned' WHERE `name` = $change;

?>

If anybody has any ideas please opst a reply here.

Anyango

11:17 am on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the reason for your parse error is pretty obvious

UPDATE `members` SET `status` = 'banned' WHERE `name` = $change;

should be enclosed in qoutes as string and should be assigned to some variable instead of just typing the line.

$sql="UPDATE `members` SET `status` = 'banned' WHERE `name` = $change";

mysql_query($sql) or die(mysql_error());

Regards
Kami

tcdearling

11:58 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Thanks for your help, I might be needing it again.