Jump to content

[SOLVED] I Should Know This


bob2588

Recommended Posts

I cant figure out why thsi code is not working can any one help

<?php
include "db.php";

$State = $_POST['State'];
$zip = $_POST['zip'];
$type = $_POST['type'];

mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error());
mysql_select_db ("$db_name");
mysql_query("INSERT INTO real (id, State, zip, Type)
Values ( '$State', '$zip', '$type')") or die ('Error updating Databases'); 


echo"Databases Updated With: .$State  .$zip .$type";








Link to comment
https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/
Share on other sites

the one missing is an auto increment value i took out part of the code while trying to figure out what i was doing wrong It is not inserting the info in to the data base

<?php
include "db.php";

$State = $_POST['State'];
$zip = $_POST['zip'];
$type = $_POST['type'];

mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error());
mysql_select_db ("$db_name");
mysql_query("INSERT INTO real (id, State, zip, Type)
Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); 


echo"Databases Updated With: .$State  .$zip .$type";












?>

here is the form

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>

<body>

<form method="POST" action="add.php">
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="State" size="20"></p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="zip" size="20"></p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="type" size="20"></p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>

 

here is the add.php

<?php
include "db.php";

$State = $_POST['State'];
$zip = $_POST['zip'];
$type = $_POST['type'];

mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error());
mysql_select_db ("$db_name");
mysql_query("INSERT INTO real (id, State, zip, Type)
Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); 


echo"Databases Updated With: .$State  .$zip .$type";












?>

and last db.php

<?php

$host = "localhost"; //Databse Location
$user = "bob2_search"; //Database User
$pass= "skater22"; //Database Password
$db_name ="bob2_search"; //Database Name 


?>

 

I figure it out the code should look like this

 

<?php
include "db.php";

$State = $_POST['State'];
$zip = $_POST['zip'];
$type = $_POST['type'];

mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error());
mysql_select_db ("$db_name");
mysql_query("INSERT INTO `$db_name`.`real` (id, State, zip, Type)
Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); 


echo"Databases Updated With: .$State  .$zip .$type";












?>

i was missing the database name in the mysql insert :/

 

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.