Jump to content

[SOLVED] Can someone lend me a fresh set of eyes?


bluebyyou

Recommended Posts

I can't figure out why the insert query wont work. I use the same connection function to run select queries on the DB. Can anyone see what the problem is?


<?php
//includes.php
/* function dbcon stores the database connection information and
   the connection functions */

/* $result must be handled on each individual page.
   for example: $row = mysql_fetch_array($result) .. */
function dbcon($sql) 
{
$host = "*******";
$user = "*********";
$password = "***********";
$database = "*********";

global $result;

$connection = mysql_connect($host,$user,$password) or die ("couldnt connect to rockypages server.");
$db = mysql_select_db($database, $connection) or die ("couldnt select rockypages database.");
$result = mysql_query($sql) or die ("Couldn't execute query.");

return $result;
}

/* This Function takes the numerical data from the PostingType Table 
   and converts it to the corresponding text. */ 
   
/* $input is the $key field in the database */
   
function posting_type($input)
{
$switch = $input;
switch ($switch)
{
case "1":
	$output = "Job";
	break;
case "2":
	$output = "For Sale";
	break;
case "3":
	$output = "Wanted";
	break;
case "4":
	$output = "Housing";
	break;
case "5":
	$output = "Services Offered";
	break;
case "6":
	$output = "Event";
	break;
}
echo $output;
}
?>


<?php 
//insert.php
include("includes.php");

if (isset($_POST['submit'])) 
{ 
$today = date("Y-m-d");

$query = sprintf("INSERT INTO Posting (date,type,price,title,desc,email,reply) 
                  VALUES ('%s','%s','%s','%s','%s','%s','%s')",
			  $today, $_POST['type'],$_POST['price'],$_POST['title'],$_POST['desc'],
                  $_POST['email'],$_POST['reply']);

dbcon($query); // <-- database connection function located on includes.php

}
else
{ 
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
Posting Type<select name="type">
<option value="0">Select One..</option>
<?php 
$query = "Select * FROM PostingType";
dbcon($query);

while ($row = mysql_fetch_array($result))
{
extract($row); ?>
<option value="<?php echo $key; ?>"><?php echo $name; ?></option>
<?php } ?>
</select><br><br>
Title<input name="title" type="text"><br>
Price<input name="price" type="text"><br><br>
Description<br>
<textarea name="desc" cols="40" rows="4"></textarea><br><br>

Email<input name="email" type="text"><br>
Verify<input name="vemail" type="text"><br><br>

<input name="reply" type="radio" value="0" checked>Reply to my E-Mail<br>
<input name="reply" type="radio" value="1">Do not show my e-mail<br><br>

Upload image  (Coming Soon..)<br>
<input name="h" type="text" disabled><input name="browse" type="button" disabled value="Browse..."><br><br>

<input name="submit" type="submit" value="Submit">
</form>

</body>
</html>
<?php } ?>

Link to comment
Share on other sites

I may have misunderstood, I added the single quotes, and had no effect, do I need to rename the fields in my DB to something other than date and desc?

 

Also I have another field in the db "number" which is the primary key and it is auto incrementing. I thought I could leave it out, but is it possible that omitting that field is messing up the INSERT query?

Link to comment
Share on other sites

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.