Page 1 of 1

Connectile Dysfunction

Posted: Fri Jun 15, 2007 4:43 pm
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'];

}

?>

Posted: Fri Jun 15, 2007 5:19 pm
by feyd
Any errors being output? What tells you the insert isn't happening?

Posted: Fri Jun 15, 2007 5:50 pm
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.

Posted: Fri Jun 15, 2007 5:59 pm
by feyd
So you are sure the insert query runs? Is the error_reporting level E_ALL or higher?

Posted: Fri Jun 15, 2007 6:10 pm
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);

Posted: Fri Jun 15, 2007 6:23 pm
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.

Posted: Fri Jun 15, 2007 7:13 pm
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.

Posted: Fri Jun 15, 2007 11:18 pm
by Burrito
nice title for this topic :lol: