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

Link to comment
Share on other sites

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/pictures/nopic.png, look at the little noob, Theive the man when you need some ' at line 2

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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 :)

Link to comment
Share on other sites

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.