Why this stores nothing in DB?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Why this stores nothing in DB?

Post by Perfidus »

Why this is storing nothing on my table?
For me seems to be ok.

Code: Select all

<?php
session_start();
if (session_is_registered('usuario')){
}
$Sesion = session_id;
$conexion=mysql_connect('', '', '');
mysql_select_db("",$conexion); 
$sql = "INSERT INTO Reservas ( Ref, ene1t, ene2t, ene3t, ene4t, ene5t, feb1t, feb2t, feb3t, feb4t, feb5t, mar1t, mar2t, mar3t, mar4t, mar5t, abr1t, abr2t, abr3t, abr4t, abr5t, may1t, may2t, may3t, may4t, may5t, jun1t, jun2t, jun3t, jun4t, jun5t, jul1t, jul2t, jul3t, jul4t, jul5t, ago1t, ago2t, ago3t, ago4t, ago5t, sep1t, sep2t, sep3t, sep4t, sep5t, oct1t, oct2t, oct3t, oct4t, oct5t, nov1t, nov2t, nov3t, nov4t, nov5t, dic1t, dic2t, dic3t, dic4t, dic5, Sesion)".
"VALUES ('$Ref', '$ene1t', '$ene2t', '$ene3t', '$ene4t', '$ene5t', '$feb1t', '$feb2t', '$feb3t', '$feb4t', '$feb5t', '$mar1t', '$mar2t', '$mar3t', '$mar4t', '$mar5t', '$abr1t', '$abr2t', '$abr3t', '$abr4t', '$abr5t', '$may1t', '$may2t', '$may3t', '$may4t', '$may5t', '$jun1t', '$jun2t', '$jun3t', '$jun4t', '$jun5t', '$jul1t', '$jul2t', '$jul3t', '$jul4t', '$jul5t', '$ago1t', '$ago2t', '$ago3t', '$ago4t', '$ago5t', '$sep1t', '$sep2t', '$sep3t', '$sep4t', '$sep5t', '$oct1t', '$oct2t', '$oct3t', '$oct4t', '$oct5t', '$nov1t', '$nov2t', '$nov3t', '$nov4t', '$nov5t', '$dic1t', '$dic2t', '$dic3t', '$dic4t', '$dic5t', '$Sesion')"; 
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$result2 = mysql_query("SELECT * FROM Reservas WHERE (Sesion='$Sesion')", $conexion); 
while($row = mysql_fetch_array($result2))  {
?>
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

you get an error?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you checked the SQL query to make sure that all the variables are being passed correctly? Just do

Code: Select all

echo $sql;
before you do the query.

For the second query, are you sure that $Sesion is set correctly? Have you echoed that to check?

Mac
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

I can`t insert data

Post by Perfidus »

OK, I'm checking the sql but nothing is echoed, maybe the form is wrong and no info reach the page? How can I be sure, Am I echoing sql right?

Code: Select all

<?php
$Sesion = session_id();
$conexion=mysql_connect("","",""); 
mysql_select_db("aa3968",$conexion);
$sql = "INSERT INTO Reservas ( Ref, ene1t, ene2t, ene3t, ene4t, ene5t, feb1t, feb2t, feb3t, feb4t, feb5t, mar1t, mar2t, mar3t, mar4t, mar5t, abr1t, abr2t, abr3t, abr4t, abr5t, may1t, may2t, may3t, may4t, may5t, jun1t, jun2t, jun3t, jun4t, jun5t, jul1t, jul2t, jul3t, jul4t, jul5t, ago1t, ago2t, ago3t, ago4t, ago5t, sep1t, sep2t, sep3t, sep4t, sep5t, oct1t, oct2t, oct3t, oct4t, oct5t, nov1t, nov2t, nov3t, nov4t, nov5t, dic1t, dic2t, dic3t, dic4t, dic5, Sesion)". 
"VALUES ('$Ref', '$ene1t', '$ene2t', '$ene3t', '$ene4t', '$ene5t', '$feb1t', '$feb2t', '$feb3t', '$feb4t', '$feb5t', '$mar1t', '$mar2t', '$mar3t', '$mar4t', '$mar5t', '$abr1t', '$abr2t', '$abr3t', '$abr4t', '$abr5t', '$may1t', '$may2t', '$may3t', '$may4t', '$may5t', '$jun1t', '$jun2t', '$jun3t', '$jun4t', '$jun5t', '$jul1t', '$jul2t', '$jul3t', '$jul4t', '$jul5t', '$ago1t', '$ago2t', '$ago3t', '$ago4t', '$ago5t', '$sep1t', '$sep2t', '$sep3t', '$sep4t', '$sep5t', '$oct1t', '$oct2t', '$oct3t', '$oct4t', '$oct5t', '$nov1t', '$nov2t', '$nov3t', '$nov4t', '$nov5t', '$dic1t', '$dic2t', '$dic3t', '$dic4t', '$dic5t', '$Sesion')"; 
echo $sql;
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 
$result2 = mysql_query("SELECT * FROM Reservas WHERE (Sesion='$Sesion')", $conexion); 
while($row = mysql_fetch_array($result2))  {
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you say nothing is echoed, do you mean nothing at all, or just that the variables aren't echoed?

Mac
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

where do the variables come from? A form?
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

Is the page blank? Are there no errors displayed??

Looks weird how hes using the session..

also have you even connected to the database?? you actually need to connect to it to store data in it...
Post Reply