PHP problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

PHP problem

Post 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()
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post 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....
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post 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.......
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

thanks for the help!!!!!!!

worked fine!

now onto new bugs and issues!

:)
Post Reply