Web Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsWeb DesignWeb Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 27th, 2015, 12:43 AM
megajuz3003 megajuz3003 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2015
Posts: 1 megajuz3003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 29 m 54 sec
Reputation Power: 0
PHP / MySQL problem

i don't know wether i have put this in the right place.... I'm hoping that someone can find my mistake . i have written/borrowed some code that edits an entry in a MySQL database. the problem i am having is that is is not updating the database.. any help would be appreciated

PHP Code:
<?php
 
function renderForm($id$ProductName$Author$Title$Year$Publisher$ProductDescription$Price$ImgPath)
 {
 
?>

 <?php 
 
// if there are any errors, display them
 
if ($error != '')
 {
 echo 
'<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 
?> 
 
 <form action="" method="post">
 <input type="hidden" name="id" value="<?php echo $id?>"/>
 <div>
 <p>
 ID: <?php echo $id?></p>
 Product Name: * <input type="text" name="ProductName" value="<?php echo $ProductName?>"/><br/>
 Author: * <input type="text" name="Author" value="<?php echo $Author?>"/><br/>
 Title: * <input type="text" name="Title" value="<?php echo $Title?>"/><br/>
 Year: * <input type="text" name="Year" value="<?php echo $Year?>"/><br/>
 Publisher: * <input type="text" name="Publisher" value="<?php echo $Publisher?>"/><br/>
 Description: * <input type="text" name="ProductDescription" value="<?php echo $ProductDescription?>"/><br/>
 Price: * <input type="text" name="Price" value="<?php echo $Price?>"/><br/>
 Image Path: * <input type="text" name="ImgPath" value="<?php echo $ImgPath?>"/><br/>
 <p>* Required</p>
 
 <input type="submit" name="submit" value="Submit">
 </div>
 </form> 
 <?php
 
}

// connect to the database
// SQL Server Login Credentials
$server "localhost";
$username "a5630291_siteuse";
$password "justin900J3";

// SQL Server Connection String
$connect_mysql=mysql_connect($server,$username,$pa  ssword) or die ("Connection Failed!");

// SQL Database Selection String
$mysql_db=mysql_select_db("a5630291_tech-readers",$connect_mysql) or die ("Could not Connect to Database");


 
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
 { 
 
// confirm that the 'id' value is a valid integer before getting the form data
 
if (is_numeric($_POST['id']))
 {

 
// generate error message
 
$error 'ERROR: Please fill in all required fields!';
 
  {
 
// save the data to the database
 
mysql_query("UPDATE Products SET ProductName='$ProductName', Author='$Author', Title='$Title', Year='$Year', Publisher='$Publisher', ProductDescription='$ProductDescription', Price='$Price', ImgPath='$ImgPath' WHERE ProductID='$id'")
 or die(
mysql_error()); 

 
 
 
 
// once saved, redirect back to the view page
 
header("Location: view.php"); 
 }
 }
 else
 {
 
// if the 'id' isn't valid, display an error
 
echo 'Error!';
 }
 }
 else
 
// if the form hasn't been submitted, get the data from the db and display the form
 
{
 
 
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
 
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
 {
 
// query db
 
$id $_GET['id'];
 
$result mysql_query("SELECT * FROM Products WHERE ProductID=$id")
 or die(
mysql_error()); 
 
$row mysql_fetch_array($result);
 
 
// check that the 'id' matches up with a row in the databse
 
if($row)
 {
 
 
// get data from db
 
$ProductName $row['ProductName'];
 
$Author $row['Author'];
 
$Title $row['Title'];
 
$Year $row['Year'];
 
$Publisher $row['Publisher'];
 
$ProductDescription $row['ProductDescription'];
 
$Price $row['Price'];
 
$ImgPath $row['ImgPath'];
 
 
// show form
 
renderForm($id$ProductName$Author$Title$Year$Publisher$ProductDescription$Price$ImgPath'');
 }
 else
 
// if no match, display result
 
{
 echo 
"No results!";
 }
 }
 else
 
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
 
{
 echo 
'Error!';
 }
 }
?>

Reply With Quote
  #2  
Old February 25th, 2015, 06:47 AM
jessica89 jessica89 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2015
Posts: 1 jessica89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 34 sec
Reputation Power: 0
Does it send a white page when you submit?
Because it seems you also have a typo in your $password in your connection.

$connect_mysql=mysql_connect($server,$username,$pa ssword)

You should also check if all column names match exactly...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsWeb DesignWeb Development > PHP / MySQL problem


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap