Saltar al contenido
Underc0de /foro

Ayuda con mi codigo php

Iniciado por deth, Septiembre 07, 2014, 04:32:59 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Avatar de deth
Septiembre 07, 2014, 04:32:59 PM Ultima modificación: Septiembre 07, 2014, 09:11:19 PM por Expermicid

hola amigos mi codigo php me marca error cuando le doy click al boton Actualizar me sale "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='12'' at line 9"

aqui mi codigo:
Código: php

<?php include_once('../../header.php'); ?>

<div class="row"><div class="twelve columns"><h3><?php lang('Car'); ?> - <?php echo $car['name']; ?></h3></div></div>
<div class="row"><div class="twelve columns">
<?php if(isset($_GET['car_id'])) : ?>

<dl class="tabs">
  <dd class="active"><a href="#calendar"><?php lang('Calendar'); ?></a></dd>
  <dd><a href="#edit"><?php lang('Edit'); ?></a></dd>
  <dd><a href="#price"><?php lang('Price'); ?></a></dd>
</dl>

<ul class="tabs-content">

    <!-- TAB 1 -->
  <li class="active" id="calendarTab">
<div class="row">
<div class="six columns">
 
<?php
            if(isset($_GET['calendar']))
            {
                $day = date("d");
                $month = $_GET['calendar_month'];
                $year = $_GET['calendar_year'];
            }
            else
            {
                $day = date("d");
                $month = date("m");
                $year = date("Y");
            }
            $previous_month = ($month-1);
            $next_month = ($month+1);
           
            $previous_year = ($year);
            $next_year = ($year);
           
            if($previous_month == 0)
            {
                $previous_month = 12;
                $previous_year = $previous_year -1;
            }
           
            if($next_month == 13)
            {
                $next_month = 1;
                $next_year = $next_year +1;
            }
            ?>
            <div class="row">
                <div class="eight columns">
                   
                    <a href="?page=rentacar&car&car_id=<?php echo $car['id']; ?>&calendar&calendar_month=<?php echo $previous_month; ?>&calendar_year=<?php echo $previous_year; ?>" class="button secondary small">&laquo; Mes Previo</a>
                    <a href="?page=rentacar&car&car_id=<?php echo $car['id']; ?>&calendar&calendar_month=<?php echo $next_month; ?>&calendar_year=<?php echo $next_year; ?>" class="button secondary small">Próximo Mes &raquo;</a>
                </div>
                <div class="four columns" style="text-align:right;">
                    <a href="?page=rentacar&car&car_id=<?php echo $car['id']; ?>&calendar&calendar_month=<?php echo date("m"); ?>&calendar_year=<?php echo date("Y"); ?>" class="button secondary small">Este Mes</a>
                </div>
            </div>
            <p></p>
            <table class="php_calendar" width="100%">
                <tr>
                    <th colspan="7"><h3><?php echo $month; ?>-<?php echo $year; ?></h3></th>
                </tr>
                <tr>
                    <th><?php lang('LUN'); ?></th>
                    <th><?php lang('MAR'); ?></th>
                    <th><?php lang('MIE'); ?></th>
                    <th><?php lang('JUE'); ?></th>
                    <th><?php lang('VIE'); ?></th>
                    <th><?php lang('SAB'); ?></th>
                    <th><?php lang('DOM'); ?></th>
                </tr>
                <?php
                for ( $i = 1; $i <= 6; $i++)
                {
                    echo '<tr>';
                        if($i == 1) { $i_day_date = 1; $week_day = 1; }
                        else if($i > 1) { $i_day_date = $i_day_date + 6; }
                       
                       
                        for ( $i_date = $i_day_date; $i_date <= $i_day_date + 6; $i_date++)
                        {
                            $week_day_a = date("d", mktime(0, 0, 0, date($month), $week_day, date($year)));
                           
                            $mysql_full_date = $year.'-'.$month.'-'.$week_day_a;
                           
                           
                           
                            $full = 'false'; $button = ''; $end_hours = '__:__';
                            $query_date = mysql_query("SELECT * FROM ".$prefix."reserved WHERE car_id='".$car['id']."' AND status='publish'");
                            while($list_date = mysql_fetch_assoc($query_date))
                            {
                                $q_start_date = explode(' ', $list_date['start_date']);
                                $q_end_date = explode(' ', $list_date['end_date']);
                               
                                if($q_start_date[0] == $mysql_full_date)
                                {
                                    $full = 'true'; $button = '';
                                    $end_hours = substr($q_end_date[1],0,5);
                                }
                               
                                if($mysql_full_date > $q_start_date[0]  and $mysql_full_date < $q_end_date[0])
                                {
                                    $full = 'true'; $button = '';
                                }
                               
                                if($mysql_full_date == $q_end_date[0])
                                {
                                    $full = 'false'; $button = '';
                                    $end_hours = substr($q_end_date[1],0,5);
                                }
                            }
                           
                           
                            if( date("m", mktime(0, 0, 0, date($month), $week_day, date($year))) == $month )
                            {
                                if(date("d", mktime(0, 0, 0, date($month), $i_date, date($year))) == 1 and $week_day_a != 31 and $week_day_a != 30 and $week_day_a != 29 )
                                {
                                    if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Mon')
                                    {
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Tue')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 1;
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Wed')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 2;
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Thu')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 3;
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Fri')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 4;
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Sat')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 5;
                                    }
                                    else if(date("D", mktime(0, 0, 0, date($month), 1, date($year))) == 'Sun')
                                    {
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td>&nbsp;</td>';
                                        echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                            echo $week_day_a; echo $button;
                                            echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                        echo '</td>';
                                        $i_date = $i_date + 6;
                                    }
                                }
                                else
                                {
                                    echo '<td class="'.$full.'" title="'.$end_hours.'">';
                                        echo $week_day_a; echo $button;
                                        echo '<br /><span style="font-size:9px;">'.$end_hours.'</span>';
                                    echo '</td>';
                                }
                            }
                            else
                            {
                                echo '<td>';
                                    echo '&nbsp;';
                                echo '</td>';
                               
                            }
                            $week_day++;
                        }
                       
                    echo '</tr>';
                }
                ?>
            </table>
</div> <!-- /.six columns -->
        <div class="six columns">
        <?php lang('Fechas'); ?> :
            <?php
$query_where_car = mysql_query("SELECT * FROm $database->reserved WHERE status='publish' AND car_id='".$car['id']."' AND where_car='customer'");
if(mysql_num_rows($query_where_car) > 0)
{
while($list_where_car = mysql_fetch_assoc($query_where_car))
{
$reserved_id = $list_where_car['id'];
}
echo '<br /> <a href="../reserved/reserved.php?reserved_id='.$reserved_id.'" class="button secondary small">'.get_lang('Customer').' '.$reserved_id.' &raquo;</a> <br /><br />';
}
else
{
lang('');
}
?>
           
            <div class="panel">
            <?php
            if(isset($_POST['reserved']))
            {
                $sd = trim(mysql_real_escape_string(strip_tags($_POST['sd'])));
                $ed = trim(mysql_real_escape_string(strip_tags($_POST['ed'])));
                $sh = trim(mysql_real_escape_string(strip_tags($_POST['start_hours'])));
                $eh = trim(mysql_real_escape_string(strip_tags($_POST['end_hours'])));
                $start_location = trim(mysql_real_escape_string(strip_tags($_POST['start_location'])));
                $end_location = trim(mysql_real_escape_string(strip_tags($_POST['end_location'])));
               
               
                if($sd == ''){ alert_box('alert', get_lang('Start Date Empty')); exit; }
                if($ed == ''){ alert_box('alert', get_lang('End Date Empty')); exit; }
               
                if($ed < $sd){ alert_box('alert', get_lang('End date can not be smaller')); exit; }
               
               
                // day calc
                $reserved_day = $ed - $sd; if($reserved_day == 0){ $reserved_day = 1; }
               
                $reserved_price = 0.00;
                $query_price = mysql_query("SELECT * FROM $database->meta WHERE ref_id='".$car['id']."' AND title='price' ORDER BY CAST('meta_key' AS SIGNED) ASC");
                while($list_price = mysql_fetch_assoc($query_price))
                {
                    $day_day = $list_price['meta_key'];
                    $day_price = $list_price['meta_value'];
                   
                    if($reserved_day > $day_day)
                    {
                    }
                    else if($reserved_day <= $day_day and $reserved_price < 0.01)
                    {
                        $reserved_price = $day_price;
                    }
                }
                $reserved_total = $reserved_day * $reserved_price;
               
                echo $reserved_price;
               
                // date format for mysql
                $mysql_sd = explode('/', $sd);
                $mysql_sd = $mysql_sd[2].'-'.$mysql_sd[1].'-'.$mysql_sd[0];
               
                $mysql_ed = explode('/', $ed);
                $mysql_ed = $mysql_ed[2].'-'.$mysql_ed[1].'-'.$mysql_ed[0];
               
                // current user id
                $user_id = $user['id'];
               
               
               
                // date control
                $back_button = '<a href="?car_id='.$car['id'].'" class="button">&laquo; '.get_lang('Back').'</a>';
                $query_date = mysql_query("SELECT * FROM $database->reserved WHERE car_id='".$car['id']."' AND status='publish' ORDER BY start_date ASC");
                while($list_date = mysql_fetch_assoc($query_date))
                {
                    $q_start_date = explode(' ', $list_date['start_date']);
                    $q_end_date = explode(' ', $list_date['end_date']);
                   
                    if($q_start_date[0] == $mysql_sd)
                    { alert_box('alert', $mysql_sd.'-'.$mysql_ed.' '.get_lang('Full Calendar')); echo $back_button; exit; }
                   
                    if($mysql_sd > $q_start_date[0]  and $mysql_sd < $q_end_date[0])
                    { alert_box('alert', $mysql_sd.'-'.$mysql_ed.' '.get_lang('Full Calendar')); echo $back_button; exit; }
                   
                    if($mysql_sd < $q_start_date[0]  and $mysql_ed > $q_start_date[0])
                    { alert_box('alert', $mysql_sd.'-'.$mysql_ed.' '.get_lang('Full Calendar')); echo $back_button; exit; }
           
                    if($mysql_ed == $q_start_date[0])
                    {
                        if($mysql_ed.' '.$eh.':00' > $q_start_date[0].' '.$q_start_date[1])
                        { alert_box('alert', $mysql_sd.'-'.$mysql_ed.' '.get_lang('Full Calendar')); echo $back_button; exit; }
                    }
           
                    if($mysql_sd == $q_end_date[0])
                    {
                        if($mysql_sd.' '.$sh.':00' < $q_end_date[0].' '.$q_end_date[1])
                        { alert_box('alert', $mysql_sd.'-'.$mysql_ed.' '.get_lang('Full Calendar')); echo $back_button; exit; }
                    }
                }
   
               
                // add mysql
                mysql_query("INSERT INTO $database->reserved
                (status, car_id, start_date, end_date, day, price, total, payment, start_location, end_location, where_car, user_id)
                VALUES
                ('pending', '".$car['id']."', '$mysql_sd $sh', '$mysql_ed $eh', '$reserved_day', '$reserved_price', '$reserved_total', '0.00', '$start_location', '$end_location', 'car_park', '$user_id')
                ");
                if(mysql_affected_rows() > 0)
                {
                    $reserved_id = mysql_insert_id();
                   
                    add_meta($reserved_id, 'customer', 'first_name', '');
                    add_meta($reserved_id, 'customer', 'last_name', '');
                    add_meta($reserved_id, 'customer', 'email', '');
                    add_meta($reserved_id, 'customer', 'phone', '');
                    add_meta($reserved_id, 'customer', 'address', '');
                    add_meta($reserved_id, 'customer', 'city', '');
                    add_meta($reserved_id, 'customer', 'post_code', '');
                    add_meta($reserved_id, 'customer', 'country', '');
   
           
                    echo '<script>window.location = "../reserved/reserved.php?reserved_id='.$reserved_id.'";</script>';
                }
                else
                {
                    echo mysql_error();
                }
            }
            ?>
           
            <form id="form_rent" name="form_rent" method="POST" action="" class="">
                <div class="row">
                    <div class="six columns">
                        <label for="sd"><?php lang('Start Date'); ?></label>
                        <div class="row">
                            <div class="seven columns">
                                <input type="text" class="w8em format-d-m-y highlight-days-67 range-low-today required" name="sd" id="sd" value="" maxlength="10" readonly />
                            </div>
                            <div class="five columns">
                                <select name="start_hours" id="start_hours">
                                    <option value="12:00">12:00</option>
                                    <option value="13:00">13:00</option>
                                    <option value="14:00">14:00</option>
                                    <option value="15:00">15:00</option>
                                    <option value="16:00">16:00</option>
                                    <option value="17:00">17:00</option>
                                    <option value="18:00">18:00</option>
                                    <option value="19:00">19:00</option>
                                    <option value="20:00">20:00</option>
                                    <option value="21:00">21:00</option>
                                    <option value="22:00">22:00</option>
                                    <option value="23:00">23:00</option>
                                    <option value="00:00">00:00</option>
                                    <option value="01:00">01:00</option>
                                    <option value="02:00">02:00</option>
                                    <option value="03:00">03:00</option>
                                    <option value="04:00">04:00</option>
                                    <option value="05:00">05:00</option>
                                    <option value="06:00">06:00</option>
                                    <option value="07:00">07:00</option>
                                    <option value="08:00">08:00</option>
                                    <option value="09:00">09:00</option>
                                    <option value="10:00">10:00</option>
                                    <option value="11:00">11:00</option>
                                </select>
                            </div>
                        </div>
                        <p></p>
                        <select name="start_location" id="start_location">
                            <option value=""> - <?php lang('Start Location'); ?> - </option>
                            <?php
                            $location = get_meta_list('location');
                            foreach($location as $value)
                            {
                                echo '<option value="'.$value.'">'.$value.'</option>';
                            }
                            ?>
                        </select>
                    </div>
                    <div class="six columns">
                        <label for="ed"><?php lang('End Date'); ?></label>
                        <div class="row">
                            <div class="seven columns">
                                <input type="text" class="w8em format-d-m-y highlight-days-67 range-low-today required" name="ed" id="ed" value="" maxlength="10" readonly />
                            </div>
                            <div class="five columns">
                                <select name="end_hours" id="end_hours">
                                    <option value="12:00">12:00</option>
                                    <option value="13:00">13:00</option>
                                    <option value="14:00">14:00</option>
                                    <option value="15:00">15:00</option>
                                    <option value="16:00">16:00</option>
                                    <option value="17:00">17:00</option>
                                    <option value="18:00">18:00</option>
                                    <option value="19:00">19:00</option>
                                    <option value="20:00">20:00</option>
                                    <option value="21:00">21:00</option>
                                    <option value="22:00">22:00</option>
                                    <option value="23:00">23:00</option>
                                    <option value="00:00">00:00</option>
                                    <option value="01:00">01:00</option>
                                    <option value="02:00">02:00</option>
                                    <option value="03:00">03:00</option>
                                    <option value="04:00">04:00</option>
                                    <option value="05:00">05:00</option>
                                    <option value="06:00">06:00</option>
                                    <option value="07:00">07:00</option>
                                    <option value="08:00">08:00</option>
                                    <option value="09:00">09:00</option>
                                    <option value="10:00">10:00</option>
                                    <option value="11:00">11:00</option>
                                </select>
                            </div>
                        </div>
                        <p></p>
                        <select name="end_location" id="end_location">
                            <option value=""> - <?php lang('End Location'); ?> - </option>
                            <?php
                            $location = get_meta_list('location');
                            foreach($location as $value)
                            {
                                echo '<option value="'.$value.'">'.$value.'</option>';
                            }
                            ?>
                        </select>
                    </div>
                </div>
               
                <p></p>
               
                <div class="row">
                    <div class="twelve columns">
                        <div class="f-right">
                            <input type="hidden" name="reserved" />
                            <input type="submit" class="button" value="<?php lang('Next'); ?> &raquo;" />
                        </div>
                    </div>
                </div>
               
                <p></p>
            </form>
            </div> <!-- /.panel -->
        </div> <!-- /.six columns -->
</div> <!-- /.row -->
  </li> <!-- /.calendar -->
 
 
 
<!-- TAB 2 -->
  <li id="editTab">

        <div class="row">
            <div class="twelve columns">
        <?php
        if(isset($_GET['success']))
        {
            alert_box('success', get_lang('Successful'));
        }
       
        if(isset($_POST['btn_update_car']))
        {
            $name = trim(mysql_real_escape_string(strip_tags($_POST['name'])));
            $plate = trim(mysql_real_escape_string(strip_tags($_POST['plate'])));
            $engine_size = trim(mysql_real_escape_string(strip_tags($_POST['engine_size'])));
            $model_year = trim(mysql_real_escape_string(strip_tags($_POST['model_year'])));
            $mileage = trim(mysql_real_escape_string(strip_tags($_POST['mileage'])));
            $manufacturer = trim(mysql_real_escape_string(strip_tags($_POST['manufacturer'])));
       
            // we check the data
            $continue = true;
            if(strlen($name) < 3 or strlen($name) > 50)
                { $continue = false; alert_box('alert', get_lang('Car Name').': '.get_lang('Minumum charecter').' 3, '.get_lang('Maximum charecter').' 50'); }
               
            if($continue == true)
            {
                if(update_car($car['id'], $name, $plate, $engine_size, $model_year, $mileage, $manufacturer))
                {
                    echo '<script> window.location = "?car_id='.$car['id'].'&success#edit"; </script>';
                }
            }
        }
        ?>

&l
WhatsApp Telegram

5 respuestas

Avatar de blackdrake
Revisa tu sentencia sql de "actualizar" ya que está mal ^^

Un saludo.


Avatar de deth
Cita de: blackdrake en Septiembre 07, 2014, 04:51:41 PM
Revisa tu sentencia sql de "actualizar" ya que está mal ^^

Un saludo.
amigo no entiendo ahi esta el codigo en que parte esta mal

Avatar de Snifer
Estimado Deth revisa tu código, estas haciendo una sentencia erronea en vez de hacer un select puedes estar dando un selet o algo asi.

Regards,
Snifer
Los enlaces son solo para miembros. Registrate o iniciá sesión


Llaman traidor a la persona que evito que caiga el foro, gente bruta!



Avatar de deth
Cita de: Snifer en Septiembre 07, 2014, 10:03:06 PM
Estimado Deth revisa tu código, estas haciendo una sentencia erronea en vez de hacer un select puedes estar dando un selet o algo asi.

Regards,
Snifer

no consigo solucionar el problema ya revise los select y estan bien escritos

Avatar de kid_goth
viejo, al menos pásanos ese header.php :) y aun asi algo que me preocupa es "at line 9" nueve lineas en una consulta y no veo que el php genere algo así, dale ese header.php (me imagino que tiene la conexión a la DB asi que con datos dummie basta :3)

Los enlaces son solo para miembros. Registrate o iniciá sesión

Acepta con humildad y aprecio que en la vida la muerte es inevitable y amarás ésta, adorando la muerte

🔗 Temas relacionados

¿Te quedó una duda sobre Dudas y pedidos generales?

Preguntala y te responde la comunidad (y el asistente Underc0de IA si nadie llega antes). Es gratis y tarda un minuto.

Ya tengo cuenta
Guardamos tu pregunta en este navegador: después de entrar la publicás con un clic.
Grupo de WhatsApp