Can I see an example of something..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Well, All the script does is return me to the add entry link and it doesn't ever update the database..

Also, I contacted my host and asked if register_globals was turned off they said yes and when I asked them to turn it on they said I could do it myself with an .htaccess file?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

dethron wrote:For debugging purposes, use the following line :

echo $id;
So what is the value for $id?
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

all that $id says is "showadd"
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Try to use following script and let me know the output.

1-) Create a test page name as test.php
2-) Fill inside with the following php code

Code: Select all

<?php

if($cm=="a")
    echo "just a letter a";
else if($cm==1)
    echo "the value is number one";
else if($cm == "me")
    echo "it comes out witj two letter";
else if($cm == "1")
    echo "the string filled with one.";
else 
    echo "cm has the value : $cm";
?>
3-) request the page with the following parameters.

Code: Select all

http://yoursite.com/test.php?cm=a

http://yoursite.com/test.php?cm=1

http://yoursite.com/test.php?cm=me

http://yoursite.com/test.php?cm=strange
4-) Send me the output for these four cases.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

1. just a letter a
2. the value is number one
3. it comes out witj two letter
4. cm has the value : strange
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Yes this is great, because as you may seem the idea is the same.

If this works, your code should also work..

Lets observe your code, and find the mistake :)

Just wait some little time.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Can u post the latest draft of the code?

I dont know in what way you changed.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

admin.php

Code: Select all

<?
include('/home/oblivion/public_html/admin/inc/config.php');
$strPAGE=$_SERVER['PHP_SELF'];
if(!isset($id)){
echo('<a href=admin.php?id=showadd>Add Entry</a>');
}
elseif($id==showadd){
$date = date ("Y-m-d H:i:s");
echo"<html><body>
<form name='form1' method='post' action='$strPAGE'>

  <p class='date'>Date: 
    <input name='date' type='text' value='$date' maxlength='20'>
  </p>
  <p class='topic'>Topic : 
    <input name='topic' type='text' size='90' maxlength='180'>
  </p>
  <p class='entry'>Entry:</p>
  <p>
    <textarea name='entry' cols='90' rows='20'></textarea>
  </p>
  <p>
    <input type='submit' name='addentry' value='Submit'>
  </p>
</form>
<p>&nbsp;</p></body>
</html>";
}

function addentry(){ 
global $table; //presuming table isn't posted, but is 'set' elsewhere 
$query = "INSERT INTO $table VALUES ('NULL','{$_POST['date']}','{$_POST['topic']}','{$_POST['entry']}')"; 
echo('Entry Added');
}


?>
config.php

Code: Select all

<?
//Include strings
include('/home/oblivion/public_html/admin/inc/strings.php');

//MySQL Connection Var's
define('DB_NAME', 'oblivion_main');
define('DB_HOST', 'localhost');
define('DB_USER', 'oblivion_oblivio');
define('DB_PASS', 'digital1');
$table=("journal");
$url=('http://www.o-blivion.com/site/blog');
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

dethron will you quit teasing the kid and give him some solid help? lol

Try this:

Code: Select all

$query = "INSERT INTO $table VALUES ('NULL','$date','$topic','$entry')";
Change to:

Code: Select all

$query = mysql_query ("INSERT INTO tablename (date table name,topic table name, entry table name) VALUES ('$date', '$topic', '$entry')");
mysql_query($query);
Last edited by tim on Fri Feb 13, 2004 5:38 pm, edited 1 time in total.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

dethron out.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

tim wrote:dethron will you quit teasing the kid and give him some solid help? lol

Try this:

Code: Select all

$query = "INSERT INTO $table VALUES ('NULL','$date','$topic','$entry')";
Change to:

Code: Select all

$query = mysql_query ("INSERT INTO tablename (date table name,topic table name, entry table name) VALUES ('$date', '$topic', '$entry')");
mysql_query($query);
The point of these forums is to help people understand how things work and how they can do it on their own. I believe Dethron was very helpful in happening this guy understand the concept of using variables to load things. The person did not ask about his query, althought it was helpful for you to give him a better way to do it, so you infact did not give him any "solid help"
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

if you'd notice the "lol" after my smart comment, it meant I was just joking.

man everyone has to be so uptight anymore these days.

Sorry dethron, no harm meant.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Thanks to all of you that are trying to help me figuare this.. But I am still clueless on why it wont work.. I've tried everything I know (and that isn't much) and I can't get it to work what so ever.. Any other ideas??
User avatar
Michael 01
Forum Commoner
Posts: 87
Joined: Wed Feb 04, 2004 12:26 am

Post by Michael 01 »

Double check what length you have each column in your SQL just to make sure its not set lower than those values defined in your script. Specifically your DATE area.

Secondly, be sure to use addslashes, and htmlspecialchars functions to your variables before the insert so that the data is inputted without possible corruption when you do get it working.
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

All the MySQL stuff is set up correctly.. The addentry code works fine when it isn' a function.. thats my only problem..
Post Reply