Jump to content

Archived

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

crzyman

Help with a simple shout box. *SOLVED*

Recommended Posts

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
[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 
<input type="submit" name="submit" value="submit">
 
</form>
[/code]
This creates the form that allows a user to enter his/her name and message. It calls test.php, which looks like this:
[code]
<?
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')");
}
?>
[/code]

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
[code]<input type="hidden" name=myValues value="<?=$myValue?>">[/code]


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

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

Here is revised code
[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>[/code]

[code]<?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')");
}
?>[/code]

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

Ray



Ray

Share this post


Link to post
Share on other sites

×

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.