Jump to content

[SOLVED] PHP/MySQL question.. de ja vu


twitch987

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.

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.