PDA

View Full Version : PHP and forms..


Alex
December 22nd, 2004, 11:18
I want to submit the input from a form to a php file for processing and adding it to a database.

The trouble is that it works perfectly on my 'localhost' but I upload it to a remote server (same PHP version) and I get my error: "No name specified." ... here is my hosts phpinfo: http://www.devplant.com/phpinfo.php

What could be causing this? Is there something I'm missing? :(

What I have:

<form name='f1' action='com/addobj.php' method='post'>
<div class='row' style='font-size: 11px;'>
Name of article: <input type='text' size='25' name='obj_name' />
</div>
<div class='row'>
<input type='submit' name='Add' value='Add article' />
</div>
<div class='spacer'>
</div>
</form>


and the PHP: (addobj.php)



<?php
if($_POST["obj_name"] = $obj_name) {

$insert = "INSERT INTO sayop_obj (obj_name) VALUES ('$obj_name')";
mysql_query($insert) or die("Sorry, could not add new object >>> " . mysql_error());
//...
} else { echo "No name specified.";}

?>

Jamie
December 22nd, 2004, 11:46
I am assuming you have created the database and username and password and then told PHP to store it there?

Alex
December 22nd, 2004, 11:52
Of course, the other parts of the script that use this feature work perfectly. but this doesn't... One of those problems that drives you insane and stops the whole project....

for some reason if($_POST["obj_name"] = $obj_name) returns false and shows the error. It shouldn't...

Jamie
December 22nd, 2004, 12:03
I'm stumped. To be honest I have only just gotten in to this PHP game, what a wonderful game it is as well! ;) Once that country called the USA wake up I am sure you'll have an answer. :D

vigo
December 22nd, 2004, 12:05
Try using strcmp instead if the assignment operator (=) in your comparasion.

Alex
December 22nd, 2004, 12:06
Thanks jamie, Its alive!!! :D

I changed it to:

if($_POST["obj_name"]) {
$obj_name = $_POST["obj_name"];
//etc...
} else { echo "No name specified.";}


and it works... *scratches head* good enough for me :)

//edit:
thanks vigo, I'll check that out too, things 'post' fast around here ;)

Jamie
December 22nd, 2004, 12:19
Glad you go it working dirmass :D

vigo
December 22nd, 2004, 13:11
//edit:
thanks vigo, I'll check that out too, things 'post' fast around here ;)

Glad it works now. It's very fast round here (any of you guys actually get any work done? :wink:)... I may need to start drinking caffeine again :shock: