Jump to content

Recommended Posts

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)");


?>

Link to comment
https://forums.phpfreaks.com/topic/70395-solved-help-with-insert/
Share on other sites

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')");
	}

?>

...
}

$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());
}

?>

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());
}
}
?>

@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'

 

 

 

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);

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());
}
}
?>

<?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());
}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.