Jump to content

Any idea as to why this isnt being submitted


GetReady

Recommended Posts

Hey to my knowledge this should submit 1 into class yet it isn't can anyone spot why? Thanks

 

<tr class="lil1">
  	<td colspan="2" align="center">

	<input type="hidden" name="class" value="37">
	<input type="Submit" value="Select Hustler As My Class"><br><br>
</td>
  </tr>
</form>
<form action="<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users ('class') VALUES ('1')");
     }
?>" method="post">
  <tr class="lil2">

Link to comment
Share on other sites

your submit button wasn't in a form.

<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users ('class') VALUES ('1')");
     }
?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">

      <input type="hidden" name="class" value="37">
      <input type="Submit" value="Select Hustler As My Class"><br><br>
   </td>
  </tr>
</form>

Link to comment
Share on other sites

So in theory the following should work; (It's not wondering if im missing something, :sight: maybe time to go back to coldfusion  :'(

 

<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users ('class') VALUES ('1')");
     }
?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">

      <input type="hidden" name="submit" value="37">
      <input type="submit" value="Select Hustler As My Class" name="submit"><br><br>
   </td>
  </tr>
</form>

Link to comment
Share on other sites

No, because the mysql query is invalid.

 

Single quotes are only used around VALUES.

 

<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users (class) VALUES ('1')") or die(mysql_error()); // if it fails it will tell you why.
     }
?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">

      <input type="submit" value="Select Hustler As My Class" name="submit"><br><br>
   </td>
  </tr>
</form>

 

Edit;

You dont need that hidden value, the submit button wil do just fine as the condition variable.

 

-cb-

Link to comment
Share on other sites

<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users ('class') VALUES ('1')");
     }
?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">

      <input type="hidden" name="submit" value="37">
      <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br>
   </td>
  </tr>
</form>

You didn't close the end of the button. Which is a /

Link to comment
Share on other sites

Hey i did the following; im Getting no errors reported, not is it submitting it, should the digit 1 not be submitted to the database via this form? Im wondering is it possibly anything to do with value="37", I do appreciate the help you are providing me with, Many Thanks.

 

<?php
     if(isset($_POST['submit']))
     {
           mysql_query("INSERT INTO users (class) VALUES ('1')") or die(mysql_error()); // if it fails it will tell you why.
     }
?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">

      <input type="hidden" name="submit" value="37">
  <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br>
     </td>
  </tr>
</form>

Link to comment
Share on other sites

has nothing to do with the 37.  either change the name of your hidden input tag, or get rid of it.  not quite sure what it's purpose is as you're not using it at all.

 

if you're not receiving any errors from the mysql.

 

rule of thumb, (especially) when in development, as a form of troubleshooting, always handle your conditions with an ELSE so as to determine where your script(s) are failing.  This carries into production as well as you must be ready to redirect a user/script upon failure.

 

now, there is no visible reason your check on whether submit was sent, but you should lose the IF and simply execute the query to ensure your db is accepting queries at the moment.

Link to comment
Share on other sites

Get rid of this line:

      <input type="hidden" name="submit" value="37">

 

You dont need it.

 

Try putting backticks around the table and column names:

INSERT INTO `users` (`class`) VALUES ('1')

 

 

-cb-

 

backticks are not necessary (but are good practice), as neither 'class' nor 'users' are reserved mysql words.

Link to comment
Share on other sites

sorry it would appear i wasn't clear with the post.. apologies for that. Would it basically be something along these lines, and is there any way to then redirect the user to another page once the update has taken place, or is that not a possibility? Sorry for the noobish posts im making trying to get my head around php atm.

 

<?php
    if(isset($_POST['submit']))
     {
        mysql_query("UPDATE users SET (`class`='1') WHERE `class`='5'") or die(mysql_error()); 
   }

?>
<form action="" method="post">
  <tr class="lil2">
     <td colspan="2" align="center">
  <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br>
     </td>

Link to comment
Share on other sites

Basically when a user logs in they have the option of choosing between 4 player class's, That's the option for the first of the 4, After choosing a class id like to redirect them to welcome.php, but that code doesn't appear to change the class field to 1, i get the error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`class`='1') WHERE `class`='5'' at line 1

 

Any info would help, Many thanks.

Link to comment
Share on other sites

Yea, i have everything set up via this, It now works like a charm :D Thanks guys, That ones being racking my brain for a while, Would it be easy enough to make it so this page only cropped up if the player class is 5? im guessing it would be something like

 

<?
if ($class >= 5)
{
?>

Link to comment
Share on other sites

yes, you would make the user login, once logged in you can store all the details from the SELECT query you used to check his username and password, into SESSION variables.

 

Put this at the top of every members page (not for included files, only at the start of the page):

session_start();

 

Then, on the login page, use a query like this:

SELECT * FROM usertable WHERE username='someuser' AND password='somepass';

 

You would use mysql_num_row() to check if its valid. then you can use mysql_fetch_assoc() to store the details into the $_SESSION array like so:

$_SESSION['username'] = $row['username'];
$_SESSION['class'] = $row['class'];
etc..

 

Then on any page using sessions, you can do:

if($_SESSION['class'] >= 4){ 
   // display content
}else{
   echo 'not allowed.';
}

 

-cb-

Link to comment
Share on other sites

Thanks, I did the code as said, and all i get is not allowed. then the content underneath it all

 

I did this at the page top

 

<?
session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['class'] = $row['class'];
?>
<?
include "vsys.php";
?>

 

and this before the forms

 

<?
if($_SESSION['class'] >= 4){ 
   // display content
}else{
   echo 'not allowed.';
}
?>


<h2>Select a Character Class for <? 	$user=getusers($_SESSION['isLogined'],'userName');echo $user->userName; ?></h2>
<table cellpadding="0" cellspacing="0" border="0"  width="600" align="center">
  <tr class="lil1">

 

Am i missing something here?  :confused:

Link to comment
Share on other sites

You need to get the concept of php variables. Every variable in php ($variable) has to come from somewhere. if it was not set, then it doesnt exhist yet (except for environment vars etc).

 

You only set the session variables at login.

The only thing at the top of your page should be session_start();

 

-cb-

Link to comment
Share on other sites

<?
session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['class'] = $row['class'];
?>
<?
include "vsys.php";
?>

For 1, you don't need to close and open a PHP tag for no reason.

For 2, you have $row['tablename'] when $row isn't defined.

For 3, you could use a function, to find out if a user is "alive" or dead. :)

 

replace /index.php with your homepage for non-logged in users.

Make sure you have two sessions set upon log-in, for example..

$_SESSION['uid'] - Contains the user_id of current user logged in

$_SESSION['name'] - contains the name of the current user logged in

Place the function in a file called functions.php, and include it to all pages.

function check_user()
{
if (!isset($_SESSION['uid']) || !isset($_SESSION['name']))
{
	session_unset();
	session_destroy();
	header("Location: /index.php");
}
else
{
	$query = mysql_query("SELECT * FROM users WHERE id='".$_SESSION['uid']."'") or trigger_error("Query failed: ".mysql_error());
	$userarray = mysql_fetch_array($query);
	if (mysql_num_rows($query) ==0)
	{
		session_unset();
		session_destroy();
		header("Location: /index.php");
	}
	foreach($userarray as $key=>$value)
	{
		$user->$key = $value;
	}
	return $user;
}
}

To call this function, in the page that you wish to be shown to members, simply do..

$user = check_user();

What this does, is not only check if the user is logged in, and if not redirect them to homepage...

It'll grab all the data from the users table based on that user .. and plonk it into an array.

The data can be accessed like so.

echo $user->username; //username being the COLLUM name in the users database table.

 

As for your query you are doing before... if you are using the function above.. you can simply do this.

mysql_query("UPDATE users SET (`class`='1') WHERE `class`='5' AND `id`='$user->id'") or die(mysql_error());

Although I'm really not sure why you have where `class`='5' when you stated there is only 4 classes to choose from?

 

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.