Page 1 of 1

Insert not working....

Posted: Wed Nov 26, 2008 9:44 am
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?

Re: Insert not working....

Posted: Wed Nov 26, 2008 10:10 am
by andyhoneycutt
What do you get when you run the query through the mysql console?

-Andy

Re: Insert not working....

Posted: Wed Nov 26, 2008 1:11 pm
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! :)

Re: Insert not working....

Posted: Thu Nov 27, 2008 3:40 am
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