CodingSqlite

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  CHYRON (DSMITHHFX)  
 To:  ALL
41187.1 
I'm trying to add new user with a school name, schoolID and regionID into users and schools tables all at one go (PHP).

The user is created in users, new school in schools, and both get regionIDs, but my code isn't posting the new schoolID to the new user's row (col stays blank). The problem seems to be down to choking on variables ($newschool and $newuser). If I hard code the values into the UPDATE statement, it writes them fine.

Anyone spot any glaring syntax issues? :-Y
Code: 
if ( $user['grpID'] == 8 ) {
    $schname = $user['schname'];
    $schreg = $user['regID'];
    $stH = stPrep("INSERT INTO schools (name, region, status) VALUES (?,?,?)");
    $result = stExec($stH,array($schname,$schreg,0));
    $stH = stPrep("SELECT last_insert_rowid()");
    $row = $stH->fetch(PDO::FETCH_NUM);
    $stH = null;
    $newschool = $row[0];
    $newuser = $user['id'];
    $stH = stPrep("UPDATE users SET schoolID = ? WHERE ID = ?");
    $result = stExec($stH,array($newschool,$newuser));
}

----
"Ninety percent of Americans use the Internet. The other ten percent use the banjo."
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  ALL
41187.2 
At last (& at least) I'm now getting a value out of a query:
 
Code: 
$stH = stPrep("SELECT * FROM schools ORDER BY ID DESC LIMIT 1");
stExec($stH,null);
$row = $stH->fetch(PDO::FETCH_NUM);
$newschool = $row[0];
echo '<pre>'; var_dump($newschool); echo '</pre>';
However var_dump returns
Code: 
string(2) "11"
-- but all I want is the last digit(s). I suppose I could clean it with a regex, but isn't there a way to just get the value of that column? WTF is "string(2)"?

Oh. It worked. [extraneous stuff is what var_dump does]

----
"Ninety percent of Americans use the Internet. The other ten percent use the banjo."
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  CHYRON (DSMITHHFX)     
41187.3 In reply to 41187.2 
I'm glad we were able to help. Don't hesitate to come back if you have any further problems.

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  99% of gargoyles look like (MR_BASTARD)     
41187.4 In reply to 41187.3 
You are a problem.

----
"Ninety percent of Americans use the Internet. The other ten percent use the banjo."
0/0
 Reply   Quote More 

 From:  Ken (SHIELDSIT)  
 To:  CHYRON (DSMITHHFX)     
41187.5 In reply to 41187.4 
Good luck getting help with that problem!   :-P
------------------------------------------------------------------------
If you don't like donut, then leave it alone. Nobody force you to eat it.
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  Ken (SHIELDSIT)     
41187.6 In reply to 41187.5 
I'm starting to get more of a handle on PDO, previously only fucked around wif MySQL stuffs, a loong time ago.

----
"Ninety percent of Americans use the Internet. The other ten percent use the banjo."
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  CHYRON (DSMITHHFX)     
41187.7 In reply to 41187.4 
Well don't hesitate to come back if you need a problem then. Like I said, always happy to help!

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

Reply to All    
 

1–7

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats