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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
some_new_guy
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 10:58 am

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

Post 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);

?>
Last edited by some_new_guy on Thu Mar 25, 2004 11:11 am, edited 1 time in total.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

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

Post 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?
some_new_guy
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 10:58 am

Post by some_new_guy »

didn't work...
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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?
some_new_guy
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 10:58 am

Post 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.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Its an SQL problem not a PHP problem! - try losing the single quotes in your query sometimes that gives me problems
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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'
some_new_guy
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 10:58 am

Post by some_new_guy »

Yeah- it works now. Thanks to all of you for your time!
Post Reply