string variable question

Thread Solved

Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

string variable question

 
0
  #1
Jul 24th, 2009
hi, i selected everything from the table and the direct variable $cResult[3] would give me something like "street address with space as delimiter" ... however, when i tried to use it, it will give me only "street" instead of "street address with space as delimiter".

does anyone know how i can fix it so it will show the whole field?
thanks


  1.  
  2.  
  3. <?php
  4. require_once('auth.php');
  5. require_once('config.php');
  6.  
  7. $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  8. if(!$link)
  9. {
  10. die('Failed to connect to server: ' . mysql_error());
  11. }
  12.  
  13. //Select database
  14. $db = mysql_select_db(DB_DATABASE);
  15. if(!$db)
  16. {
  17. die("Unable to select database");
  18. }
  19.  
  20. $cid = $_SESSION['SESS_CUSTOMER_ID'];
  21.  
  22. $qry="SELECT fname, lname, email, streetAddress,zip_id, passwd FROM customer WHERE customer_id='$cid'";
  23.  
  24. /////////////////// problem begin //////////////////////////////////
  25. $cResult=mysql_fetch_array(mysql_query($qry));
  26.  
  27. $fn= "$cResult[0]";
  28. $ln= "$cResult[1]";
  29. $email= "$cResult[2]";
  30. $street= "$cResult[3]"; //---> this will give me only part of the field (the first word basically)
  31. ///////////////// problem end ///////////////////////////////
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,475
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: string variable question

 
0
  #2
Jul 24th, 2009
Try replacing the problem area with the following:
  1. $cResult=mysql_fetch_array(mysql_query($qry));
  2. $fn=$cResult[0];
  3. $ln=$cResult[1];
  4. $email=$cResult[2];
  5. $street=$cResult[3];
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

Re: string variable question

 
0
  #3
Jul 24th, 2009
Originally Posted by cwarn23 View Post
Try replacing the problem area with the following:
  1. $cResult=mysql_fetch_array(mysql_query($qry));
  2. $fn=$cResult[0];
  3. $ln=$cResult[1];
  4. $email=$cResult[2];
  5. $street=$cResult[3];


i will try again later but i think i already tried that and didn't work.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 986
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 128
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: string variable question

 
-1
  #4
Jul 24th, 2009
Just a thought, is your 4th field (street) long enough to take the whole street name. Check in phpmyadmin or whatever you use to admin your db to see if the data in 'street' is complete.

If this ain't a problem, have you got any strange characters following the first word?
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

Re: string variable question

 
0
  #5
Jul 24th, 2009
Originally Posted by ardav View Post
Just a thought, is your 4th field (street) long enough to take the whole street name. Check in phpmyadmin or whatever you use to admin your db to see if the data in 'street' is complete.

If this ain't a problem, have you got any strange characters following the first word?

nope, no strange characters. the field is long enough and the street i inserted "132 main street" was already stored in the table.

but it is weird that [code] echo "$cResult[3]" returns me only "132"
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,475
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: string variable question

 
0
  #6
Jul 25th, 2009
Originally Posted by k2k View Post
but it is weird that [code] echo "$cResult[3]" returns me only "132"
Perhaps it is an error in the part of the script that inserts into the table. Try using the mysql_real_escape_string() function to see if it escapes the spaces. And remember to put quotes around each string to be inserted. Below is an example:
  1. echo '`column`="'.mysql_real_escape_string('132 main street').'"';
  2. mysql_query('INSERT INTO `table` SET `column`="132 main street"') or die(mysql_error());
And check if the first line returns whats in the mysql query.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

Re: string variable question

 
0
  #7
Jul 25th, 2009
still don't know why, but it magically works now with $street= $cResult[3]


and echo "$cResult[3]" return "132 main street"

..... thanks everyone tried to help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC