Jump to content

[SOLVED] Gah I hate MYSQL Queries.


Aureole

Recommended Posts

I have no idea why this isn't working...basically on step one you enter your username password email address etc. then it sends a validation code to your email and I have a header that takes you to step two then you enter your validation code which is sent to this file but it doens't work.

 

<?php
/*--------------------------*\
File: steptwo.php
Author: Joe
Created: 14/August/07 6:06 PM
Modified: 14/August/07 6:37 PM
Revision: 2
\*--------------------------*/
  include("connect.php");

if (isset($_POST['submit']))
  {

  if (empty($_POST['mem_validate']))
   {
   die('You didn\'t enter a validation code.');
  }
  else
    {
$mem_validate = mysql_real_escape_string($_POST['mem_validate']);
  }
  
  $query = mysql_query("SELECT * FROM gs_mem WHERE mem_validate = '".$mem_validate."'");
  $result = mysql_query($query);
  if ($result)
    {
$update = mysql_query("UPDATE gs_mem SET mem_active = 1 WHERE mem_validate = '".$mem_validate."'");
mysql_query($update) or die();
    header("Location: signup.php?step=three");
  }
  else
    {
die();
  }
}

else
  {
  echo('Form not submitted');
}

?>

Link to comment
https://forums.phpfreaks.com/topic/64888-solved-gah-i-hate-mysql-queries/
Share on other sites

these are your mysl lines, right?

 

  $query = mysql_query("SELECT * FROM gs_mem WHERE mem_validate = '".$mem_validate."'");

and

$update = mysql_query("UPDATE gs_mem SET mem_active = 1 WHERE mem_validate = '".$mem_validate."'");

 

?

 

Ill go validate them now....

Even something as simple as this isn't working:

 

<?php
  $query = mysql_query("SELECT mem_dname FROM gs_mem WHERE mem_validate = '".$mem_validate."'");
  $result = mysql_query($query);
  if ($result)
    {
    header("Location: http://www.veraci7y.net/GameSpaces/signup.php?step=three");
  }
  else
    {
die(mysql_error());
  }
?>

 

It's giving me:

 

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 'Resource id #3' at line 1

 

What is it talking about I don't see anything wrong with it at all...it's talking about line 1.....line 1 is <?php LOL.

IT is taling about line one in your SQL

 

SELECT mem_dname FROM gs_mem WHERE mem_validate = 'somecode';

what are you looking for in the datbase (examlple of what goes in mem_validate

Run that through an SQL host... dio you have PHPMYADMIN acess?

Yes I just ran this in PHPMyAdmin:

 

SELECT mem_dname FROM gs_mem WHERE mem_validate = e4b0f8a3528fe910f5225c95380f4417

 

I also tried:

 

SELECT mem_dname FROM gs_mem WHERE e4b0f8a3528fe910f5225c95380f4417 = mem_validate

 

mem_validate is a random string that is generated when the user enters there username and password and hits enter it is also added to the database in mem_validate... It is then sent to their Email address. They have to input it into a text area then it checks to see if the code exists in the database and if so sets mem_active to 1 therefore activating their account...

 

...but it's just being stupid.

 

Both times it said:

 

MySQL said: Documentation

#1054 - Unknown column 'e4b0f8a3528fe910f5225c95380f4417' in 'where clause'

 

And there is a row that has that id in mem_validate and that row does have an entry for mem_dname...

try using quotations in the php then:

 

<?php
 $query = "SELECT mem_dname FROM gs_mem WHERE mem_validate='".$mem_validate."'";
 $result = mysql_query($query);
 if ($result)
   {
   header("Location: http://www.veraci7y.net/GameSpaces/signup.php?step=three");
   }
 else
   {
die(mysql_error());
   }
?>

In response to Barand, I didn't know that. But all I want it to do is if it finds something in the database in the mem_validate row which is equal to the variable mem_validate that came in via POST then...do something...otherwise don't do something, how would I approach this? Thanks.

When you're having trouble with MySQL queries, it is always helpful to print the generated query out with the error message:

<?php
  $query = "SELECT mem_dname FROM gs_mem WHERE mem_validate = '".$mem_validate."'";
  $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error())l
  header("Location: http://www.veraci7y.net/GameSpaces/signup.php?step=three");
?>

 

While changing your code to the above code, I noticed you were calling the mysq_query() function twice. The second time you were passing it the results of the first call. This is what is giving you the error. Remove the second call to mysql_query().

 

Ken

In response to Barand, I didn't know that. But all I want it to do is if it finds something in the database in the mem_validate row which is equal to the variable mem_validate that came in via POST then...do something...otherwise don't do something, how would I approach this? Thanks.

 

if (mysql_num_rows($result) > 0)

    // record/s found

else

    // not found

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.