mysql中的单词之间没有空格?

时间:2021-10-26 21:38:25

I just looked at my MySQL data not all the words are joined up! For example if the word are David Greene, it will show them as DavidGreene.

我只看了我的MySQL数据,并没有把所有单词都加入!例如,如果单词是David Greene,它将显示为DavidGreene。

How can I put the space where there should be one?

我怎样才能将空间放在哪里?

The data is dynamic by the way. Edit: here is the code:

顺便提一下,数据是动态的。编辑:这是代码:

<?php
$errorMsg = "";
// First we check to see if the form has been submitted 
if (isset($_POST['username'])){
    //Connect to the database through our include 
    include_once "scripts/connect_to_mysql.php";
    // Filter the posted variables
    $username = ereg_replace("[^A-Za-z0-9]", "", $_POST['username']); // filter everything but numbers and letters
    $country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']); // filter everything but spaces, numbers, and letters
    $state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters
    $city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters
    $accounttype = ereg_replace("[^a-z]", "", $_POST['accounttype']); // filter everything but lowercase letters
    $email = stripslashes($_POST['email']);
    $email = strip_tags($email);
    $email = mysql_real_escape_string($email);
    $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
        $passport = ereg_replace("[^A-Za-z0-9]", "", $_POST['passport']); // filter everything but numbers and letters
    // Check to see if the user filled all fields with
    // the "Required"(*) symbol next to them in the join form
    // and print out to them what they have forgotten to put in
    if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password) || (!passport)){

        $errorMsg = "You did not submit the following required information!<br /><br />";
        if(!$username){
            $errorMsg .= "--- User Name";
        } else if(!$country){
            $errorMsg .= "--- Country"; 
        } else if(!$state){ 
            $errorMsg .= "--- State"; 
       } else if(!$city){ 
           $errorMsg .= "--- City"; 
       } else if(!$accounttype){ 
           $errorMsg .= "--- Account Type"; 
       } else if(!$email){ 
           $errorMsg .= "--- Email Address"; 
       } else if(!$password){ 
           $errorMsg .= "--- Password";
       } else if(!$passport){ 
           $errorMsg .= "--- Passport";
       }
    } else {
    // Database duplicate Fields Check
    $sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
    $sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
    $username_check = mysql_num_rows($sql_username_check);
    $email_check = mysql_num_rows($sql_email_check); 
    if ($username_check > 0){ 
        $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
    } else if ($email_check > 0){ 
        $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
    } else {
        // Add MD5 Hash to the password variable
       $hashedPass = md5($password); 
        // Add user info into the database table, claim your fields then values 
        $sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, passport, signupdate) 
        VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass','$passport',now())") or die (mysql_error());
        // Get the inserted ID here to use in the activation email
        $id = mysql_insert_id();
        // Create directory(folder) to hold each user files(pics, MP3s, etc.) 
        mkdir("memberFiles/$id", 0755); 
        // Start assembly of Email Member the activation link
        $to = "$email";
        // Change this to your site admin email
        $from = "admin@somewebsite.com";
        $subject = "Complete your registration";
        //Begin HTML Email Message where you need to change the activation URL inside
        $message = '<html>
        <body bgcolor="#FFFFFF">
        Hi ' . $username . ',
        <br /><br />
        You must complete this step to activate your account with us.
        <br /><br />
        Please click here to activate now &gt;&gt;
        <a href="http://www.netolancer.co.uk/bitcoin/activation.php?id=' . $id . '">
        ACTIVATE NOW</a>
        <br /><br />
        Your Login Data is as follows: 
        <br /><br />
        E-mail Address: ' . $email . ' <br />
        Password: ' . $password . ' 
        <br /><br /> 
        Thanks! 
        </body>
        </html>';
        // end of message
        $headers = "From: $from\r\n";
        $headers .= "Content-type: text/html\r\n";
        $to = "$to";
        // Finally send the activation email to the member
        mail($to, $subject, $message, $headers);
        // Then print a message to the browser for the joiner 
        print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
        We just sent an Activation link to: $email<br /><br />
        <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
        Link inside the message. After email activation you can log in.";
        exit(); // Exit so the form and page does not display, just this success message
    } // Close else after database duplicate field value checks
  } // Close else after missing vars check
} //Close if $_POST
?>

1 个解决方案

#1


0  

Try this:

<?php

$errorMsg = "";
// First we check to see if the form has been submitted 
if (isset($_POST['username'])) {
    //Connect to the database through our include 
    include_once "scripts/connect_to_mysql.php";
    // Filter the posted variables
    $username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
    $country = filter_var($_POST['country'], FILTER_SANITIZE_STRING);
    $state = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
    $city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
    $accounttype = filter_var($_POST['accounttype'], FILTER_SANITIZE_STRING);
    $email = filter_var(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
    $password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
    // Check to see if the user filled all fields with
    // the "Required"(*) symbol next to them in the join form
    // and print out to them what they have forgotten to put in
    if ((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password) || (!passport)) {

        $errorMsg = "You did not submit the following required information!<br /><br />";
        if (!$username) {
            $errorMsg .= "--- User Name";
        } else if (!$country) {
            $errorMsg .= "--- Country";
        } else if (!$state) {
            $errorMsg .= "--- State";
        } else if (!$city) {
            $errorMsg .= "--- City";
        } else if (!$accounttype) {
            $errorMsg .= "--- Account Type";
        } else if (!$email) {
            $errorMsg .= "--- Email Address";
        } else if (!$password) {
            $errorMsg .= "--- Password";
        } else if (!$passport) {
            $errorMsg .= "--- Passport";
        }
    } else {
        // Database duplicate Fields Check
        $sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
        $sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
        $username_check = mysql_num_rows($sql_username_check);
        $email_check = mysql_num_rows($sql_email_check);
        if ($username_check > 0) {
            $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
        } else if ($email_check > 0) {
            $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
        } else {
            // Add MD5 Hash to the password variable
            $hashedPass = md5($password);
            // Add user info into the database table, claim your fields then values 
            $sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, passport, signupdate) 
        VALUES('" . $username . "','" . $country . "','" . $state . "','" . $city . "','" . $accounttype . "','" . $email . "','" . $hashedPass . "','" . $passport . "',now())") or die(mysql_error());
            // Get the inserted ID here to use in the activation email
            $id = mysql_insert_id();
            // Create directory(folder) to hold each user files(pics, MP3s, etc.) 
            mkdir("memberFiles/$id", 0755);
            // Start assembly of Email Member the activation link
            $to = "$email";
            // Change this to your site admin email
            $from = "admin@somewebsite.com";
            $subject = "Complete your registration";
            //Begin HTML Email Message where you need to change the activation URL inside
            $message = '<html>
        <body bgcolor="#FFFFFF">
        Hi ' . $username . ',
        <br /><br />
        You must complete this step to activate your account with us.
        <br /><br />
        Please click here to activate now &gt;&gt;
        <a href="http://www.netolancer.co.uk/bitcoin/activation.php?id=' . $id . '">
        ACTIVATE NOW</a>
        <br /><br />
        Your Login Data is as follows: 
        <br /><br />
        E-mail Address: ' . $email . ' <br />
        Password: ' . $password . ' 
        <br /><br /> 
        Thanks! 
        </body>
        </html>';
            // end of message
            $headers = "From:" . $from . "\r\n";
            $headers .= "Content-type: text/html\r\n";
            // Finally send the activation email to the member
            mail($to, $subject, $message, $headers);
            // Then print a message to the browser for the joiner 
            print "<br /><br /><br /><h4>OK" . $firstname . ", one last step to verify your email identity:</h4><br />
        We just sent an Activation link to:" . $email . "<br /><br />
        <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
        Link inside the message. After email activation you can log in.";
            exit(); // Exit so the form and page does not display, just this success message
        } // Close else after database duplicate field value checks
    } // Close else after missing vars check
} //Close if $_POST
mysql_close();
?>

I have the impression that you have left out a very large part of your code. For instance the error message variable is not used inside your code after it is set. I haven't taken the time to change everything to mysqli. But I like to encourage you to make the switch. Please not that I haven't test the code, so that part is up to you.

我的印象是你遗漏了很大一部分代码。例如,设置后,代码中不会使用错误消息变量。我没有花时间把所有东西改成mysqli。但我想鼓励你进行转换。请注意,我没有测试代码,因此该部分由您决定。

