Connectile Dysfunction

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
dbdvd7
Forum Newbie
Posts: 18
Joined: Fri Nov 17, 2006 2:33 pm

Connectile Dysfunction

Post by dbdvd7 »

Hello,
Im a newbie and Im sure Im missing something simple here. I can connect to Mysql and validate anything on the server already and echo results if my input is empty, but I cannot insert anything. This is basically a form that inserts email and a name attribute on an already existing List created by PHPList. It first check if the user exists, if so returns info on them. If they dont it is supposed to create the parameters for them. I've been staring at this for a day and tried anything I can get my hands on. I hope its something simple that I am missing...any suggestions?

Code: Select all

<?php

error_reporting(E_ALL);
$name = 'Herb';
$email = "herb@gmail.com";

require("maillist/config/config.php");



$db = mysql_connect("localhost", "$database_user", "$database_password") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("$database_name") or die(mysql_error());
echo "Connected to Database<br />";


$att = mysql_query("SELECT userid FROM phplist_user_user_attribute WHERE value='$name'") or die(mysql_error());
$id  = mysql_fetch_array($att);

echo "hello".$id['userid'];
 
 
 
  $exusr = mysql_query("SELECT id FROM phplist_user_user WHERE email='$email'")  or die(mysql_error());
  $userId = mysql_fetch_array($exusr);
 
 
  if (empty($userId)) {
   
	echo '$userId is empty';    
	
	 {
      $uniqueId = md5(uniqid(mt_rand(0,1000).$email));
      $uid = mysql_query("SELECT COUNT(*) FROM phplist_user_user WHERE uniqid='($uniqueid)'") or die(mysql_error());
      $exists = mysql_fetch_array($uid);
     } while ($exists);
    
	    $insert = mysql_query ("INSERT INTO phplist_user_user (email,entered,confirmed,uniqid) values ('$email',now(),1,'$uniqueId')") or die(mysql_error());
    $result = mysql_fetch_array($insert);
    
	
	
    $getid = mysql_query ("SELECT id FROM phplist_user_user WHERE uniqid='$uniqueId'") or die(mysql_error());
    $newid = mysql_fetch_array($getid);
  
  
  echo "New User Created:".$newid['id'];
 
  }else{
  
  
echo "User ID:".$userId['id'];

}

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Any errors being output? What tells you the insert isn't happening?
dbdvd7
Forum Newbie
Posts: 18
Joined: Fri Nov 17, 2006 2:33 pm

Post by dbdvd7 »

There are no errors being output. The values I am trying to put in a table just won't appear in my MySql Admin. I can put values in the admin and read them with this bit of code webside, it just won't insert any new data into the List that I can view server side.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

So you are sure the insert query runs? Is the error_reporting level E_ALL or higher?
dbdvd7
Forum Newbie
Posts: 18
Joined: Fri Nov 17, 2006 2:33 pm

Post by dbdvd7 »

The insert query runs fine if I place it above the if(empty($userid)). Where I run into trouble is the user validation and creation section. Although, it does render the echo '$userId is empty'; in the browser. I think the problem may lie in the uniqueId creation through the while loop.

And yes the error_reporting is (E_ALL);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Well, if the insert itself doesn't error and the echo before the unique id creation happens... the only thing left to be a culprit is the unique id creation code. Debugging time.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The field `uniqid` does need to be unique ...as far as I can tell. You alread have an auto_increment field in that table.
What do you use `uniquid` for? For validating the email address, i.e. sending an email to the address with a link containing that value?
Then there's no need for
dbdvd7 wrote:{
$uniqueId = md5(uniqid(mt_rand(0,1000).$email));
$uid = mysql_query("SELECT COUNT(*) FROM phplist_user_user WHERE uniqid='($uniqueid)'") or die(mysql_error());
$exists = mysql_fetch_array($uid);
} while ($exists);
Just enter $uniqueId once (without checking for duplicates) and send a link http:....?userid=15&acode=637039b62454f3a5076d2bcdff06aff9


mysql_query doesn't return a result resource for INSERT statement, only TRUE or FALSE. Therefore remove the second line from
dbdvd7 wrote:$insert = mysql_query ("INSERT INTO phplist_user_user (email,entered,confirmed,uniqid) values ('$email',now(),1,'$uniqueId')") or die(mysql_error());
$result = mysql_fetch_array($insert);
Also get rid of
dbdvd7 wrote:$getid = mysql_query ("SELECT id FROM phplist_user_user WHERE uniqid='$uniqueId'") or die(mysql_error());
$newid = mysql_fetch_array($getid);
and use mysql_insert_id instead.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

nice title for this topic :lol:
Post Reply