Jump to content

Recommended Posts

Posted

Please help! I can't figure out why this code isn't working.

I made my column names in my mySQL table with spaces in them, and now I'm getting syntax errors on an INSERT query.. I tried escaping out quote characters and everything.. I must be doing something wrong.

 

>$query = "INSERT INTO contacts (Date Entered, Date Of Call, Company Name, Contact Name, Phone, Contact, Source, Result) VALUES ('$dateent','$datecall','$compname','$contname','$phone','$contact','$source','$result')";

 

I'd appreciate any help on the subject.

Thanks!

 

Sarah

Posted

Well, I couldn't figure it out.. so I changed the column names.

 

But I wanted them to show up like this on the screen:

 

"Sorting by: Date Of Call "

 

but now since I couldn't use spaces, It looks like this:

 

"Sorting by: Date_Of_Call " . Kinda unprofessional.. I'll have to write more code to change the variables I guess.

 

 

Sarah

Posted

just a guess as I've never tried this in MySQL specifically, but...

 

When crafting a SQL statement, you can use a column name definition in the format:

 

SELECT column_name AS 'Desired Name' FROM table_name;

 

I don't know the syntax off the top of my head for denoting that Desired name. It may need to be either surrounded by ", ', or [].

 

Hope that helps!

Posted

1stover has a good idea worth checking into.

 

But it sounds like you just need to change a variable in your script so that the echo or print statement says something different than it currently does.

Posted

Thanks 1stover... your suggestion was good too.

 

Sarah, look in your script for "Sorting by:" so that you can find the line that prints out this statement. Once you find it, you shouldn't have too much problem identifying the variable name that actually prints out the column name.

 

One way to get a cleaner version would be to do a replace statement that removes certain characters.

 

So let's say the variable is $column and the print statement looks something like print("Sorting by: $column");

 

But you're getting stuff like:

 

Sorting by: Date_Of_Call

 

Then you could do this:

 

$new_column = str_replace("_"," ", $column);

print("Sorting by: $new_column");

 

This keeps the value of the first variable the same and keeps your code intact but also creates a new variable that replaces all "_" with a space. This way, you can add as many columns as you like and the code will still work perfectly.

 

There you go!

Posted

That's some good code to use.. I think I will try that when I clean it up.

 

But for now (to get it working temporarily) I just changed the column names back to "Date_Of_Call" with the underscores and then wrote this code to make it display differently:

>if ($sortby == "Date_Of_Call"){
 $sortby_print = "Date Of Call";
}

 

That way, it'll just print the sortby_print variable instead of the column name..

 

But I will try your code, seems less redundant than coding all those if statements.

 

Thanks for the ideas!

 

Sarah

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...