Jump to content

not inserting in mysql.


bogdaniel

Recommended Posts

hello please can someone help me with this code.. it doesn't give any error it doesn't says something on var_dump says NULL NULL...

 

 

 

 

 

<? 
function formular($stare = 1)
{
    if ($stare == 1) {
        $x = '';
        $y = '';
    } else {
        $x = $_POST['x'];
        $y = $_POST['y'];
    }


    $formular = '<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
 <td><form name="form1" method="post" action="' . $_SERVER['PHP_SELF'] . '">
 </td>
</tr>
<tr>
 <td><input name="x" type="text" value="' . $x . '" maxlength="3">
 </td>
</tr>
<tr>
 <td><input name="y" type="text" value="' . $y . '" maxlength="3">
 </td>
</tr>
<tr>
 <td><input type="submit" name="Submit" value="Rezerva">
 </td>
</tr>';

    return $formular;
}

if (!isset($_POST['x'])) {
    echo formular(1);
} else {
    $x = $_POST['x'];
    $y = $_POST['y'];

    $verificare = 0;

    if (empty($x)) {
        $verificare = 1;
        echo '<br>Nu A fost Specificat coordonatul X.';
    }

    if (strlen($x) < 1) {
        $verificare = 1;
        echo '<br>Minim 2 caractere.';
    } elseif (!eregi('[0-9]{1}', $x)) {
        $verificare = 1;
        echo '<br>Coordonatul trebuie sa contima minim 2 caractere.';
    }
    if (empty($y)) {
        $verificare = 1;
        echo '<br>Nu A fost Specificat coordonatul X.';
    }

    if (strlen($y) < 1) {
        $verificare = 1;
        echo '<br>Minim 2 caractere.';
    } elseif (!eregi('[0-9]{1}', $y)) {
        $verificare = 1;
        echo '<br>Coordonatul trebuie sa contima minim 2 caractere.';
    }

    if ($verificare == 1) {
        echo formular(0);
    } else {
    	$userid = $_SESSION['id'];
        $result = mysql_query("SELECT DISTINCT x, y FROM ".TBL_REZERVARI." WHERE x = '$x' AND y = '$y' ");
        if (mysql_numrows($result) >= 1) {
            exit();
        } else {
            $sql = mysql_query("INSERT INTO ".TBL_REZERVARI." (`user_id`, `x`, `y`, `data`, `expira`, `time`) VALUES ('$userid', '$x', '$x',  NOW(), CURDATE() + INTERVAL 3 DAY, CURTIME())") or
                die('Nu am putut adauga nimic. ' . mysql_error());
            //var_dump($_SESSION);
            
            $q = mysql_query("SELECT * FROM ".TBL_REZERVARI."");
            $num_rows = mysql_num_rows($q);
            echo "$num_rows Rows\n";

        }
    }
} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.