#1


0  

Try this:

<?php

$errorMsg = "";
// First we check to see if the form has been submitted 
if (isset($_POST['username'])) {
    //Connect to the database through our include 
    include_once "scripts/connect_to_mysql.php";
    // Filter the posted variables
    $username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
    $country = filter_var($_POST['country'], FILTER_SANITIZE_STRING);
    $state = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
    $city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
    $accounttype = filter_var($_POST['accounttype'], FILTER_SANITIZE_STRING);
    $email = filter_var(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
    $password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
    // Check to see if the user filled all fields with
    // the "Required"(*) symbol next to them in the join form
    // and print out to them what they have forgotten to put in
    if ((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password) || (!passport)) {

        $errorMsg = "You did not submit the following required information!<br /><br />";
        if (!$username) {
            $errorMsg .= "--- User Name";
        } else if (!$country) {
            $errorMsg .= "--- Country";
        } else if (!$state) {
            $errorMsg .= "--- State";
        } else if (!$city) {
            $errorMsg .= "--- City";
        } else if (!$accounttype) {
            $errorMsg .= "--- Account Type";
        } else if (!$email) {
            $errorMsg .= "--- Email Address";
        } else if (!$password) {
            $errorMsg .= "--- Password";
        } else if (!$passport) {
            $errorMsg .= "--- Passport";
        }
    } else {
        // Database duplicate Fields Check
        $sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
        $sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
        $username_check = mysql_num_rows($sql_username_check);
        $email_check = mysql_num_rows($sql_email_check);
        if ($username_check > 0) {
            $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
        } else if ($email_check > 0) {
            $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
        } else {
            // Add MD5 Hash to the password variable
            $hashedPass = md5($password);
            // Add user info into the database table, claim your fields then values 
            $sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, passport, signupdate) 
        VALUES('" . $username . "','" . $country . "','" . $state . "','" . $city . "','" . $accounttype . "','" . $email . "','" . $hashedPass . "','" . $passport . "',now())") or die(mysql_error());
            // Get the inserted ID here to use in the activation email
            $id = mysql_insert_id();
            // Create directory(folder) to hold each user files(pics, MP3s, etc.) 
            mkdir("memberFiles/$id", 0755);
            // Start assembly of Email Member the activation link
            $to = "$email";
            // Change this to your site admin email
            $from = "admin@somewebsite.com";
            $subject = "Complete your registration";
            //Begin HTML Email Message where you need to change the activation URL inside
            $message = '<html>
        <body bgcolor="#FFFFFF">
        Hi ' . $username . ',
        <br /><br />
        You must complete this step to activate your account with us.
        <br /><br />
        Please click here to activate now &gt;&gt;
        <a href="http://www.netolancer.co.uk/bitcoin/activation.php?id=' . $id . '">
        ACTIVATE NOW</a>
        <br /><br />
        Your Login Data is as follows: 
        <br /><br />
        E-mail Address: ' . $email . ' <br />
        Password: ' . $password . ' 
        <br /><br /> 
        Thanks! 
        </body>
        </html>';
            // end of message
            $headers = "From:" . $from . "\r\n";
            $headers .= "Content-type: text/html\r\n";
            // Finally send the activation email to the member
            mail($to, $subject, $message, $headers);
            // Then print a message to the browser for the joiner 
            print "<br /><br /><br /><h4>OK" . $firstname . ", one last step to verify your email identity:</h4><br />
        We just sent an Activation link to:" . $email . "<br /><br />
        <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
        Link inside the message. After email activation you can log in.";
            exit(); // Exit so the form and page does not display, just this success message
        } // Close else after database duplicate field value checks
    } // Close else after missing vars check
} //Close if $_POST
mysql_close();
?>

I have the impression that you have left out a very large part of your code. For instance the error message variable is not used inside your code after it is set. I haven't taken the time to change everything to mysqli. But I like to encourage you to make the switch. Please not that I haven't test the code, so that part is up to you.

我的印象是你遗漏了很大一部分代码。例如,设置后,代码中不会使用错误消息变量。我没有花时间把所有东西改成mysqli。但我想鼓励你进行转换。请注意,我没有测试代码,因此该部分由您决定。