Page 1 of 1

glitch in code- likely an easy solve- HELP me!

Posted: Thu Mar 25, 2004 10:58 am
by some_new_guy
Hi there. I am having a problem with a script that I have. I've tested the variables with a simple script to make sure that they are being initially submitted, and they are. When they are spit into this script, however, I get nothing back, and can see no problems with it. The database fields (rec_id, entry_password, and confirmed) are correct in the script, and the variable titles are correct. What is wrong ? Help! Thanks in advance.

Code: Select all

<?php

$msg = "";

	$user      = "myurl.com";
	$password  = "";
	$db        = "whatever";

$link = mysql_connect("localhost", $user, $password);
	if (!$link) die ("cant connect to mysql");

mysql_select_db($db, $link) or die ("cannot connect");

$query = "SELECT entry_password where rec_id='$rec_id'";

mysql_query($query, $link) or die (mysql_error());

($myrow = mysql_fetch_row($result));
$gotpassword = $myrow&#1111;0];

if ($gotpassword == $the_password)&#123;
$query = "UPDATE mailinglist set confirmed=$confirmed where rec_id='$rec_id' ";
echo "&message=You're in there like under wear, mango.";
echo "&loading=NO";
&#125;
else&#123;
echo "&message=Your password was lame, kid.";
&#125;


mysql_query($query, $link) or die (mysql_error());


mysql_close($link);

?>

Re: glitch in code- likely an easy solve- HELP me!

Posted: Thu Mar 25, 2004 11:11 am
by TheBentinel.com
Did you mean to assign the query to $result?

Code: Select all

mysql_query($query, $link) or die (mysql_error());
($myrow = mysql_fetch_row($result));
Should be...

Code: Select all

$result = mysql_query($query, $link) or die (mysql_error());
($myrow = mysql_fetch_row($result));
Did that help?

Posted: Thu Mar 25, 2004 11:48 am
by some_new_guy
didn't work...

Posted: Thu Mar 25, 2004 12:00 pm
by TheBentinel.com
some_new_guy wrote:didn't work...
Did it do anything? Output anything? Give any errors?

If you comment out the database access parts and just echo the incoming fields, are they populated?

If you just ask it how many records it found, does it give you a record count?

Posted: Thu Mar 25, 2004 1:06 pm
by some_new_guy
I made up a simple form and tried the code through that. Here is the form.

Code: Select all

<html>
<body>
<form action="confirm_test.php" method="post">
  <input type="text" name="rec_id"> 
  rec_id
  <br>
  <input type="text" name="confirmed"> 
  confirmed
  <br>
  <input type="text" name="entry_password"> 
  entry_password
<input type="submit" value="Submit" name="submit" /></form>
</body>
</html>
Here is the revised script.

Code: Select all

<?php
$msg = "";

$user      = "myURL.com";
	$password  = "";
	$db        = "whatever";

$link = mysql_connect("localhost", $user, $password);
	if (!$link) die ("cant connect to mysql");

mysql_select_db($db, $link) or die ("cannot connect");

$query = "SELECT entry_password where rec_id='$rec_id'";

$result = mysql_query($query, $link) or die (mysql_error()); 
($myrow = mysql_fetch_row($result)); 

$gotpassword = $myrow&#1111;0];

if ($gotpassword == $the_password)&#123;
$query = "UPDATE mailinglist set confirmed=$confirmed where rec_id='$rec_id'";
echo "&message=You're in there like under wear, homeboy. You just may be seeing a pair of shoes on your feet real soon like.";
echo "&loading=NO";
&#125;
else&#123;
echo "&message=Your password was wack, kid.";
&#125;

mysql_query($query, $link) or die (mysql_error());


mysql_close($link);

?>
And it is still not working. Hrere is the error message:
You have an error in your SQL syntax near 'where rec_id='2'' at line 1

I am pretty sure my database info is all lined up, but I am very new to all of this- my apologies.

Posted: Thu Mar 25, 2004 1:09 pm
by TheBentinel.com
What happens if you modify your PHP code to look like this:

Code: Select all

<?php
echo $rec_id ;
echo "<br>";
echo $the_password;
?>
Does that print the rec_id and the_password? I think it won't since your form calls it "entry_password", but maybe I'm missing something.

Posted: Thu Mar 25, 2004 1:17 pm
by magicrobotmonkey
Its an SQL problem not a PHP problem! - try losing the single quotes in your query sometimes that gives me problems

Posted: Thu Mar 25, 2004 1:19 pm
by markl999
$query = "SELECT entry_password where rec_id='$rec_id'";

That's invalid syntax, hence the error, needs to be in the format..
SELECT something FROM tablename WHERE this='that'

Posted: Thu Mar 25, 2004 1:52 pm
by some_new_guy
Yeah- it works now. Thanks to all of you for your time!