Forum Moderators: coopster
Any ideas?
------------------------------------------
<?php
$connect= mysql_connect("localhost","root","****xx") or die("Could not connect to database in localhost!");
$result= mysql_select_db("outagedb") or die("Could not select outagedb database!");
$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description)
VALUES=
('$name',
'$date',
'$device',
'$tac',
'$utt',
'$description')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
echo "<table border=1 align=center width=500>";
echo " <tr> ";
echo " <td> ";
echo " Name";
echo " </td>";
echo " <td>".$name. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Date";
echo " </td>";
echo " <td >".$date. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Device";
echo " </td>";
echo " <td >".$device. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Tac Case";
echo " </td>";
echo " <td >".$tac. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " UTT Ticket";
echo " </td>";
echo " <td >".$utt. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Description";
echo " </td>";
echo " <td>".$description. "</td>";
echo " </tr>";
echo "</table>";
?>
try getting the actual error from mysql like so
change this line
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
to
$queryresult = mysql_query($sqlquery) or die(mysql_error() [ca.php.net]);
that should help you get more detailed information about the actual error.
You have an error in your SQL syntax near '(name,date,device,tac,utt,description) VALUES= ('', '', '', '', '', '')' at line 1
------------------------------------------
Here's a question which I'm not sure if it's the cause of my problem....
I have a field in the table called "key".....
Does this field need to be in the php script? Does it need to be in the form as a hidden field or something?
Sorry for the newbie questions....trying to learn.
no worries :)
>>trying to learn
that's what we're here for
As you can see it isn't getting the variables that are posted from the form.
VALUES= ('', '', '', '', '', '')
obviously they are all blank. Did you submit a blank form? if not you may want to do this
extract($_POST);
$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description) VALUES=('$name', '$date', '$device', '$tac', '$utt', '$description')";
is the key field PRIMARY KEY AUTO_INCREMENT?
Yes, the field 'key' is set as primary auto-increment.
The form isn't blank...I'm not sure why the variables are not being picked up.
By the way, in case I forget...thanks for the time.
I set up the table with 7 fields...("key" being the one used as the primary). On my form, I only have the 6 form fields(name,date,device,tac,utt,description ) and pointed the action POST to the php script.
I'm not sure if I need to do anything with the "key" field other than put it in the table for indexing purposes. I didn't mention it anywhere on the html form or the php script.
The connection to the SQL seems to be ok. I'm actually pretty new at PHP...so there might be some basic step I'm missing.
$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description)You will still need to get your columns from the form data though as jatar_k suggested earlier.
VALUES
('$name',
'$date',
'$device',
'$tac',
'$utt',
'$description')";
1)I need to let the person posting know that the post was succesful.
2)I need to have an option of searching the database and displaying results from past posts
Any ideas or tutorials to get me started? I've been cruising other posts but it's only confusing me further. No 2 scripts are alike. I see some basic syntax (like connecting to a databse, or querying a databse)...but I'm not sure how or where to put this code.
I have 1 html page with the form and 1 php file that does the first processing. What now?
Maybe I should buy a book...but that means I would need to learn how to read ;)
More truth to that statement than you could imagine! That's why we come here.
nir0, have you trolled through the PHP Library [webmasterworld.com] here yet? There are a couple threads in there that should really help you get going...