Jump to content

mysql simple query


pedrobcabral

Recommended Posts

At the moment I have the following code:

[code]
<?php
$query = "SELECT FROM register code WHERE email = '{$this->email}'";
$result =  mysql_query($query);
while($row = mysql_fetch_object($result)) { $this->mysqlcode = "$row->code"; }
?>
[/code]

But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you.
Link to comment
https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105129
Share on other sites

[quote author=pedrobcabral link=topic=110707.msg448103#msg448103 date=1160153289]
At the moment I have the following code:

[code]
<?php
$query = "SELECT FROM register code WHERE email = '{$this->email}'";
$result =  mysql_query($query);
while($row = mysql_fetch_object($result)) { $this->mysqlcode = "$row->code"; }
?>
[/code]

But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you.
[/quote]
you may need to do some error checking. try this:
[code]
<?php
$query = "SELECT FROM register code WHERE email = '{$this->email}'";
$result =  mysql_query($query);
if (mysql_num_rows($result) == 1) $this->mysqlcode = mysql_result($sql, 0, 'code');
?>
[/code]

just make sure you have a record returned first
Link to comment
https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105137
Share on other sites

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.