Jump to content

Please help my INSERT and UPDATE scripts have ceased working


Go to solution Solved by mac_gyver,

Recommended Posts

I am a complete Newb where this PHP malarkey is concerned, however I have picked up a few basics and probably many more bad habits.

The problem I have is the INSERT script and the UPDATE scripts have ceased working on Friday, the last time I know the INSERT worked was Thursday as items are added pretty much daily without any problems. All I have done is added 2 fields in the database 'salesperson' and 'made_live' and amended the scripts accordingly, when I realized it had stopped working I re-uploaded the original files and it still wasn't working, however I don't know if this is just coincidence or I've broken something.

I can't for the life of me see any errors in the script but what do I know, (actually I wish to re-phrase that, I can't see any errors that would cause this problem, I'm sure that there are plenty of errors in it ;-)

I would very much appreciate it if one of you experts could take a peek for me before I yank out what grey hair I have remaining.

Many thanks in advance. Ian.

 

INSERT Script:

 

<?php
//Connect to the MySQL database
include"../scripts/connect_to_mysql.php";

if (!get_magic_quotes_gpc()) {
$meta_desc=addslashes($_POST['meta_desc']);
$sku=$_POST['sku'];
$business_name=addslashes($_POST['business_name']);
$address=$_POST['address'];
$package=addslashes($_POST['package']);
$contact_name=addslashes($_POST['contact_name']);
$description=addslashes($_POST['description']);
$phone=$_POST['phone'];
$e_mail=$_POST['e_mail'];
$short_web=$_POST['short_web'];
$weblink=$_POST['weblink'];
$facebook=$_POST['facebook'];
$first_ad=$_POST['first_ad'];
$main_menu=$_POST['main_menu'];
$category=$_POST['category'];
$sub_category=$_POST['sub_category'];
$niche_category=$_POST['niche_category'];
$display_ad=$_POST['display_ad'];

$salesperson=$_POST['salesperson'];
$made_live=addslashes($_POST['made_live']);
}
 

//* The script below fails to enter anything into the db*//

$sql=mysql_query( "INSERT INTO business_list (id, meta_desc, sku, business_name, address, package, contact_name, description, phone, e_mail, short_web, weblink, facebook, first_ad, main_menu, category, sub_category, niche_category, display_ad, salesperson, made_live) VALUES ('NULL', '$meta_desc', 'NULL', '$business_name', '$address', '$package', '$contact_name', '$description', '$phone', '$e_mail', '$short_web', '$weblink', '$facebook', '$first_ad', '$main_menu', '$category', '$sub_category', '$niche_category', '$display_ad', '$salesperson', '$made_live')");
 

//*$lastid now returns '0' (as the INSERT failed) when the script worked before it would return the id, then that id is used to update the sku in the db for the review section.*//

$lastid=mysql_insert_id();
$sql=mysql_query ($sql) or die ('<p></p><p></p>Database successfully updated with all the information relating to:<strong> ' . $business_name . ' </strong>,
<p>USE THIS ID FOR AD IMAGE:<strong> '
. $lastid . ' </strong><form action="set_sku.php" method="post" enctype="multipart/form-data" name="set_sku">
<p>Now you need to update the SKU in the Database</P>
<label>INPUT ID HERE TO UPDATE SKU AND CONTINUE TO ADD THE IMAGES</label>
<input name="sku" type="text" maxlength="7" />
<input type="submit" value="Update SKU" />
</form>
</p>'
);
mysql_close()
?>

 

 

UPDATE Script:

 

<?php
include
"../scripts/connect_to_mysql.php";

if (!get_magic_quotes_gpc()) {
$ud_id=$_POST['ud_id'];
$ud_sku=$_POST['ud_sku'];
$ud_business_name=addslashes($_POST['ud_business_name']);
$ud_address=addslashes($_POST['ud_address']);
$ud_package=addslashes($_POST['ud_package']);
$ud_contact_name=addslashes($_POST['ud_contact_name']);
$ud_description=addslashes($_POST['ud_description']);
$ud_meta_desc=addslashes($_POST['ud_meta_desc']);
$ud_phone=$_POST['ud_phone'];
$ud_e_mail=$_POST['ud_e_mail'];
$ud_short_web=$_POST['ud_short_web'];
$ud_weblink=$_POST['ud_weblink'];
$ud_facebook=$_POST['ud_facebook'];
$ud_first_ad=$_POST['ud_first_ad'];
$ud_category=$_POST['ud_category'];
$ud_sub_category=$_POST['ud_sub_category'];
$ud_niche_category=$_POST['ud_niche_category'];
$ud_display_ad=$_POST['ud_display_ad'];
$ud_salesperson=$_POST['ud_salesperson'];

$ud_made_live=addslashes($_POST['ud_made_live']);
}

 

//*The above script works as the data is displayed in the UPDATE form, the below script fails to actually do the UPDATE*//

$query="UPDATE business_list SET sku='$ud_sku', business_name='$ud_business_name', address='$ud_address', package='$ud_package', contact_name='$ud_contact_name', description='$ud_description', meta_desc='$ud_meta_desc', phone='$ud_phone', e_mail='$ud_e_mail', short_web='$ud_short_web', weblink='$ud_weblink', facebook='$ud_facebook', first_ad='$ud_first_ad', main_menu='$ud_main_menu', category='$ud_category', sub_category='$ud_sub_category', niche_category='$ud_niche_category', display_ad='$ud_display_ad', salesperson='$ud_salesperson', made_live='$ud_made_live' WHERE id='$ud_id'";

