needdd help here.....plssssssssss

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
silentcloud18
Forum Newbie
Posts: 3
Joined: Sat Mar 15, 2008 11:46 pm

needdd help here.....plssssssssss

Post by silentcloud18 »

Everah | Please use proper code tags when posting code in the forums. You may use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight. Your post has been edited to show how we would like to see it.

it can't insert data to my database, don't know y..i'm a real newbie....using php 5 and mysql 5

Code: Select all

<?php
session_start();
//echo"<h1>Member only</h1>";
?>
<body>
<?php
if (session_is_registered("valid_user"))
        {
        //echo "<br><br>Welcome <b><font color=\"green\">$valid_user</font></b> <br>";
?>
<table align="center"><tr>
        <td><?php include "menu.inc"; //include this as menu ?></td> 
       </tr>
       <tr>
         <td>
<?php
function new_items(){
        echo "<center><b>POST YOUR ITEMS HERE</b></center>";
        echo "<center><b>Please fill in this form to post items</b></center>";
        echo "<form name=newitems method=post action=\"additem.php?act=add\">\n";
        echo "<table>";
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Item name :</b></td>";
        echo "<td>";
        echo "    <input class=\"inputbox\" type=\"text\" name=\"item_name\">";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Category :</b></td>";
        echo "<td>";
        echo "    <select name=\"item_cat\">";
        echo "    <option selected>Engine and performance</option>";
        echo "    <option>Wheels and chasis</option>";
        echo "    <option>Exterior and body</option>";
        echo "    </select>";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Condition :</b></td>";
        echo "<td>";
        echo "    <input class=\"inputbox\" type=\"text\" name=\"item_cond\">";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Price :</b></td>";
        echo "<td>";
        echo "    <input class=\"inputbox\" type=\"text\" name=\"item_price\">";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Your name :</b></td>";
        echo "<td>";
        echo "    <input class=\"inputbox\" type=\"text\" name=\"supp_name\">";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr valign=top>\n";
        echo "<td align=right><b>Your contact No :</b></td>";
        echo "<td>";
        echo "    <input class=\"inputbox\" type=\"text\" name=\"supp_cont\">";
        echo "</td>";
        echo "</tr>\n";
 
        echo "<tr><td colspan=2 align=center>\n";
 
        echo "<input type=submit name=Submit value=\"SAVE\">\n";
        echo "<input type=reset name=Submit2 value=\"RESET\">\n";
        echo "</td></tr>\n";
 
        echo "</form>\n";
        echo "</table>\n";
 
} // end function new_items
 
function add_items(){
        global $id,$item_name,$item_cat,$item_cond,$item_price,$supp_name,$supp_cont;
 
$DbServer = "localhost"; //server
$DbUser = "root"; //my username, you should change this
$DbPass = "awesliuk"; //my password, you should change this either
$DbName = "project_elective"; //this is my database name..in MySQL
 
// make connection to database
$dblink=mysql_connect($DbServer, $DbUser, $DbPass) OR DIE("Unable to connect to database");
@mysql_select_db("$DbName") or die( "Unable to select database");
 
        $query="insert into items (id,item_name,item_cat,item_cond,item_price,supp_name,supp_cont) VALUES ('$id','$item_name','$item_cat','$item_cond','$item_price','$supp_name','$supp_cont')";
        $result = mysql_query($query);
 
        echo "<br><br><br><center>Thank You..your item has been saved</center>\n";
} // end function add_items
 
switch($act) {
        case "add":
        add_items();
        break;
 
        default:
        new_items();
        break;
}
 
        }
        else
        {
        echo "<br>You are not logged in.<br>";
        echo "Only logged in members may see this page.<br><br>";
        echo "<a href =\"index.php\">Back to login</a>";
        }
        
?>
Everah | Please use proper code tags when posting code in the forums. You may use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight. Your post has been edited to show how we would like to see it.
Last edited by RobertGonzalez on Mon Mar 17, 2008 10:25 am, edited 1 time in total.
Reason: Tags note
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: needdd help here.....plssssssssss

Post by pickle »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Moving post to PHP Code. Please wrap your code in tags as well so it's readable.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: needdd help here.....plssssssssss

Post by RobertGonzalez »

Why not try using a mysql_error() call after the query so the database server can tell you what's wrong with it. If there is nothing wrong with the query turn on display_errors so you can see what PHP is telling you.
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Re: needdd help here.....plssssssssss

Post by nincha »

change:
$result = mysql_query($query);
to
$result = mysql_query($query) or die(mysql_error());
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: needdd help here.....plssssssssss

Post by Christopher »

And:

Code: Select all

$result = mysql_query($query);
if (mysql_errno()) {
     echo 'Error: ' . mysql_error();
}
(#10850)
silentcloud18
Forum Newbie
Posts: 3
Joined: Sat Mar 15, 2008 11:46 pm

Re: needdd help here.....plssssssssss

Post by silentcloud18 »

here is the file, if its alright with you guys...help me with my prob..
Attachments
_sample_.rar
its a little bit messy...
(19.74 KiB) Downloaded 22 times
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: needdd help here.....plssssssssss

Post by John Cartwright »

Run the file with the changes that were suggested and post the results. Nobody is going to do the work for you.
Post Reply