943,518 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 490
  • PHP RSS
Jul 24th, 2009
0

string variable question

Expand Post »
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


PHP Syntax (Toggle Plain Text)
  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 ///////////////////////////////
Similar Threads
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Jul 24th, 2009
0

Re: string variable question

Try replacing the problem area with the following:
php Syntax (Toggle Plain Text)
  1. $cResult=mysql_fetch_array(mysql_query($qry));
  2. $fn=$cResult[0];
  3. $ln=$cResult[1];
  4. $email=$cResult[2];
  5. $street=$cResult[3];
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 24th, 2009
0

Re: string variable question

Click to Expand / Collapse  Quote originally posted by cwarn23 ...
Try replacing the problem area with the following:
php Syntax (Toggle Plain Text)
  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.
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Jul 24th, 2009
-1

Re: string variable question

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?
Sponsor
Featured Poster
Reputation Points: 1046
Solved Threads: 941
Sarcastic Poster
ardav is offline Offline
6,661 posts
since Oct 2006
Jul 24th, 2009
0

Re: string variable question

Click to Expand / Collapse  Quote originally posted by ardav ...
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"
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Jul 25th, 2009
0

Re: string variable question

Click to Expand / Collapse  Quote originally posted by k2k ...
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:
php Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 25th, 2009
0

Re: string variable question

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.
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: ImageCreateFromPNG
Next Thread in PHP Forum Timeline: Free Open Source Software





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC