forumnz Posted September 23, 2007 Share Posted September 23, 2007 THis isn't displaying any errors but won't insert into db. What could be the prob? Sam. <?php $title = $_POST['title']; $subtitle = $_POST['subtitle']; $startp = $_POST['startp']; $res = $_POST['res']; $bnp = $_POST['bnp']; $descr = $_POST['descr']; $pup = $_POST['pup']; $days = $_POST['days']; $duration = $days; //Connect to mysql server $link=mysql_connect("localhost","aaaa","aaaa"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("bbmembers"); if(!$db) { die("Unable to select database"); } mysql_query("INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, $title, $subtitle, $startp, $res, $bnp, $descr, $pup, $days)"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/ Share on other sites More sharing options...
rarebit Posted September 23, 2007 Share Posted September 23, 2007 Try it like this! $result = mysql_query($s); if (!$result) { die('Invalid query: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353636 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 Invalid query: Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353642 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 should do it if($query!=="false") {insert} else if($query=="false") { echo "error";} Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353646 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 I dont know. ALl I know is something isn't working?? Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353648 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 please paste the code Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353652 Share on other sites More sharing options...
dbo Posted September 23, 2007 Share Posted September 23, 2007 Couple things. 1) This thing looks weird, not sure what you're doing there. NOW()+INTERVAL $duration DAY 2) Field types that handle strings should be surrounded by '' Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353653 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 if ($result!=='true') { die('Invalid query: ' . mysql_error()); } else { insert into database;} Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353655 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 This is the current code and the form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="insert.php"> <input type="text" name="title" id="title" /> <br /> <input type="text" name="subtitle" id="subtitle" /> <br /> <input type="text" name="startp" id="startp" /> <br /> <input type="text" name="res" id="res" /> <br /> <input type="text" name="bnp" id="bnp" /> <br /> <label> <textarea name="descr" id="descr" cols="45" rows="5"></textarea> </label> <br /> <label> <select name="pup" id="pup"> <option value="Pick-ups Allowed">Pick-ups Allowed</option> <option value="No Pick-ups">No Pick-ups</option> </select> </label> <br /> <label> <select name="days" id="days"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="14">14</option> </select> </label> <br /> <br /> <br /> <label> <input type="submit" name="button" id="button" value="Submit" /> </label> <br /> </form> </body> </html> <?php $title = $_POST['title']; $subtitle = $_POST['subtitle']; $startp = $_POST['startp']; $res = $_POST['res']; $bnp = $_POST['bnp']; $descr = $_POST['descr']; $pup = $_POST['pup']; $days = $_POST['days']; $duration = $days; //Connect to mysql server $link=mysql_connect("localhost","aaa","aaa"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("bbmembers"); if(!$db) { die("Unable to select database"); } $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } else { mysql_query("INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, '$title, $subtitle, $startp, $res, $bnp, $descr, $pup, $days')"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353683 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 $result = mysql_query($s); Where is $s defined? Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353690 Share on other sites More sharing options...
rarebit Posted September 23, 2007 Share Posted September 23, 2007 ... } $s = "INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, '$title, $subtitle, $startp, $res, $bnp, $descr, $pup, $days')"; $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353691 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 Couple things. 1) This thing looks weird, not sure what you're doing there. NOW()+INTERVAL $duration DAY Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353692 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 What do I do then? I currently have this: <?php $title = $_POST['title']; $subtitle = $_POST['subtitle']; $startp = $_POST['startp']; $res = $_POST['res']; $bnp = $_POST['bnp']; $descr = $_POST['descr']; $pup = $_POST['pup']; $days = $_POST['days']; $duration = $days; //Connect to mysql server $link=mysql_connect("localhost","aaa","aaa"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("bbmembers"); if(!$db) { die("Unable to select database"); } $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } else { $s = "INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, '$title', '$subtitle', '$startp', '$res', '$bnp', '$descr', '$pup', '$days')"; $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353700 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 Are you getting any errors? I think you need the MySQL function DATE_ADD: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-add DATE_ADD(date,INTERVAL expr unit) Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353701 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 Yes this error. Invalid query: Query was empty What does that error mean? Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353708 Share on other sites More sharing options...
Barand Posted September 23, 2007 Share Posted September 23, 2007 @BlueSkyIS, if you read that page you'll find Date arithmetic also can be performed using INTERVAL together with the + or - operator: date + INTERVAL expr unit date - INTERVAL expr unit Example: mysql> SELECT '1997-12-31 23:59:59' + INTERVAL 1 SECOND; -> '1998-01-01 00:00:00' Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353710 Share on other sites More sharing options...
forumnz Posted September 23, 2007 Author Share Posted September 23, 2007 SO what could the problem be? Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353712 Share on other sites More sharing options...
Barand Posted September 23, 2007 Share Posted September 23, 2007 Yes this error. Invalid query: Query was empty What does that error mean? You usually get that error if you do something like $query = "SELECT blah FROM table"; $result = mysql_query($non_existant_var_name); Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353717 Share on other sites More sharing options...
forumnz Posted September 24, 2007 Author Share Posted September 24, 2007 This is the code currently. It shouldn't do that. I can't see the prob. Can you? <?php $title = $_POST['title']; $subtitle = $_POST['subtitle']; $startp = $_POST['startp']; $res = $_POST['res']; $bnp = $_POST['bnp']; $descr = $_POST['descr']; $pup = $_POST['pup']; $days = $_POST['days']; $duration = $days; //Connect to mysql server $link=mysql_connect("localhost","aaa","aaa"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("bbmembers"); if(!$db) { die("Unable to select database"); } $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } else { $s = "INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, '$title', '$subtitle', '$startp', '$res', '$bnp', '$descr', '$pup', '$days')"; $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353718 Share on other sites More sharing options...
Barand Posted September 24, 2007 Share Posted September 24, 2007 <?php $title = $_POST['title']; $subtitle = $_POST['subtitle']; $startp = $_POST['startp']; $res = $_POST['res']; $bnp = $_POST['bnp']; $descr = $_POST['descr']; $pup = $_POST['pup']; $days = $_POST['days']; $duration = $days; //Connect to mysql server $link=mysql_connect("localhost","aaa","aaa"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("bbmembers"); if(!$db) { die("Unable to select database"); } $result = mysql_query($s); // ????????????????????????????????????? if ($result!=='true') { die('Invalid query: ' . mysql_error()); } else { $s = "INSERT INTO auctions (start, end, title, subtitle, startp, res, bnp, descr, pup, days) VALUES (NOW(), NOW()+INTERVAL $duration DAY, '$title', '$subtitle', '$startp', '$res', '$bnp', '$descr', '$pup', '$days')"; $result = mysql_query($s); if ($result!=='true') { die('Invalid query: ' . mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353721 Share on other sites More sharing options...
forumnz Posted September 24, 2007 Author Share Posted September 24, 2007 I now get this Invalid query: Unknown column 'days' in 'field list' Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353722 Share on other sites More sharing options...
darkfreaks Posted September 24, 2007 Share Posted September 24, 2007 is days a column in your db? Quote Link to comment https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/#findComment-353724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.