Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP New Line problems

Status
Not open for further replies.

peterv6

Programmer
Sep 10, 2005
70
US
I'm new to PHP, and I'm having problems with getting error messages to display on multiple lines. My syntax must be wrong, but I haven't been able to figure out the problem.

I've tried:

$query ="INSERT INTO usersTable
VALUES ('0','karen','$encrypted_password')";
$result = mysql_query($query);
if (!$result) {
print "Invalid query: " . mysql_error() . "\n";
print "Whole query: " . $query;
die;

I've also tried:

$query ="INSERT INTO usersTable
VALUES ('0','karen','$encrypted_password')";
$result = mysql_query($query);

if (!$result) {
$message = 'Invalid query: ' . mysql_error() . '\n';
$message .= 'Whole query: ' . $query;
die($message);

Both output this on one line:
kds1973 d27e2a00960df8585d1ccce348ad3eae Invalid query: Duplicate entry 'karen' for key 2 Whole query: INSERT INTO usersTable VALUES ('0','karen','d27e2a00960df8585d1ccce348ad3eae')

Where I want:
kds1973
d27e2a00960df8585d1ccce348ad3eae
Invalid query: Duplicate entry 'karen' for key 2
Whole query: INSERT INTO usersTable VALUES ('0','karen','d27e2a00960df8585d1ccce348ad3eae')


(I know the 2 newlines won't give me exactly what I want, but it should have split it into at least 2 lines.) Can someone help me out?
Thanks!

PETERV
Syracuse, NY &
Boston, MA
 
After doing a little searching on the net, it looks like I'm doing this entirely wrong. Can anyone point me in the right direction? Basically what I'm looking for is how to format the error message from a MySQL query into a multi-line format for display in a web page.
Thanks....

PETERV
Syracuse, NY &
Boston, MA
 
If you are going to display in a webpage, use html to format your output.

If you want two lines add a <br> tag to create the break, or use any of the many available <html> elements to mark it up.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The output you used is great if you're sending a plaintext email or saving to a standard txt file. Then, you can parse any of this text with the simple function "nl2br();"

What you're trying to do is output an escape character to the browser, but the browser is looking for HTML formatting. it'll ignore new lines because the browser allows you to format your code for readability. (i.e. it'll ignore tabs "\t" too)
 
Thanks for the info guys, it'll come in handy. Can either of you give me an example of how I could output this with line breaks to a web page using HTML?

PETERV
Syracuse, NY &
Boston, MA
 
Code:
if (!$result) {
   print "Invalid query: " . mysql_error() . "\n<br>";
   print "Whole query: " . $query . "\n<br>";
   die;

-----------------------------------------
I cannot be bought. Find leasing information at
 
Just like your line break:
Code:
 print "Invalid query: " . mysql_error() . "[red]<br>[/red]";

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
jaxtell & vacunita, thank you both for these examples. I'm using jaxtell's answer in my page, but I've removed the newline inside the quotes, as it is not needed when using the <br>. You both have been very helpful, I apreciate you both.
Peter V.

PETERV
Syracuse, NY &
Boston, MA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top