Jump to content


Photo

Help with a simple shout box. *SOLVED*


  • Please log in to reply
3 replies to this topic

#1 crzyman

crzyman
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 September 2006 - 06:32 PM

Hello. This is driving me nuts. I have a page that loads information from a database into a page using the include statement. So if the varible $name = "Joe" then it will pull all the information from the database for joe. This works great. Now I am trying to make a shout box on the page. This is my code:

comment.php
<?PHP
$myValue = "Joe";
?>

<form action="test.php" method="GET">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br>
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="hidden" name=$myValues  
<input type="submit" name="submit" value="submit">
  
</form>
This creates the form that allows a user to enter his/her name and message. It calls test.php, which looks like this:
<?
mysql_connect("localhost","name","password");

mysql_select_db("news");

$artist_name =  $_GET['$myValues'];

if($submit)
{
   
   $time=date("h:ia d/j/y");
   
   $result=MYSQL_QUERY("INSERT INTO shoutbox (id,artist_name,name,message,time)".
      "VALUES ('NULL','$artist_name','$name', '$message','$time')");
}
?>

The information for $myValue doesn't get entered into the database. The rest of it works. Somehow I have to pass the value of $myValue to the script, test.php, from the form which is comment.php. Can this even be done or am I way out of key here? Please advise.

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 September 2006 - 06:36 PM

first redo some of the code, put the query itself into a variable like
$insert "INSERT INTO tablename ...;";
then do the query with a handle
$query = mysql_query($insert)
ex cetera, then below everything type in
echo mysql_error();
then return the error message here.
If no error messages comes up, check your variables by
echoing each of them, find out which ones are getting filled and which ones are empty.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 15 September 2006 - 06:38 PM

Well first you did not close your tags and second you didn't give it a value. Right now you are giving that value a name of Joe.Is that your intention???

try this
<input type="hidden" name=myValues value="<?=$myValue?>">


also $submit will not work unless you have globals turned on, which they are not by default

if(isset($_GET['submit'])){

Here is revised code
<?php
$myValue = "Joe";
?>

<form action="test.php" method="GET">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br>
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="hidden" name=myValues value="<?=$myValue?>">  
<input type="submit" name="submit" value="submit">
  
</form>

<?php
mysql_connect("localhost","name","password");

mysql_select_db("news");

$artist_name =  $_GET['myValues'];

if(isset($_GET['submit']))
{
   
   $time=date("h:ia d/j/y");
   
   $result=MYSQL_QUERY("INSERT INTO shoutbox (artist_name,name,message,time)".
      "VALUES ('$artist_name','$name', '$message','$time')");
}
?>

You do not have to insert a null value into an autoincrement field. It will fill in by itself

Ray



Ray



#4 crzyman

crzyman
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 15 September 2006 - 06:58 PM

Thank you so very much. Its working great.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users