crzyman Posted September 15, 2006 Share Posted September 15, 2006 This is the form:[code]<?$myValue = "Joe";?><form action="test.php" method="post"><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="artist" value="<?php echo $myValue; ?>"><input type="submit" name="submit" value="submit"></form>[/code]This is the php script test.php:[code]<?//the host, name, and password for your mysqlmysql_connect("localhost","name","pass");//select the databasemysql_select_db("news");$artist_name = $_GET['artist'];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]Every thing gets put into the database except for the value of $name. Can someone please tell me what I am doing wrong? Many thanks.I aslo tried this, but still no luck.[code]<?$myValue = "Joe";?><form action="test.php" method="post"><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="artist" value=".$myValue."><input type="submit" name="submit" value="submit"></form>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 15, 2006 Share Posted September 15, 2006 $artist_name = [b]$_GET[/b]['artist'];Your form method is [b]POST[/b] :)Retrieve ALL the data from the form from the $_POST array. Do NOT rely on variables being global as your code assumes. Quote Link to comment Share on other sites More sharing options...
crzyman Posted September 15, 2006 Author Share Posted September 15, 2006 Thanks for your help. The value for artist gets entered into the database as .$myValue. and not as "Joe"? Please advise. Many thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 15, 2006 Share Posted September 15, 2006 I don't understand the line in the form code that defines $myName as Joe, but here's how I'd do the script that adds to your database:[code]<?php//the host, name, and password for your mysqlmysql_connect("localhost","name","pass");//select the databasemysql_select_db("news");$name = trim(strip_tags($_POST['name']));$message = trim(strip_tags($_POST['message']));$artist_name = trim(strip_tags($_POST['artist']));if(isset($_POST['submit')){ $time = date("h:ia d/j/y"); $query = "INSERT INTO shoutbox (id,artist_name,name,message,time)". "VALUES ('NULL','$artist_name','$name','$message','$time')"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);}?>[/code]As a side note, you're making future trouble for yourself by entering the time in that format because is you ever want to sort by date, or compare dates you'll have big problems. Use the datetime yyyy-mm-dd hh:mm format for time in going into the database. You can always reformat that to [b]display[/b] in your preferred format. Quote Link to comment Share on other sites More sharing options...
crzyman Posted September 15, 2006 Author Share Posted September 15, 2006 Thank you for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.