mysql_query($query);
echo "Record Updated";
mysql_close();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SLBD - Admin</title>
<link rel="stylesheet" href="../stylesheets/style.css" type="text/css" media="screen" />
</head>

<body>

<?php include_once("../templates/template_header.php"); ?>

<h1> <?php echo "Record Updated"; ?></h1>

<div id="contact" class="request">
<a href="log_out.php">[Log Out]</a> | <a href="reports_asc.php"> [Reports]</a>

<table width="100%" border="0" cellpadding="40">
<tr><strong>
<form action="admin.php" method="get" name="id">
<td align="center">
<input type="submit" value="Add an Advert" />
</td>
</form>

<form action="imageadmin.php">
<td align="center">
<input type="submit" value="Add or Update an Image" />
</td>
</form>

<form action="admin_update.php" method="get" name="id">
<td align="center">
<label>Update Ad with ID?</label><br /><br />
<input name="id" type="text" size="5" maxlength="7"> <br /><br />
<input type="submit" value="Update Advert" />
</td>
</form>
</strong>
</tr>
</table>

</div>
<br />
<?php include_once("../templates/template_footer.php"); ?>
</body>
</html>

The CONNECT Script works fine because:

  • the site displays correctly and uses the same script
  • The UPDATE command collects the data, just won't do the UPDATE

 

replace the top part of your code upto and including the first failed query and let us know what it gives back.

<?php
//Connect to the MySQL database
include"../scripts/connect_to_mysql.php";

if (!get_magic_quotes_gpc()) {
$meta_desc=addslashes($_POST['meta_desc']);
$sku=$_POST['sku'];
$business_name=addslashes($_POST['business_name']);
$address=$_POST['address'];
$package=addslashes($_POST['package']);
$contact_name=addslashes($_POST['contact_name']);
$description=addslashes($_POST['description']);
$phone=$_POST['phone'];
$e_mail=$_POST['e_mail'];
$short_web=$_POST['short_web'];
$weblink=$_POST['weblink'];
$facebook=$_POST['facebook'];
$first_ad=$_POST['first_ad'];
$main_menu=$_POST['main_menu'];
$category=$_POST['category'];
$sub_category=$_POST['sub_category'];
$niche_category=$_POST['niche_category'];
$display_ad=$_POST['display_ad'];

$salesperson=$_POST['salesperson'];
$made_live=addslashes($_POST['made_live']);
}

$insQry = <<<INS_QRY
INSERT INTO business_list
  (
    meta_desc,
    business_name,
    address,
    package,
    contact_name,
    description,
    phone,
    e_mail,
    short_web,
    weblink,
    facebook,
    first_ad,
    main_menu,
    category,
    sub_category,
    niche_category,
    display_ad,
    salesperson,
    made_live
  )
VALUES
  (
    '$meta_desc',
    '$business_name',
    '$address',
    '$package',
    '$contact_name',
    '$description',
    '$phone',
    '$e_mail',
    '$short_web',
    '$weblink',
    '$facebook',
    '$first_ad',
    '$main_menu',
    '$category',
    '$sub_category',
    '$niche_category',
    '$display_ad',
    '$salesperson',
    '$made_live'
  )
INS_QRY;
$sql=mysql_query($insQry)
or die ("The Following Query Failed To Run :<br><br>".$insQry."<br><br>The Server resonded with the following error:<br><br><span style=\"font-weight:bold;\>".mysql_error()."</span>");
exit("query was successful");

Thanks Muddy_Funster for your help, you really don't know how much I appreciate it, I've done as you asked and used test as an entry where there is not a list item and the following was returned;

 

The Following Query Failed To Run :

INSERT INTO business_list ( meta_desc, business_name, address, package, contact_name, description, phone, e_mail, short_web, weblink, facebook, first_ad, main_menu, category, sub_category, niche_category, display_ad, salesperson, made_live ) VALUES ( 'test', 'test', 'test', 'Free', 'test', 'test', 'test', 'test', 'test', 'Go To Website', 'test', '1', 'BUS Business', 'BUS Computers and IT', 'BUS C&I SEO', ' ', 'Free', 'Gabi', '28-08-2013' )

The Server resonded with the following error:

Hi Cracka, it is a date field however I've also made it VARCHAR, deleted it completely and gone right back to scripts I know for sure worked previously and still it doesn't work, it really does make no sense to me.

 

I know that the problem is going to be such a simple one but I just can't see it.

  • Solution

if you correct or simply remove the <span></span> tag in the code that Muddy_Funster posted or do a 'view source' of the output in your browser, you will be able to see what the mysql_error() statement returned.

Thank you so much Muddy_Funster and Mac_Gyver, unfortunately I can't mark both of your answers as solved, as soon as I saw the error in the source code I knew that I had caused it.

 

What i had done is when I added the 2 new fields 'salesperson' and 'made_live' I renamed the field 'niche_category' to 'made_live' as it was never used then I proceeded to add the new lines of code to the scripts and left 'niche_category' in both files hence the error "unknown field 'niche_category'"

 

Once again you guys are legends and far more helpful than Stack Overflow. thanks again both of you I only wish I could help you out someday too.

 

Kind Regards

Ian.

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.