Jump to content

Help with a simple shout box. *SOLVED*


crzyman

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.
Link to comment
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.
Link to comment
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

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.