Jump to content

Recommended Posts

after an exhausting post figuring out what was wrong and finally getting everything to work, its all gone downhill.

 

all i tried to do was add more fields to the database table + the input page and now the thing aint working. can anyone spot where i've messed up? i get no errors but it doesnt insert the info.

 

input page

<form action="insert.php" method="post">
bedrooms: <input type="text" name="bedrooms"><br>
bathrooms: <input type="text" name="bathrooms"><br>
area: <input type="text" name="area"><br>
postcode: <input type="text" name="postcode"><br>
ref: <input type="text" name="ref"><br>
description:<input type="text" name="description"></textarea><br>
rent pw: <input type="text" name="rentpw"><br>
rentpm: <input type="text" name="rentpm"><br>
deposit: <input type="text" name="deposit"><br>
availability: <input type="text" name="availability"><br>
type: <input type="text" name=type"><br>
address: <input type="text" name="address"><br>
image: <input type="text" name="image"><br>
<input type="Submit">
</form>

 

insert.php

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(mysql_error()); 
$bedrooms=$_POST['bedrooms'];
$bathrooms=$_POST['bathrooms'];
$area=$_POST['area'];
$postcode=$_POST['postcode'];
$ref=$_POST['refs'];
$description=$_POST['description'];
$rentpw=$_POST['rentpw'];
$rentpm=$_POST['rentpm'];
$deposit=$_POST['deposit'];
$propertynear=$_POST['propertynear'];
$availability=$_POST['availability'];
$type=$_POST['type'];
$address=$_POST['address'];
$image=$_POST['image'];

$query = "INSERT INTO properties VALUES ('','$bedrooms','$bathrooms','$area','$postcode','$ref','$description','$rentpw','$rentpm','$deposit','$propertynear','$availability,'$type','$address','$image')";
mysql_query($query);
echo("Success.");
mysql_close();
?> 

Link to comment
https://forums.phpfreaks.com/topic/140736-solved-phpmysql-question-de-ja-vu/
Share on other sites

change insert.php to this

 

<?php
include("dbinfo.inc.php");
$link = mysql_connect('localhost', $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
    die("Can't use $database : " . mysql_error());
}
$bedrooms=$_POST['bedrooms'];
$bathrooms=$_POST['bathrooms'];
$area=$_POST['area'];
$postcode=$_POST['postcode'];
$ref=$_POST['refs'];
$description=$_POST['description'];
$rentpw=$_POST['rentpw'];
$rentpm=$_POST['rentpm'];
$deposit=$_POST['deposit'];
$propertynear=$_POST['propertynear'];
$availability=$_POST['availability'];
$type=$_POST['type'];
$address=$_POST['address'];
$image=$_POST['image'];

$query = "INSERT INTO properties VALUES ('','$bedrooms','$bathrooms','$area','$postcode','$ref','$description','$rentpw','$rentpm','$deposit','$propertynear','$availability,'$type','$address','$image')";
$result = mysql_query($query);
if (!$result) {
    die('Invalid query: ' . mysql_error());
} else {
   echo("Success.");
}
?>

 

and see what happens, if you get an error post it

Did you do what I said or what Revraz said??

 

If you did as Revraz said I'm guessing you didn't add the error reporting as you mentioned.

 

Also, just as a note you're echoing 2success2 out at the end of the page, as long as there's not a fatal error that will always print not matter what happens

well yeah obviously but i cant see anything wrong with the HTML and dreamweaver doesnt seem to have any objections to it.. as for what happens after submission i havent a clue about that..

 

aside from the previous typo's which were ammended i dont see anything wrong

 

<form action="insert.php" method="post">
bedrooms: <input type="text" name="bedrooms"><br>
bathrooms: <input type="text" name="bathrooms"><br>
area: <input type="text" name="area"><br>
postcode: <input type="text" name="postcode"><br>
ref: <input type="text" name="ref"><br>
description:<input type="text" name="description"><br>
rent pw: <input type="text" name="rentpw"><br>
rentpm: <input type="text" name="rentpm"><br>
deposit: <input type="text" name="deposit"><br>
availability: <input type="text" name="availability"><br>
type: <input type="text" name="type"><br>
address: <input type="text" name="address"><br>
image: <input type="text" name="image"><br>
<input type="Submit">
</form>

had to echo($_POST) as print_r has been disable for some security reason.. does this make a difference?

 

It just says "Array"

 

Yea, if print_r is disabled do this:

 

foreach ($_POST as $key => $val)
      echo "key :: $key  =>  value :: $val <br />"; 

 

And see what that prints.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.