Jump to content

Recommended Posts

I use the code below to verify fields are not empty and then insert the data into the proper tables. The insert worked fine untill I added the code at the top to  verify that the fields where not empty.

Now when I run it it inserts everything EXCEPT "SPHONE", "CATEGORY", "UPC", AND "BRAND".

 

Can someone see somthing I can't?

 

 

<?php

$bname=$_POST['bname'];

if (empty($bname))

{

echo"<a href='addproducts.php'>Enter Your Store Name</a>";

exit(); // stop exec here

}

 

$sphone=$_POST['sphone'];

if (empty($sphone))

{

echo"<a href='addproducts.php'>Enter Your Store Phone</a>";

exit(); // stop exec here

}

 

$category=$_POST['category'];

if (empty($category))

{

echo"<a href='addproducts.php'>Enter a Category</a>";

exit(); // stop exec here

}

 

$brand=$_POST['brand'];

if (empty($brand))

{

echo"<a href='addproducts.php'>Enter a Brand</a>";

exit(); // stop exec here

}

 

if

(isset($_POST['bname']) &&!empty($_POST['bname'])&&

isset($_SESSION['sphone']) &&!empty($_SESSION['sphone'])&&

isset($_POST['category']) &&!empty($_POST['category'])&&

isset($_POST['brand']) &&!empty($_POST['brand']) )

 

// don't worry about ID, it is checked for numeric ONLY

$bname=mysql_real_escape_string($bname) ;

$sphone=mysql_real_escape_string($sphone) ;

$category=mysql_real_escape_string($category) ;

$brand=mysql_real_escape_string($brand) ;

 

include("k_falls_dbinfo2.inc.php");

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "INSERT INTO products VALUES ('','$bname','$sphone','$category','$upc','$brand','$model','$description','$extra','$price','$website')";

mysql_query($query);

 

 

#  if the user submitted a CATEGORY

if( isset($category) )

{

  #  get the user id 

  $id = mysql_insert_id( );

 

  #  and insert the CATEGORY details

  $query = "INSERT INTO categories VALUES ('','$category')";

  mysql_query($query);

}

if( isset($brand) )

{

  #  get the user id 

  $id = mysql_insert_id( );

  $query = "INSERT INTO brands VALUES ('','$brand')";

  $result = mysql_query( $query );

}

mysql_free_result( $result );

mysql_close();

// -----------------------------

(header("location: addproducts.php"));

if($result)

{

echo "Your information has been successfully added to the database.";

}

else

{

echo"hmm I sc...up!";

}

?>

 

<edit> fixed a {} </edit>

 

 

Link to comment
https://forums.phpfreaks.com/topic/86162-solved-problems-with-insert/
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.