Jump to content

help passing data to Mysql


tenfoottrike

Recommended Posts

ok first off im new to php just starting to get it and well i have a simple php form submit code but when it submits to the mysql database it stops a mail and mail and on do not submit to the database

 

here is my code

 

if($_POST['submit']{
             $comname = $_POST['comname'];
             $fname = $_POST['fname'];
             $lname = $_POST['lname'];
             $phone = $_POST['phone'];
             $email  = $_post['email'];
             $add = $_post['add'];
             $city = $_post['city'];
             $state = $_post['state'];
             $zip = $_post['zip'];
             $stuf = $_post['stuf'];

$conn = @mysql_connect("localhost","user","pass") or die('Error: ' . mysql_error());
$sql = "INSERT INTO `database`.`table` (`ID`, `comname`, `fname`, `lname`, `phone`, `email`, `add`, `city`, `    state`, `zip`, `stuf`)VALUES (NULL, '$comname', '$fname', '$lname', '$phone ', '$email', '$add', '$city', '$state', '$zip', '$stuf');";
mysql_query($sql) or die('Error: ' . mysql_error());
echo "Info submited: ".$comname." ".$fname." ".$lname." ".$phone." ".$email." ".$add." ".$city." ".$state." ".$zip." ".$stuf.
mysql_close();

else{
                 die("fourm was not filled out right");
                }
}
?>

 

also how do i redirect the page after it's done

Link to comment
https://forums.phpfreaks.com/topic/195088-help-passing-data-to-mysql/
Share on other sites

if($_POST['submit']{
             $comname = $_POST['comname'];
             $fname = $_POST['fname'];
             $lname = $_POST['lname'];
             $phone = $_POST['phone'];
             $email  = $_POST['email'];
             $add = $_POST['add'];
             $city = $_POST['city'];
             $state = $_POST['state'];
             $zip = $_POST['zip'];
             $stuf = $_POST['stuf'];



$conn = mysql_connect("localhost","user","pass") or die('Error: ' . mysql_error());

mysql_select_db("database", $conn) or dir(mysql_error());

$sql = "INSERT INTO `table` (`ID`, `comname`, `fname`, `lname`, `phone`, `email`, `add`, `city`, `    state`, `zip`, `stuf`)VALUES (NULL, '$comname', '$fname', '$lname', '$phone ', '$email', '$add', '$city', '$state', '$zip', '$stuf');";
mysql_query($sql) or die('Error: ' . mysql_error());
echo "Info submited: ".$comname." ".$fname." ".$lname." ".$phone." ".$email." ".$add." ".$city." ".$state." ".$zip." ".$stuf.
mysql_close();
}
else{
                 die("form was not filled out right");
}
}
?>

 

should work

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.