Jump to content

[SOLVED] MySQL adding row


Msword

Recommended Posts

<?php
require("dbconnect.php");
mysql_select_db("runecrypt", $sql);
$personid = 1; //needs to be from variable(person.php?personid=1) note for later
$name = 'Man';
$pictureurl = '/pictures/nopic.png';
$exinfo = 'look at the little noob';
$dsc = 'Theive the man when you need some cash';
$location = 'All around the world';
$quest = 'http://www.runecrypt.com/index.php?pid=49';
$membonly = 'Yes';
$contributors = 'Msword, others';
$lastupdate = 'CURDATE()';
mysql_query("INSERT INTO pdatabase (name, pictureurl, exinfo, dsc, location, quest, membonly, contributors, lastupdate)
VALUES ($name, $pictureurl, $exinfo, $dsc, $location, $quest, $membonly, $contributors, $lastupdate)");
?>

isn't added anything to the table, whats wrong?

Link to comment
https://forums.phpfreaks.com/topic/63125-solved-mysql-adding-row/
Share on other sites

try to do similar to this to see the error

mysql_query("INSERT INTO pdatabase (name, pictureurl, exinfo, dsc, location, quest, membonly, contributors, lastupdate)
VALUES ($name, $pictureurl, $exinfo, $dsc, $location, $quest, $membonly, $contributors, $lastupdate)") or die(mysql_error());

 

or you would want to put a ' ' in the varibale inside that statement

No problem. Glad to help. Just an FYI, I learned 99% of what I know here in these forums.

 

On the timestamp, do you actually need the time stamp format or just a date? As in today's date. Normally the timestamp format would be used for other calcs down the road. The CURDATE, I believe, is a MySQL function and not a PHP function. You might try replacing that with the PHP equivalent in order to get your date.

 

If you don't need an actual timestamp then I use this format and it works great:

 

$date = date("F j, Y, g:i a");

<?php
require("dbconnect.php");
mysql_select_db("runecrypt", $sql);
$personid = 1; //needs to be from variable(person.php?personid=1)   note for later
$name = 'Man';
$pictureurl = mysql_real_escape_string('/pictures/nopic.png');
$exinfo = 'look at the little noob';
$dsc = 'Theive the man when you need some cash';
$location = 'All around the world';
$quest = mysql_real_escape_string('http://www.runecrypt.com/index.php?pid=49');
$membonly = 'Yes';
$contributors = mysql_real_escape_string('Msword, others');
$lastupdate = date("F j, Y, g:i a");
mysql_query("INSERT INTO pdatabase (name, pictureurl, exinfo, dsc, location, quest, membonly, contributors, lastupdate)
VALUES ('$name', '$pictureurl', '$exinfo', '$dsc', '$location', '$quest', '$membonly', '$contributors', '$lastupdate')") or die(mysql_error());
?>

whats wrong with that? it just comes out as 0000-00-00

i only need a date, time doesn't matter, as i'm not calculating anything with this, just needs to be able to be displayed

 

EDIT: nevermind, just used the wrong variable type on the database :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.