/    Sign up×
Community /Pin to ProfileBookmark

My simple simple code not working,

Hi,
This simple code is not working. I’d be grateful for any help.

The [I]if(mysql_query($query))[/I] block seems to not even execute, it doesn’t echo the else statement.

i’m simply trying to build an input for mysql queries,

[code=php]
$cnx = mysql_connect(‘localhost’, ‘root’, ‘password’);
$db = mysql_select_db(“warmmail”);

if(isset($_POST[‘submit’])) {
$query = $_POST[‘query’];
//echo $query;
if(mysql_query($query)) {
echo “Q succeeded”;
} else {
echo “Q failed”;
echo mysql_error();
}
} else {
echo “<p>Vars not set</p>”;
}

?>
<style type=”text/css”>textarea{width:200px;height:200px}</style>
<form action=”<?php $_SERVER[‘php_self’] ?>” >
<input name=”query” type=”text” />
<input type=”submit” name=”submit” value=”submit” />
</form>[/code]

thanks for any help on this!,

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ZipTimeTrackerApr 12.2012 — Change "php_self" to "PHP_SELF"

Make the form method="post"

Also, mysql_query only returns boolean for some queries: http://php.net/manual/en/function.mysql-query.php
Copy linkTweet thisAlerts:
@toptomatoauthorApr 12.2012 — thank you!,... i'm so embarrassed
Copy linkTweet thisAlerts:
@BelrickApr 12.2012 — Are you really allowing people to type in their own SQL queries straight into your DB?

?
Copy linkTweet thisAlerts:
@mtrickApr 12.2012 — Change your form action php function its "PHP_SELF" not "PHP_self"
Copy linkTweet thisAlerts:
@toptomatoauthorApr 12.2012 — No, i'm not letting user type in query's. it's just for me, to bypass PHPMyAdmin.

thanks for the help
Copy linkTweet thisAlerts:
@BelrickApr 12.2012 — Me, I love phpmyadmin.

"strokes phpmyadmin lovingly"
×

Success!

Help @toptomato spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...