Jump to content

[SOLVED] PHP Terminate account help!


jamesxg1

Recommended Posts

Ok iv looked but it still doesnt tell me how to make a button that will execute a db query :S,

 

Any help people ?,

 

Thanks

 

James.

 

A button won't execute a query.

You can make the button hit a page, and then that page does the update and then takes them to whatever page you want.

Link to comment
Share on other sites

What exact part of this do you need help with? Your question is so general that the only way to answer it would be to do it for you and that is not what programming help forums are for.

 

Do you have a specific part you need help with? What have you done so far?

Link to comment
Share on other sites

What exact part of this do you need help with? Your question is so general that the only way to answer it would be to do it for you and that is not what programming help forums are for.

 

Do you have a specific part you need help with? What have you done so far?

 

 

Hiya,

 

Well what i need is something that my customers can click and it will updat there groupid in the database, And i have created the page and tryed to create the code but im stuck!.

 

James.

Link to comment
Share on other sites

You need to get the id from somewhere, most likely a session, but here's a skeleton of how you can accomplish this.

 

if(isset($_POST['butt')) {
   //execute query
   //redirect
}
?>





 

How do you have an online store and don't even know how to go about this?

Link to comment
Share on other sites

You need to get the id from somewhere, most likely a session, but here's a skeleton of how you can accomplish this.

 

<?php 
if(isset($_POST['butt')) {
   //execute query
   //redirect
}
?>

<html>
<body>
<input type="button" name="butt" value="update">
</body>
</html>

 

How do you have an online store and don't even know how to go about this?

 

Hiya Maq,

 

Thankyou for that and i dont i am a beginner im trying to make my own social network script im getting pretty far i just keep stalling on parts that i dont understand :(!, And i have copied the code you gave me and edited it is this correct

<?php 
if(isset($_POST['butt')) {
   //execute query
mysql_query("UPDATE Users SET groupid = 'P' WHERE userid = '$username'")
   //redirect
(Location: logout.php)
}
?>

<html>
<body>
<input type="button" name="butt" value="update">
</body>
</html>

, Thankyou

 

James.

Link to comment
Share on other sites

Is it?  What makes you think it's not?  Does it work the way you want it to?  Do you get errors?

 

 

Ok. I see you are getting annoyed with me i will close the thread.

 

I don't know about everyone else but, I'm not getting annoyed...  I'm just trying to push you in the right direction.  We gave you the pseudo code, now as Blade already said, the pieces are out there you just have to put them together.  There's probably a similar scenario to yours right here on phpfreaks.  If we do all the work for you, you will never do any work for yourself because you will never learn.  That's why this section is called PHP Help, not PHP we will code your CMS for free.  The point is to try it yourself and come back with some code and questions for us to help you out with.

 

P.S. - The section isn't closed, it's just marked as solved.

 

Good luck!

Link to comment
Share on other sites

Is it?  What makes you think it's not?  Does it work the way you want it to?  Do you get errors?

 

 

Ok. I see you are getting annoyed with me i will close the thread.

 

I don't know about everyone else but, I'm not getting annoyed...  I'm just trying to push you in the right direction.  We gave you the pseudo code, now as Blade already said, the pieces are out there you just have to put them together.  There's probably a similar scenario to yours right here on phpfreaks.  If we do all the work for you, you will never do any work for yourself because you will never learn.  That's why this section is called PHP Help, not PHP we will code your CMS for free.  The point is to try it yourself and come back with some code and questions for us to help you out with.

 

P.S. - The section isn't closed, it's just marked as solved.

 

Good luck!

 

 

Thankyou Maq,

 

I do try im just not very skilled i am undergoing tutorials thoe but the stuff i need done tutorials dont help! :(,

 

heres what iv made of that code so far it had some errors in the $_POST area but all sorted

<?php 
if(isset($_POST['terminate'])) 
   //execute query
mysql_query("UPDATE Users SET groupid = 'P' WHERE userid = '$username' ");
   //redirect
header("Location:../login/logout.php");
?>

<html>
<body>
<input type="button" name="terminate" value="update">
</body>
</html>

 

Unfortunetly it still doesnt work it just redirect's me straight away without any of the querys done :(, But not to fear i will continue on my quest to sort it :), If you have any ideas on why it just redirects please post would be much apreciated :).

 

Thanks guy's.

 

James.

Link to comment
Share on other sites

* This is not tested *

 

You need to assign $username to something like Blade said, but this should be an error less example.

 

if(isset($_POST['terminate'])) {
  $username = "user1"; 
  $sql = "UPDATE Users SET groupid = 'P' WHERE userid = '$username'";
  mysql_query($sql) or die(mysql_error());
  header("Location: ../login/logout.php");
}
?>



</pre>
<form method="POST" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>">

</form>
<b

Link to comment
Share on other sites

Where is $username defined and also you are comparing the username to the userid in the query.

 

 

Sorry, Blade your totally are correct really sorry here iv edited it

 

<?php 
if(isset($_POST['terminate'])) 
   //execute query
mysql_query("UPDATE Users SET groupid = 'P' WHERE username = '$username' ");
   //redirect
header("Location:../login/logout.php");
?>

<html>
<body>
<input type="button" name="terminate" value="update">
</body>
</html>

 

Thanks for pointing that out.

 

James.

Link to comment
Share on other sites

You still need the variable $username to be assigned to something.  In your sql statement you're comparing username to something that doesn't even exist.  How do you know what username to UPDATE?

Link to comment
Share on other sites

You still need the variable $username to be assigned to something.  In your sql statement you're comparing username to something that doesn't even exist.  How do you know what username to UPDATE?

 

 

Oh. Well what i was trying to do was get it from the session and the varible for that is $username, This is the code so far

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");

isloggedin();
accessneeded("C");

?>
<?php 
if(isset($_POST['terminate'])) {
  $sql = "UPDATE users SET groupid = 'P' WHERE username = '$username'";
  mysql_query($sql) or die(mysql_error());
  header("Location: ../login/logout.php");
}
?>

<html>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="terminate" value="update">
</form>
</body>
</html>

 

James.

Link to comment
Share on other sites

Assuming you have already started the session, you can change your SQL statement to:

 

  $sql = "UPDATE users SET groupid = 'P' WHERE username = '{$_SESSION['username']}'";

 

Also, there's no point to have (lines 10 & 11):

 

?>

 

Does it work?

 

Unfortunatly no.

 

It just displays the button and once clicked it re-directs you.

 

Unknown to why it dont work thoe :S,

 

Im completely confused now :(,

 

James.

 

So it just doesn't update the database?

Link to comment
Share on other sites

Assuming you have already started the session, you can change your SQL statement to:

 

  $sql = "UPDATE users SET groupid = 'P' WHERE username = '{$_SESSION['username']}'";

 

Also, there's no point to have (lines 10 & 11):

 

?>
<?php 

 

Does it work?

 

Unfortunatly no.

 

It just displays the button and once clicked it re-directs you.

 

Unknown to why it dont work thoe :S,

 

Im completely confused now :(,

 

James.

 

So it just doesn't update the database?

 

 

WORKS!!!,

 

Thankyou so much guy's!, Remeber my username because i WILL get better at PHP one day and i will do something back for you's once again THANKYOU!!.

 

Life savers!.

 

Many Many Thanks

 

James.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.