PHP problem
Moderator: General Moderators
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
PHP problem
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()
?>
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()
?>
what happens? what does not? php version? os? did you read Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+?
welcome
welcome
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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)?reverend_ink wrote:and yes I read the sticky but didnt provide my particular errors....
Basically, using the recommended settings in the php.ini (PHP's configuration file) you can't do this:
Code: Select all
<form action="file.php" method="post">
<input type="text" name="field1" />
<input type="text" name="field2" />
<input type="submit" name="submit" value="submit" />Code: Select all
echo 'in field1 you entered: '.$field1;
echo '<br />';
echo 'in field2 you entered: '.$field2;Code: Select all
echo 'in field1 you entered: '.$_POST['field1'];
echo '<br />';
echo 'in field2 you entered: '.$_POST['field2'];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()
?>-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
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.......
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.......
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
and see what you get.
Mac
Code: Select all
foreach ($_POST as $key => $value) {
$$key = $value;
}Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
oh, and you need to change
to
(comma inbetween them not a full stop) to prevent the MySQL error.
Mac
Code: Select all
'$city'. '$state'Code: Select all
'$city', '$state'Mac
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London