Jump to content

spaces in mysql field causing problems with php code - please help


JimmyA

Recommended Posts

Hello everybody,

Sorry so long a post - I did not know how to shorten

I am trying to make a ??Web App?? I think it would be called. it's a part pricing look up Web Page.

 

Reported by webmin 1.620

Operating system Debian Linux 6.0

Kernel and CPU Linux 2.6.32-5-686 on i686

Apache version 2.2.16

MySQL version 5.1.66

PHP5 version ???? // did not know where to find

 

This is the portion of the code giving me problems:

onclick=getpartinfo2('" .$mfg. "','" .$row['PARTNO']. "')>";

and is used like this:

 

while($row = mysqli_fetch_array($result)){

$part = $row['PARTNO']; // Added this just trying somethimg!!!

echo $part; // This outputs to screen and is correct

if($row['PRC'] == 'NLA'){

echo "<tr bgcolor='Tomato' onclick=getpartinfo2('" .$mfg. "','" .$row['PARTNO']. "')>";}

elseif($row['PRC'] == 'USE'){

echo "<tr bgcolor='Yellow' onclick=getpartinfo2('" .$mfg. "','" .$row['PARTNO']. "')>";}

else{

echo "<tr bgcolor='Lime' onclick=getpartinfo2('" .$mfg. "','" .$row['PARTNO']. "')>";}

echo "<td>".$row['PARTNO']."</td>".

Rest of code...

 

I have tryed $row['PARTNO'] // error below

$part // var I set above // error below

strval($part) // error below

"$row['PARTNO']" // server error

{$row['PARTNO']} // server error

'{$row['PARTNO']}' // server error

"{$row['PARTNO']}" // error below

 

and really many more that I can not remember

table lookups and returned values all work correctly

it's the (onclick=) code echo'd back to the calling page I have a problem with

 

If I enter a partno like...

partno entered '230004-s'

I get this:

onclick="getpartinfo2('pl_Test','230004-S')"

// this is the expected output and when I click on the row (onclick event)

the getpartinfo2() works perfectly

 

If I enter a partno that has spaces in it...

partno entered '24 009 103-s'

and when I click the row (onclick event), I get this error ->

getpartinfo2('pl_Test','24

SyntaxError: unterminated string literal

http://192.168.1.200...jquery-1.9.0.js

Line 3811

 

If I look at firebug->Console->Response -> it shows this,

onclick=getpartinfo2('pl_Test','24 009 103-S')

// what I want for this portion of the output -> which is correct

 

but using firefox->tools->web devolper extension->view source->veiw generated source

the code says

onclick="getpartinfo2('pl_Test','24" 009="" 103-s')=""

 

and in firebug->html - it looks like this

<tr bgcolor="Lime" 103-s')="" 009="" onclick="getpartinfo2('pl_Test','24">

<td>24 009 103-S</td>

<td>CLOSURE PLATE ASSEMB</td>

<td></td>

<td align="right">279.42</td>

<td align="right"><b>335.30</b></td>

<td align="center">0</td>

<td align="center">0</td>

<td align="center">0</td>

<td align="center">12-12</td>

<td></td>

</tr>

 

It's almost like PHP is trying to do math operations on what is suppose to be a string

 

I have only been working with html-php-mysql for about 3 weeks,

and the last week on this single problem

 

Thanks for any help I could get;

Jimmy

Link to comment
Share on other sites

Yes, all returnd values in the database are correct and verified, the problem is not the returned values -> but with the php generated code returned to the calling page (if that is the correct term for this) like I said I am only about 3 weeks old with programming.

Thanks,

Jimmy

Link to comment
Share on other sites

Gave your code a closer look (please use the

 tags next time, thanks), and it seems that it's not your CS that's the problem. As evidenced by what you wrote here:
If I look at firebug->Console->Response -> it shows this,

onclick=getpartinfo2('pl_Test','24 009 103-S')

 

Once you've gotten the response from the server, PHP has no further influence of the data. In fact, PHP is no longer running, and even if it was it has no way to directly influence what happens on the client.

What is happening, I suspect, is that you have some JS that runs and corrupts the values for you. Try to see if the same happens in another browser, which may or may not help to determine exactly where the problem is.

Most likely, you'll have to use your browser's developer tools to debug the JS. Until you find out what, exactly, causes the problem.

Link to comment
Share on other sites

Thank you - for your replies and attention,

there is no java running on this code yet, the same thing happens on 5 other computers I have here, all are ubuntu 10.04 with firefox browsers - non of the other computers have any debuging or other addons installed, (I finally got away from win so can't test with that, One other machine has deibian sqeeze with Iceweasel and epiphany browsers on it and they both do the same thing as the other machines with firefox - there is no error or anything just nothing happens when I mouse click on the returned row of the generated table ->

onclick=getpartinfo2('pl_Test','24 009 103-S')

if you look at this part of the code

<tr bgcolor="Lime" 103-s')="" 009="" onclick="getpartinfo2('pl_Test','24">
<td>24 009 103-S</td>

etc...

this is what is sent back from the php function

the code works perfectly if there are no spaces in the partno,the only other thing that touches this before the page gets it back is

jquery-1.9.0.js -> i don't know what it does to it, using ajax style programming to dynamically create the table on the page.

mabey a bug in the jquery lib ?? I'm just totally lost, I just want to return a simple string from my php function and I can't get it right.

Link to comment
Share on other sites

I finally found php str_replace(), and changed the code to:

data.php

while($row = mysqli_fetch_array($result)){
   if($row['PRC'] == 'NLA'){
       echo "<tr bgcolor='Tomato' onclick=getpartinfo2('".$mfg."','".str_replace(" ","#",$row['PARTNO'])."')>";}
   elseif($row['PRC'] == 'USE'){
       echo "<tr bgcolor='Yellow' onclick=getpartinfo2('".$mfg."','".str_replace(" ","#",$row['PARTNO'])."')>";}
   else{
       echo "<tr bgcolor='Lime' onclick=getpartinfo2('".$mfg."','".str_replace(" ","#",$row['PARTNO'])."')>";}
       echo "<td>".$row['PARTNO']."</td>".
        "<td>".$row['DESC']."</td>".
	       "<td>".$row['PARTNO2']."</td>".
	       "<td align='right'>".$row['PRICE']."</td>".
	       "<td align='right'><b>".number_format($row['PRICE']*1.20, 2, '.', ',')."</b></td>".
	       "<td align='center'>"."0"."</td>".
	       "<td align='center'>"."0"."</td>".
	       "<td align='center'>"."0"."</td>".
	       "<td align='center'>".$row['DATE']."</td>".
	       "<td>".$row['PRC']."</td>".
	       "</tr>";}

Which created a couple more problems, But was able to over come them with a

js var.replace(/#/g," ") function for my getpartinfo2() function

index.php

function getpartinfo2(mfg, partno){
   var partno=partno.replace(/#/g," ");
       $.post("js_php/getpart_info.php", {mfg:mfg, partno:partno}, function(data){
       $("#part_data").html(data);});
}

 

I still think may be a jquery bug ??? or maybe a feature ?

I consider this a work around but hey it does work a dream for now, --untill I find another bug in my code -> marking as solved for now

thanks for all the help !!

jimmy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.