Insert not working....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CodeMama
Forum Newbie
Posts: 9
Joined: Fri Nov 07, 2008 12:28 pm

Insert not working....

Post by CodeMama »

Ok, I'm missing something....this script was working fine for me yesterday, I added a couple more fields and now it is not inserting...

Code: Select all

<?php
if(isset($_POST['add']))
{
 include 'inc/dbconnOpen.php';
 $href = $_POST['href'];
 $title = $_POST['title'];
 $blurb = $_POST['blurb'];
 $bmonth = $_POST['bmonth'];
 $bday = $_POST['bday'];
 $byear = $_POST['byear'];
 $emonth = $_POST['emonth'];
 $eday = $_POST['eday'];
 $eyear = $_POST['eyear'];
 $expos = $_POST['expos'];
 
 $query = "INSERT INTO `textads`  (`title`, `href`, `blurb`, `bmonth`, `bday`, `byear`, `emonth`, `eday`, `eyear`, `expos`) VALUES
('$title', '$href', '$blurb', '$bDate', '$eDate', '$expos', '$bmonth', '$bday', '$byear', '$emonth', '$eday', '$eyear')";
/*echo $query; */
 mysql_query($query) or die('Error, friggin insert query failed');
 echo "New Dream Job Text Ad  added";
}
else
{
?>
<form action="" method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">TITLE</td>
<td><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td width="100">Blurb</td>
<td><input name="blurb" type="text" id="blurb"></td>
</tr>
<tr>
<td width="100">LINK</td>
<td><input name="href" type="text" id="href"></td>
</tr>
<tr>
<td width="100">Beginning Date</td>
<td>
<table>
<td>Month:<input name="bmonth" type="text" id="bmonth"></td><td>Day:<input name="bday" type="text" id="bday"></td><td>Year:<input name="byear" type="text" id="byear"></td></table></td>
</tr>
<tr>
<td width="100">Ending Date</td>
<td>
<table>
<td>Month<input name="emonth" type="text" id="emonth"></td><td>Day: <input name="eday" type="text" id="eday"></td><td>Year:<input name="eyear" type="text" id="eyear"></td></table></td>
</tr>
<tr>
<td width="100">Exposures Purchased</td>
<td><input name="expos" type="text" id="expos"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add AD"><input type="reset"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
What did I get wrong?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Insert not working....

Post by andyhoneycutt »

What do you get when you run the query through the mysql console?

-Andy
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Insert not working....

Post by JAB Creations »

While sort of noobish I enjoy using phpMyAdmin...

I would recommend removing the mysql_query function and just assign it as a string...then do a print_r and go to phpMyAdmin and execute the function there (once the variables have been converted to values that echo out in the browser). From there you should be able to troubleshoot it nicely.

...or you could copy and paste your variables, make a backup of them in a commented area of your code...write static values and slowly reassign the new variables to their original source one or two at a time until you determine which one is the culprit. Good luck! :)
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: Insert not working....

Post by iijb »

Hi,
I think you have to make a little change in your code. In place of '$title' change it to
' ". $title ." '
Change your code like this.

$query = "INSERT INTO `textads` (`title`, `href`, `blurb`, `bmonth`, `bday`, `byear`, `emonth`, `eday`, `eyear`, `expos`) VALUES
('". $title ."' ,'". $href ."', ......)";

Hope this will work
iijb
Post Reply