Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    127.0.0.1
    Posts
    67
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Question Problem with rand()

    hi.....I need to have random 10nums in one string, without spaces or dots.
    I tried this:
    PHP Code:
    $delcode rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9); 
    but on site that message appeared:
    Code:
    Notice: Undefined variable: delcode in /opt/lampp/htdocs/newsletter/index.php on line 16
    here is all my code:
    PHP Code:
    <?php

    $title 
    "Newsletter";

    include(
    '../header.php');
    include(
    "../functions/mysql_con.php");

    $delcode rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9);

    function 
    sendmail($to) {
    $subject "[site] - Registrácia do newsletteru";
    $message '
    Vážený zákazník,
      ďakujeme Vám za registráciu do newsletteru na našej stránke.

      Ak sa chcete odhlásiť z newsletteru, kliknite <a href="http://[site].sk/newsletter/odhlasenie/?id='
    .$delcode.'">sem</a>.';
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' "\r\n";
    $headers .= 'From: [site].sk <newsletter@[site].sk>' "\r\n";
    mail($to,$subject,$message,$headers);
    }

    if (
    $_POST['send']) {
    $old = array("\"""\'""<"">""("")"";""ľ""š""č""ť""ž""ý""á""í""é""ň""ú""ä""ô");
    $new   = array(""", "'", "&lt", "(", ")", ";", "&gt", "Äľ", "š", "ÄŤ", "ĹĄ", "Ĺľ", "Ă˝", "á", "Ă*", "Ă©", "Ĺˆ", "Ăş", "ä", "Ă´");
    $email = str_replace($new, $old, $_POST['
    email']);

    if (strcmp($_POST['
    email'],"")) {

    if (mysql_query("INSERT INTO newsletter (mail,del_code) VALUES ('".$email."','".$delcode."')") && sendmail($email))
    {
    echo '
    <div id="content" align="center">

    <
    h2>Úspe&#353;ne ste sa registrovali do newsletteru</h2>

    </div>

    <
    meta http-equiv="refresh" content="2;url=/">
    ';
    }
    else {
    echo '
    <div id="content" align="center">

    <
    h2>Vyskitol sa problém pri registrácii</h2>

    <
    p>Prosím skuste neskôr.</p>

    </
    div>
    ';
    }
    }
    else {
    echo '
    <div id="content" align="center">

    <
    h2>Nezadali ste svoj e-mail</h2>

    <
    table>
        <
    form action="/newsletter/index.php" method="post">
            <
    tr><td>&#353; e-mail: </td><td><input type="text" name="email" maxlength="350" /></td></tr>
            
    <tr><td colspan="2"><input type="hidden" name="send" value="1" /></td></tr>
            <
    tr><td colspan="2"><input type="submit" value="Prihlásiť sa do newsletteru" /></td></tr>
        </
    form>
    </
    table>

    </
    div>
    ';
    }
    }
    include("../functions/mysql_close.php");
    include('
    ../footer.php); ?>
    where is the problem?

    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,428
    Thanks
    11
    Thanked 302 Times in 301 Posts
    Inside your sendmail function, $delcode is *local* since you haven't declared it global (which it is). So you need to start sendmail like this:
    Code:
    function sendmail($to) { global $delcode; ....
    Or you could pass $delcode in as a parameter to sendmail, of course (which would be better).

    Dave

  • Users who have thanked tracknut for this post:

    sonic656 (01-07-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •