removing parts of string

  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

I have created a form that pulls off a list of contacts from a MySQL database.
They are then displayed inside of a form, using the select tag and a submit button. The method used is post

however, when the selection is posted, it is stripping off all text after a space.

for example

old house - then will send "old"
3I's - then it sends "3I\"

How can I get it to transfer across the whole string as displayed in my database?

Cheers
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

its ok, crisis averted, figured it out

when I was defining the table inside PHP tags, I was wrapping tab values in ' '

changed it to \" and all is ok now
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

What does your insert statement look like?
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

actually Dog, you could help with something else
What SQL query edits a record direct, because I only seem to have table structure examples at my disposal.

What I mean is, I can edit table columns, delete records etc...

But how do I tell a MySQL database that I want to edit a particular record and replace it with new properties

Example.
Table = Abdials

I need a command that tells that table to search for an entry using a WHERE clause and replace it with posted variables

Any ideas?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

PHP Code: [ Select ]
 
$id = $_POST['uniqueID'];
 
$value1 = $_POST['value1'];
 
$value2 = $_POST['value2'];
 
 
 
$query = "
 
UPDATE tableName
 
SET row1 = '$value1', row2='$value2'
 
WHERE tablePK = '$id' ";
 
 
 
mysql_query($sql, DB_Link);
 
 
  1.  
  2. $id = $_POST['uniqueID'];
  3.  
  4. $value1 = $_POST['value1'];
  5.  
  6. $value2 = $_POST['value2'];
  7.  
  8.  
  9.  
  10. $query = "
  11.  
  12. UPDATE tableName
  13.  
  14. SET row1 = '$value1', row2='$value2'
  15.  
  16. WHERE tablePK = '$id' ";
  17.  
  18.  
  19.  
  20. mysql_query($sql, DB_Link);
  21.  
  22.  


should do it
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

see below - does this look right!! the table I'm amending has 2 columns, contactName and abdialNumber: Would this then be right?

Code: [ Select ]
$changeContact = $_POST['changeContact'];
$addContact = $_POST['addContact'];
$addAbdial = $_POST['addAbdial'];

$query = "
UPDATE abdials
SET contactName = '$addContact', row2='$addAbdial'
WHERE contactName = 'changeContact' ";
  1. $changeContact = $_POST['changeContact'];
  2. $addContact = $_POST['addContact'];
  3. $addAbdial = $_POST['addAbdial'];
  4. $query = "
  5. UPDATE abdials
  6. SET contactName = '$addContact', row2='$addAbdial'
  7. WHERE contactName = 'changeContact' ";
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

PHP Code: [ Select ]
 
$changeContact = $_POST['changeContact'];
 
$addContact = $_POST['addContact'];
 
$addAbdial = $_POST['addAbdial'];
 
 
 
$query = "
 
UPDATE abdials
 
SET contactName = '$addContact', abdialNumber='$addAbdial'
 
WHERE contactName = '$changeContact' ";
 
 
  1.  
  2. $changeContact = $_POST['changeContact'];
  3.  
  4. $addContact = $_POST['addContact'];
  5.  
  6. $addAbdial = $_POST['addAbdial'];
  7.  
  8.  
  9.  
  10. $query = "
  11.  
  12. UPDATE abdials
  13.  
  14. SET contactName = '$addContact', abdialNumber='$addAbdial'
  15.  
  16. WHERE contactName = '$changeContact' ";
  17.  
  18.  


looks write now
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

contactName and abdialNumber (I know I left row2 in my last post :x )

I have now amended my page and all seems to go through ok, I get my message saying that I have successfully amended that record, however, to no avail, it has not actually amended anything

any thoughts
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Do you not have a primary key row in your table? (an INT value)
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

I do confess that in my eagerness to learn, I didnt have an ID column.
Because I simply was trying things out, I created the table as told in previous posts.
I have exported all the data, recreated the database and imported the backed up data, but I amended the exported file so that it adds an ID column when importing.

So in summary, I now do have an auto incrementing INT column in every table :lol:
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Cool so you still having the same problem?
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

not as such no, all seems to be working great
however, I do have one record, which appears in the database as

3I's - Newcastle

But when posted, it changes to

3I\

Any idea why this is??[/b]
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

strip the slashes from your output. You bviously have the magic runtime situation set to on.

So the DBMS escapes all special characters ie ' with \' so it doens't ready it as a single quote
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

well I'll have to take a look at that at some point.
I've worked round it for now however as what as I was doing initially, to get the users login name (which is always displayed when navigating the site), was to initially pull in the variable $AUTH_USER, which when printed, give me a result of something like domain\\\\username

but this method was crap because I couldnt delete records out of the database by username due to the problem with the slashes

I've recreated both databases with the ID column now anyways and the users now have choice to create own login name, works much simpler and more concise

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.