Page 1 of 1

PHP problem

Posted: Sun Apr 20, 2003 1:18 am
by reverend_ink
ok I am quit new at php, and tackeling hard projects early on...

but researched hours and hours to start a php/mysql form but am unable to input the data to the db....

any help would be great...

thanks in advance....

<?
$host = "host";
$login_name = "login";
$password = "password";


MySQL_connect("$host","$login_name","$password");


MySQL_select_db("db_name") or die("Could not select database");
$query = mysql_query("INSERT INTO table (partnerid, first_name, last_name, email, address, address2, city, state, country, zip, soc_sec, phone, password_hint, password) VALUES ('', '$first_name', '$last_name', '$email', '$address', '$address2', '$city'. '$state', '$country', '$zip', '$soc_sec', '$phone', '$password_hint', '$password')");
$result = mysql_query("SELECT partnerid FROM table WHERE first_name = '$first_name%' AND last_name = '$last_name%' AND password = '$password%' ");
$data = mysql_fetch_array($result);
MySQL_close()
?>

Posted: Sun Apr 20, 2003 3:59 am
by volka
what happens? what does not? php version? os? did you read Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+?
welcome ;)

Posted: Sun Apr 20, 2003 11:28 am
by reverend_ink
Nothing is happening

Using freebsd with php4 and mysql 3.23.42

when the form posts to the php script it doenst post the information to the database.

and yes I read the sticky but didnt provide my particular errors....

Posted: Sun Apr 20, 2003 12:19 pm
by twigletmac
reverend_ink wrote:and yes I read the sticky but didnt provide my particular errors....
but did you try using $_POST (if you sent the information from the form via the POST method) or $_GET (if you sent the information from the form via the GET method)?

Basically, using the recommended settings in the php.ini (PHP's configuration file) you can't do this:

Code: Select all

&lt;form action="file.php" method="post"&gt;
&lt;input type="text" name="field1" /&gt;
&lt;input type="text" name="field2" /&gt;
&lt;input type="submit" name="submit" value="submit" /&gt;
and then do this in file.php:

Code: Select all

echo 'in field1 you entered: '.$field1;
echo '<br />';
echo 'in field2 you entered: '.$field2;
you would have to do something like:

Code: Select all

echo 'in field1 you entered: '.$_POST['field1'];
echo '<br />';
echo 'in field2 you entered: '.$_POST['field2'];
Also short tags may be disabled so you may have to use <?php ?> instead of <? ?>.

For more debugging try changing your code to something like this:

Code: Select all

<?php 
$host = 'host'; 
$login_name = 'login'; 
$password = 'password'; 

// don't put variable names into quotes, do $host not "$host", the quotes
// are totally unneccessary.
@mysql_connect($host, $login_name, $password) or die(mysql_error()); 
@mysql_select_db('db_name') or die('Could not select database<br />'.mysql_error()); 

$sql = "INSERT INTO table (partnerid, first_name, last_name, email, address, address2, city, state, country, zip, soc_sec, phone, password_hint, password) VALUES (NULL, '$first_name', '$last_name', '$email', '$address', '$address2', '$city'. '$state', '$country', '$zip', '$soc_sec', '$phone', '$password_hint', '$password')";
// for debugging echo out the SQL statement so you can see exactly what it looks like
echo '<p><b>SQL statement:</b></p><p>'.$sql.'</p>';
// end debugging

@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

// To work out the new partner_id just use mysql_insert_id() instead of
// another SQL statement
$partner_id = mysql_insert_id();

// check the id by echoing it:
echo '<p>partner_id = '.$partner_id.'</p>';

mysql_close() 
?>
Mac

Posted: Sun Apr 20, 2003 12:47 pm
by reverend_ink
I tried using that script verbatum and recieved errors up the yin~yang...

tried doing mods to it same result.....

You have an error in your SQL syntax near '. '', '', '', '', '', '', '')' at line 1
INSERT INTO table (partnerid, first_name, last_name, email, address, address2, city, state, country, zip, soc_sec, phone, password_hint, password) VALUES ('', '', '', '', '', '', ''. '', '', '', '', '', '', '')

Trying to figure this out....thanks all to those who have helped.......

Posted: Sun Apr 20, 2003 1:08 pm
by twigletmac
Basically there's no information being passed - all those variables $first_name, $last_name, $email et. al. are empty. Try running this code before the SQL statement:

Code: Select all

foreach ($_POST as $key => $value) {
     $$key = $value;
}
and see what you get.

Mac

Posted: Sun Apr 20, 2003 1:43 pm
by twigletmac
oh, and you need to change

Code: Select all

'$city'. '$state'
to

Code: Select all

'$city', '$state'
(comma inbetween them not a full stop) to prevent the MySQL error.

Mac

Posted: Sun Apr 20, 2003 2:13 pm
by reverend_ink
thanks for the help!!!!!!!

worked fine!

now onto new bugs and issues!

:)